Skip to content

Commit

Permalink
map preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ihptru committed Mar 24, 2016
1 parent 8380d2f commit 4971394
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 38 deletions.
2 changes: 1 addition & 1 deletion openra/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def mapAPI(request, arg, arg1="", arg2="", arg3="", arg4=""):
# get detailed map info by hash
elif arg == "hash":
map_hashes = arg1.split(',')
mapObject = Maps.objects.filter(map_hash__in=map_hashes)
mapObject = Maps.objects.filter(map_hash__in=map_hashes).distinct('map_hash')
if not mapObject:
raise Http404
if arg2 == "yaml":
Expand Down
5 changes: 0 additions & 5 deletions openra/forms.py

This file was deleted.

17 changes: 12 additions & 5 deletions openra/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def ProcessUploading(self, user_id, f, post, rev=1, pre_r=0):
pre_rev = pre_r,
next_rev = 0,
downloading = True,
requires_upgrade = not self.LintPassed,
requires_upgrade = True,
advanced_map = resp_map_data['advanced'],
lua = resp_map_data['lua'],
posted = timezone.now(),
Expand All @@ -317,6 +317,7 @@ def ProcessUploading(self, user_id, f, post, rev=1, pre_r=0):

self.UnzipMap()


lint_check_response = utility.LintCheck(transac, self.map_full_path_filename, parser)
if lint_check_response['error'] == False and lint_check_response['response'] == 'pass_for_requested_parser':
self.LintPassed = True
Expand All @@ -326,6 +327,7 @@ def ProcessUploading(self, user_id, f, post, rev=1, pre_r=0):
else:
Maps.objects.filter(id=transac.id).update(requires_upgrade=True)


if int(resp_map_data['mapformat']) < 10:
self.GenerateMinimap(resp_map_data['game_mod'], parser)

Expand Down Expand Up @@ -445,18 +447,18 @@ def LegacyImport(self, mapPath, parser=settings.OPENRA_ROOT_PATH + list(reversed



def addScreenshot(f, arg, user_id, item):
def addScreenshot(request, arg, item):
if item == 'map':
Object = Maps.objects.filter(id=arg)
if not Object:
return False
if not (Object[0].user_id == user_id.id or user_id.is_superuser):
if not (Object[0].user_id == request.user.id or request.user.is_superuser):
return False
else:
return False
tempname = '/tmp/screenshot.temp'
with open(tempname, 'wb+') as destination:
for chunk in f.chunks():
for chunk in request.FILES['screenshot'].chunks():
destination.write(chunk)

command = 'file -b --mime-type %s' % tempname
Expand All @@ -465,12 +467,17 @@ def addScreenshot(f, arg, user_id, item):
if mimetype not in ['image/jpeg','image/png','image/gif']:
return False

map_preview = False
preview = request.POST.get('map_preview', None)
if preview == 'on':
map_preview = True

transac = Screenshots(
user = Object[0].user,
ex_id = int(arg),
ex_name = item+"s",
posted = timezone.now(),
map_preview = False,
map_preview = map_preview,
)
transac.save()

Expand Down
5 changes: 5 additions & 0 deletions openra/static/js/highslide/highslide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ var config1 = {
slideshowGroup: 'group1',
transitions: ['expand', 'crossfade']
};

var config_minimap = {
slideshowGroup: 'map_preview',
transitions: ['expand', 'crossfade']
}
8 changes: 4 additions & 4 deletions openra/static/style002.css
Original file line number Diff line number Diff line change
Expand Up @@ -1379,10 +1379,10 @@ p.registerInfo {
margin: 0 0 0 140px;
}

.addScreenshotForm {
font-size: 0.9em;
float: right;
padding-top: 50px;
.screenshot_form {
padding: 20px;
text-align: left;
margin-bottom: 30px;
}

/* */
Expand Down
17 changes: 13 additions & 4 deletions openra/templates/addScreenshotForm.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{% if request.user.is_authenticated %}
<div class="upload_container">
<form action="/maps/{{arg}}/" method="POST" enctype="multipart/form-data">{% csrf_token %}
<h3>Upload screenshot of your map</h3>
<div class='addScreenshotForm'>
<div class='cBlock no-pd-bot'>
<h3>Upload screenshot of your map</h3>
</div>

<div class='cBlock screenshot_form'>
<div>
{% if form.scfile.errors %} <span class="error">{{ form.scfile.errors|join:", " }}</span>{% endif %}
{{ form.scfile }}
<input name="screenshot" type="file">
<br />
<p>
<input name="map_preview" type="checkbox"> Map full preview <span class="red">*</span>
</p>
<p>
<span class="red">*</span> Last uploaded Map full preview is available via click on minimap.
</p>
</div>
<div>
<button type="submit">Upload</button>
Expand Down
8 changes: 7 additions & 1 deletion openra/templates/displayMap.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

<div class="map_image_container left">
<div class="map_image">
<img src={{ '/maps/' }}{{ arg }}{{ '/minimap' }} alt="minimap" />
{% if map_preview %}
<a class="map_full_preview" href="/screenshots/{{map_preview.id}}/" onclick="return hs.expand(this, config_minimap)">
<img src={{ '/maps/' }}{{ arg }}{{ '/minimap' }} alt="minimap" />
</a>
{% else %}
<img src={{ '/maps/' }}{{ arg }}{{ '/minimap' }} alt="minimap" />
{% endif %}
</div>
</div>
<div class="clear"></div>
Expand Down
49 changes: 31 additions & 18 deletions openra/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import cgi
import pytz
import copy
import base64
from functools import reduce
from django.conf import settings
from django.http import StreamingHttpResponse
from django.template import RequestContext, loader
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect, Http404
from django.db.models import Max
from django.utils import timezone

from .forms import AddScreenshotForm
from django.db.models import F, Count, Q
from django.contrib.auth.models import User
from allauth.socialaccount.models import SocialAccount
Expand Down Expand Up @@ -532,10 +531,10 @@ def displayMap(request, arg):
else:
Maps.objects.filter(id=arg, user_id=request.user.id).update(info=request.POST['mapInfo'].strip())
return HttpResponseRedirect('/maps/'+arg)
elif request.FILES.get('scfile', False) != False:
form = AddScreenshotForm(request.POST, request.FILES)
if form.is_valid():
handlers.addScreenshot(request.FILES['scfile'], arg, request.user, 'map')
elif request.FILES.get('screenshot', False) != False:

handlers.addScreenshot(request, arg, 'map')

elif request.POST.get('comment', "") != "":
transac = Comments(
item_type = 'maps',
Expand Down Expand Up @@ -652,6 +651,11 @@ def displayMap(request, arg):
show_upgrade_map_button = False # map is up-to-date
###

map_preview = None
for sc_item in screenshots:
if sc_item.map_preview:
map_preview = sc_item

license, icons = misc.selectLicenceInfo(mapObject)
userObject = User.objects.get(pk=mapObject.user_id)
Maps.objects.filter(id=mapObject.id).update(viewed=mapObject.viewed+1)
Expand Down Expand Up @@ -681,6 +685,7 @@ def displayMap(request, arg):
'lints': lints,
'comments': comments,
'show_upgrade_map_button': show_upgrade_map_button,
'map_preview': map_preview,
}
return StreamingHttpResponse(template.render(template_args, request))

Expand Down Expand Up @@ -897,17 +902,27 @@ def serveYaml(request, arg):


def serveYamlRules(request, arg):
path = os.getcwd() + os.sep + __name__.split('.')[0] + '/data/maps/' + arg + os.sep + '/content/map.yaml'

result = ""
start = False
fn = open(path, 'r')
lines = fn.readlines()
fn.close()
for line in lines:
if "Rules:" in line:
start = True
if start:
result += line

mapObject = Maps.objects.filter(id=arg).first()
if mapObject:
if int(mapObject.mapformat) < 10:
path = os.getcwd() + os.sep + __name__.split('.')[0] + '/data/maps/' + arg + os.sep + '/content/map.yaml'
start = False
fn = open(path, 'r')
lines = fn.readlines()
fn.close()
for line in lines:
if "Rules:" in line:
start = True
if start:
result += line
else:
result = base64.b64decode(mapObject.base64_rules).decode()
else:
HttpResponseRedirect('/')

response = StreamingHttpResponse(cgi.escape(result, quote=None), content_type='application/plain')
response['Content-Disposition'] = 'attachment; filename = advanced.%s' % arg
return response
Expand Down Expand Up @@ -1124,12 +1139,10 @@ def addScreenshot(request, arg, item):
Object = Maps.objects.filter(id=arg)
if not (Object[0].user_id == request.user.id or request.user.is_superuser):
return StreamingHttpResponse("")
form = AddScreenshotForm()
template = loader.get_template('addScreenshotForm.html')
template_args = {
'request': request,
'arg': arg,
'form': form,
}
return StreamingHttpResponse(template.render(template_args, request))

Expand Down

0 comments on commit 4971394

Please sign in to comment.