← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands-website/add_hints into lp:widelands-website

 

kaputtnik has proposed merging lp:~widelands-dev/widelands-website/add_hints into lp:widelands-website.

Commit message:
Add hints-field to the description of the maps.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1542449 in Widelands Website: "Display map->hint on the website"
  https://bugs.launchpad.net/widelands-website/+bug/1542449

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/add_hints/+merge/285664

* Add hints filed to show on the website.
* Uploader description could be edited.
* Added exception for KeyError
* Did some style changes.

I ran pyformat over this, so some of the changes are only syntax stuff.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/add_hints into lp:widelands-website.
=== modified file 'media/css/base.css'
--- media/css/base.css	2016-01-12 08:05:17 +0000
+++ media/css/base.css	2016-02-10 22:42:48 +0000
@@ -49,6 +49,10 @@
 	color: #181;
 }
 
+.breadCrumb{
+	margin-bottom: 10px;
+}
+
 /* We put this after a:hover  */
 /* to prevend the hover style */
 /* for this link              */

=== modified file 'media/css/maps.css'
--- media/css/maps.css	2015-04-01 20:01:41 +0000
+++ media/css/maps.css	2016-02-10 22:42:48 +0000
@@ -7,7 +7,7 @@
 }
 
 img.map {
-	margin: 0px 10px 10px 0px;
+	margin: 10px 10px 10px 0px;
 }
 
 .maps table td{

=== added file 'templates/wlmaps/edit_comment.html'
--- templates/wlmaps/edit_comment.html	1970-01-01 00:00:00 +0000
+++ templates/wlmaps/edit_comment.html	2016-02-10 22:42:48 +0000
@@ -0,0 +1,27 @@
+{% extends "wlmaps/base.html" %}
+
+{% block content %} 
+<h1>Edit comment: {{ map.name }}</h1>
+<div class="blogEntry">
+    <form enctype="multipart/form-data" action="{% url wlmaps_edit_comment map.slug %}" method="post">
+        <div>
+		{{ form.uploader_comment.label_tag }}:
+			<span class="posRight">
+				<a href="/wiki/WikiSyntax" title="Opens new Tab/Window" target="_blank">
+					<img src="{{ MEDIA_URL }}img/menu_help.png" alt="Help on Syntax" class="middle">
+					Help on Syntax
+				</a>
+			</span>
+		{{ form.uploader_comment }}
+		</div>
+		{% if form.uploader_comment.errors %}
+			<span class="errormessage">{{ form.uploader_comment.errors }}</span><br />
+		{% endif %}
+		{% csrf_token %}
+        <button type="submit">
+            <img src="{{ MEDIA_URL }}forum/img/send.png" alt ="Submit" class="middle" />
+            <span class="middle">Submit</span>
+        </button>
+	</form>
+</div>
+{% endblock %}
\ No newline at end of file

=== modified file 'templates/wlmaps/map_detail.html'
--- templates/wlmaps/map_detail.html	2015-02-18 22:30:08 +0000
+++ templates/wlmaps/map_detail.html	2016-02-10 22:42:48 +0000
@@ -7,6 +7,7 @@
 {% load wlmaps_extra %}
 {% load wlprofile %}
 {% load threadedcommentstags %}
+{% load wl_markdown %}
 
 {% block title %}{{ map.name }} - {{ block.super }}{% endblock %}
 
@@ -33,23 +34,34 @@
 
 {% block content %}
 <h1>Map: {{ map.name }}</h1>
-<div class="blogEntry">
-	<a href="{% url wlmaps_index %}">Maps</a> &#187;
-	{{ map.name }}
-	<br /><br />
-	<img class="posLeft map" src="{{ MEDIA_URL }}{{ map.minimap.url }}" alt="{{ map.name }}" />
-
-	<div style="display: inline-block;">
+<div class="blogEntry" style="padding-bottom: 3em">
+	<div>
+		<a href="{% url wlmaps_index %}">Maps</a> &#187; {{ map.name }}
+	</div>
+		<img class="posLeft map" style="float: left" src="{{ MEDIA_URL }}{{ map.minimap.url }}" alt="{{ map.name }}" />
+	<div>
 		<h3>Description:</h3>
-		<p>{{ map.descr }}</p>
-	</div>
-	<br />
-	<div style="display: inline-block;">
+		<p>{{ map.descr|wl_markdown:"escape" }}</p>
+	</div>
+	{% if map.hint %}
+	<div>
+		<h3>Hint:</h3>
+		<p>{{ map.hint|wl_markdown:"escape" }}</p>
+	</div>
+	{% endif %}
+
+	<div style="clear: left;">
 		<h3>Comment by uploader:</h3>
-		<p>{{ map.uploader_comment }}</p>
-	</div>
-	<br />
-	<div style="display: inline-block;">
+		<div>{{ map.uploader_comment|wl_markdown:"remove" }}</div>
+		{% if user == map.uploader %}
+			<a class="button posLeft" href="{% url wlmaps_edit_comment map.slug %}">
+				<img alt="Edit" title="Edit your comment" class="middle" src="{{ MEDIA_URL }}forum/img/edit.png">
+				<span class="middle">Edit</span>
+			</a>
+		{% endif %}
+	</div><br />
+
+	<div style="display: block" >
 		<h3>Basic Information:</h3>
 		<table>
 			<tr>
@@ -93,17 +105,20 @@
 				<td class="grey">Upload:</td><td>by {{ map.uploader|user_link }} at {{ map.pub_date|custom_date:user }}</td>
 			</tr>
 		</table>
+		
+		{% if not map.world_name %}
+		<div>
+			<strong>This map requires a version of Widelands newer than build18!</strong>
+		</div>
+		{% endif %}
 	</div>
-	<br />
-	{% if not map.world_name %}
-	<strong>This map requires a version of Widelands newer than build18!</strong><br />
-	{% endif %}
-	<br />
-	<a class="button" href="{% url wlmaps_download map.slug %}">
+	
+	<div style="margin: 1em 0px 1em 0px">
+	<a class="button posLeft" href="{% url wlmaps_download map.slug %}">
 		<img src="{{ MEDIA_URL }}img/download.png" alt ="" class="middle" />
 		<span class="middle">Download this map</span>
 	</a>
-	<div style="clear: left;"></div>
+	</div>
 </div>
 
 <div class="blogEntry">

=== modified file 'templates/wlmaps/upload.html'
--- templates/wlmaps/upload.html	2013-08-09 22:49:08 +0000
+++ templates/wlmaps/upload.html	2016-02-10 22:42:48 +0000
@@ -8,15 +8,24 @@
 {% block content %}
 <h1>Map Upload</h1>
 <div class="blogEntry">
-	<a href="{% url wlmaps_index %}">Maps</a> &#187; Upload
-	<br /><br />
+	<div class="breadCrumb">
+		<a href="{% url wlmaps_index %}">Maps</a> &#187; Upload
+	</div>
 	<form enctype="multipart/form-data" action="{% url wlmaps_upload %}" method="post">
 		{{ form.file.label_tag }}: {{ form.file }}<br />
 		{% if form.file.errors %}
 			<span class="errormessage">{{ form.file.errors }}</span><br />
 		{% endif %}
-		{{ form.uploader_comment.label_tag }}:<br />
+		<div>
+		{{ form.uploader_comment.label_tag }}:
+			<span class="posRight">
+				<a href="/wiki/WikiSyntax" title="Opens new Tab/Window" target="_blank">
+					<img src="{{ MEDIA_URL }}img/menu_help.png" alt="Help on Syntax" class="middle">
+					Help on Syntax
+				</a>
+			</span>
 		{{ form.uploader_comment }}
+		</div>
 		{% if form.uploader_comment.errors %}
 			<span class="errormessage">{{ form.uploader_comment.errors }}</span><br />
 		{% endif %}

=== modified file 'wlmaps/admin.py'
--- wlmaps/admin.py	2009-04-04 14:32:27 +0000
+++ wlmaps/admin.py	2016-02-10 22:42:48 +0000
@@ -5,12 +5,11 @@
 from models import Map
 from django.contrib import admin
 
+
 class MapAdmin(admin.ModelAdmin):
     prepopulated_fields = {'slug': ('name',)}
-    search_fields = [ "name", "author" ]
-    list_display = ["name", "author", "pub_date"]
-    list_filter = [ "pub_date" ]
+    search_fields = ['name', 'author']
+    list_display = ['name', 'author', 'pub_date']
+    list_filter = ['pub_date']
 
 admin.site.register(Map, MapAdmin)
-
-

=== modified file 'wlmaps/forms.py'
--- wlmaps/forms.py	2014-07-21 15:29:30 +0000
+++ wlmaps/forms.py	2016-02-10 22:42:48 +0000
@@ -14,6 +14,7 @@
 
 
 class UploadMapForm(ModelForm):
+
     class Meta:
         model = Map
         fields = ['file', 'uploader_comment']
@@ -26,44 +27,61 @@
             # no clean file => abort
             return cleaned_data
 
-        name = MEDIA_ROOT + "wlmaps/maps/" + file.name
+        name = MEDIA_ROOT + 'wlmaps/maps/' + file.name
         default_storage.save(name, ContentFile(file.read()))
         try:
             # call map info tool to generate minimap and json info file
-            check_call(["wl_map_info", name])
-            # TODO(shevonar): delete file because it will be saved again when the model is saved. File should not be saved twice
+            check_call(['wl_map_info', name])
+            # TODO(shevonar): delete file because it will be saved again when
+            # the model is saved. File should not be saved twice
             default_storage.delete(name)
         except CalledProcessError:
-            self._errors["file"] = self.error_class(["The map file could not be processed."])
-            del cleaned_data["file"]
+            self._errors['file'] = self.error_class(
+                ['The map file could not be processed.'])
+            del cleaned_data['file']
             return cleaned_data
 
-        mapinfo = json.load(open(name + ".json"))
+        mapinfo = json.load(open(name + '.json'))
 
-        if Map.objects.filter(name = mapinfo["name"]):
-            self._errors["file"] = self.error_class(["A map with the same name already exists."])
-            del cleaned_data["file"]
+        if Map.objects.filter(name=mapinfo['name']):
+            self._errors['file'] = self.error_class(
+                ['A map with the same name already exists.'])
+            del cleaned_data['file']
             return cleaned_data
 
         # Add information to the map
-        self.instance.name = mapinfo["name"]
-        self.instance.author = mapinfo["author"]
-        self.instance.w = mapinfo["width"]
-        self.instance.h = mapinfo["height"]
-        self.instance.nr_players = mapinfo["nr_players"]
-        self.instance.descr = mapinfo["description"]
-        self.instance.world_name = mapinfo["world_name"]
-        # mapinfo["minimap"] is an absolute path and cannot be used.
-        self.instance.minimap = "/wlmaps/maps/" + file.name + ".png"
-
-        # the json file is no longer needed
-        default_storage.delete(name + ".json")
-
+        try:
+            self.instance.name = mapinfo['name']
+            self.instance.author = mapinfo['author']
+            self.instance.w = mapinfo['width']
+            self.instance.h = mapinfo['height']
+            self.instance.nr_players = mapinfo['nr_players']
+            self.instance.descr = mapinfo['description']
+            self.instance.hint = mapinfo['hint']
+    
+            self.instance.world_name = mapinfo['world_name']
+            # mapinfo["minimap"] is an absolute path and cannot be used.
+            self.instance.minimap = '/wlmaps/maps/' + file.name + '.png'
+    
+            # the json file is no longer needed
+            default_storage.delete(name + '.json')
+        except KeyError:
+            self._errors['file'] = self.error_class(
+                ['A KeyError is occured. Please ask in the forum for help.'])
+            del cleaned_data['file']
+            return cleaned_data
+        
         return cleaned_data
 
-
     def save(self, *args, **kwargs):
         map = super(UploadMapForm, self).save(*args, **kwargs)
         if kwargs['commit']:
             map.save()
         return map
+
+
+class EditCommentForm(ModelForm):
+
+    class Meta:
+        model = Map
+        fields = ['uploader_comment', ]

=== modified file 'wlmaps/models.py'
--- wlmaps/models.py	2014-07-21 15:29:30 +0000
+++ wlmaps/models.py	2016-02-10 22:42:48 +0000
@@ -14,33 +14,38 @@
 
 
 class Map(models.Model):
-    name = models.CharField( max_length = 255, unique = True )
+    name = models.CharField(max_length=255, unique=True)
     slug = models.SlugField(unique=True)
-    author = models.CharField( max_length = 255 )
-    w = models.PositiveIntegerField( verbose_name = 'Width')
-    h = models.PositiveIntegerField( verbose_name = 'Height')
-    nr_players = models.PositiveIntegerField( verbose_name = 'Max Players')
-
-    descr = models.TextField( verbose_name = "Description" )
-    minimap = models.ImageField( verbose_name = "Minimap", upload_to = settings.MEDIA_ROOT + "/wlmaps/minimaps/" )
-    file = models.FileField( verbose_name = "Mapfile", upload_to = settings.MEDIA_ROOT + "/wlmaps/maps/" )
-
-    world_name = models.CharField( max_length = 50  )
-
-    pub_date = models.DateTimeField( default = datetime.datetime.now )
-    uploader_comment = models.TextField( verbose_name = "Uploader comment", blank = True )
+    author = models.CharField(max_length=255)
+    w = models.PositiveIntegerField(verbose_name='Width')
+    h = models.PositiveIntegerField(verbose_name='Height')
+    nr_players = models.PositiveIntegerField(verbose_name='Max Players')
+
+    descr = models.TextField(verbose_name='Description')
+    hint = models.TextField(verbose_name='Hint')
+    minimap = models.ImageField(
+        verbose_name='Minimap', upload_to=settings.MEDIA_ROOT + '/wlmaps/minimaps/')
+    file = models.FileField(verbose_name='Mapfile',
+                            upload_to=settings.MEDIA_ROOT + '/wlmaps/maps/')
+
+    world_name = models.CharField(max_length=50)
+
+    pub_date = models.DateTimeField(default=datetime.datetime.now)
+    uploader_comment = models.TextField(
+        verbose_name='Uploader comment', blank=True)
     uploader = models.ForeignKey(User)
-    nr_downloads = models.PositiveIntegerField( verbose_name = "Download count", default = 0)
+    nr_downloads = models.PositiveIntegerField(
+        verbose_name='Download count', default=0)
 
-    rating = AnonymousRatingField(range=10, can_change_vote = True)
+    rating = AnonymousRatingField(range=10, can_change_vote=True)
 
     if settings.USE_SPHINX:
         search = SphinxSearch(
-            weights = {
+            weights={
                 'name': 100,
                 'author': 60,
                 'uploader_comment': 40,
-                }
+            }
         )
 
     class Meta:
@@ -48,8 +53,8 @@
         get_latest_by = 'pub_date'
 
     @models.permalink
-    def get_absolute_url( self ):
-        return ("wlmaps_view", None, {"map_slug": self.slug } )
+    def get_absolute_url(self):
+        return ('wlmaps_view', None, {'map_slug': self.slug})
 
     def __unicode__(self):
         return u'%s by %s' % (self.name, self.author)

=== modified file 'wlmaps/test_urls.py'
--- wlmaps/test_urls.py	2009-04-04 14:32:27 +0000
+++ wlmaps/test_urls.py	2016-02-10 22:42:48 +0000
@@ -3,6 +3,5 @@
 from django.conf.urls.defaults import *
 
 urlpatterns = patterns('',
-    url(r'^wlmaps/', include("wlmaps.urls")),
-)
-
+                       url(r'^wlmaps/', include('wlmaps.urls')),
+                       )

=== modified file 'wlmaps/urls.py'
--- wlmaps/urls.py	2009-04-11 21:41:28 +0000
+++ wlmaps/urls.py	2016-02-10 22:42:48 +0000
@@ -5,12 +5,16 @@
 from views import *
 
 urlpatterns = patterns('',
-    url(r'^$', index, name="wlmaps_index" ),
-    url(r'^upload/$', upload, name = "wlmaps_upload" ),
-    
-    url(r'^(?P<map_slug>[-\w]+)/$', view, name = "wlmaps_view" ),
-    url(r'^(?P<map_slug>[-\w]+)/download/$', download, name = "wlmaps_download" ),
-    
-    url(r'^(?P<map_slug>[-\w]+)/rate/$', rate, name = "wlmaps_rate" ),
-)
-
+                       url(r'^$', index, name='wlmaps_index'),
+                       url(r'^upload/$', upload, name='wlmaps_upload'),
+
+                       url(r'^(?P<map_slug>[-\w]+)/$',
+                           view, name='wlmaps_view'),
+                       url(r'^(?P<map_slug>[-\w]+)/edit_comment/$',
+                           edit_comment, name='wlmaps_edit_comment'),
+                       url(r'^(?P<map_slug>[-\w]+)/download/$',
+                           download, name='wlmaps_download'),
+
+                       url(r'^(?P<map_slug>[-\w]+)/rate/$',
+                           rate, name='wlmaps_rate'),
+                       )

=== modified file 'wlmaps/views.py'
--- wlmaps/views.py	2013-08-09 22:49:08 +0000
+++ wlmaps/views.py	2016-02-10 22:42:48 +0000
@@ -2,7 +2,7 @@
 # encoding: utf-8
 #
 
-from forms import UploadMapForm
+from forms import UploadMapForm, EditCommentForm
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
 from django.contrib.auth.decorators import login_required
@@ -19,27 +19,26 @@
 #########
 # Views #
 #########
-def index( request ):
+def index(request):
     maps = models.Map.objects.all()
-    return render_to_response("wlmaps/index.html",
-                { "maps": maps,
-                  "maps_per_page": MAPS_PER_PAGE,
-                },
-                context_instance = RequestContext(request))
-
-def rate( request, map_slug ):
-    """
-    Rate a given map
-    """
-    if request.method != "POST":
-        return HttpResponseNotAllowed(["post"])
-
-    m = get_object_or_404( models.Map, slug = map_slug )
-
-    if not "vote" in request.POST:
+    return render_to_response('wlmaps/index.html',
+                              {'maps': maps,
+                               'maps_per_page': MAPS_PER_PAGE,
+                               },
+                              context_instance=RequestContext(request))
+
+
+def rate(request, map_slug):
+    """Rate a given map."""
+    if request.method != 'POST':
+        return HttpResponseNotAllowed(['post'])
+
+    m = get_object_or_404(models.Map, slug=map_slug)
+
+    if not 'vote' in request.POST:
         return HttpResponseBadRequest()
     try:
-        val = int(request.POST["vote"])
+        val = int(request.POST['vote'])
     except ValueError:
         return HttpResponseBadRequest()
 
@@ -50,44 +49,60 @@
                  ip_address=request.META['REMOTE_ADDR'])
     # m.save() is not needed
 
-    return HttpResponseRedirect(reverse("wlmaps_view", None, {"map_slug": m.slug }))
-
-
-def download( request, map_slug ):
-    """
-    Very simple view that just returns the binary data of this map and increases
-    the download count
-    """
-    m = get_object_or_404( models.Map, slug = map_slug )
-
-    file = open(m.file.path, "rb")
+    return HttpResponseRedirect(reverse('wlmaps_view', None, {'map_slug': m.slug}))
+
+
+def download(request, map_slug):
+    """Very simple view that just returns the binary data of this map and
+    increases the download count."""
+    m = get_object_or_404(models.Map, slug=map_slug)
+
+    file = open(m.file.path, 'rb')
     data = file.read()
-    filename = os.path.basename("%s.wmf" % m.name)
+    filename = os.path.basename('%s.wmf' % m.name)
 
     # Remember that this has been downloaded
     m.nr_downloads += 1
     m.save()
 
-    response =  HttpResponse( data, mimetype = "application/octet-stream")
+    response = HttpResponse(data, mimetype='application/octet-stream')
     response['Content-Disposition'] = 'attachment; filename="%s"' % filename
 
     return response
 
 
 def view(request, map_slug):
-    map = get_object_or_404( models.Map, slug = map_slug )
-
+    map = get_object_or_404(models.Map, slug=map_slug)
     context = {
         #"average_rating": _average_rating( map.rating ),
-        "map": map,
+        'map': map,
     }
-    return render_to_response( "wlmaps/map_detail.html",
-                              context,
-                              context_instance=RequestContext(request))
-
-
-@login_required
-def upload( request ):
+    return render_to_response('wlmaps/map_detail.html',
+                              context,
+                              context_instance=RequestContext(request))
+
+
+@login_required
+def edit_comment(request, map_slug):
+    map = get_object_or_404(models.Map, slug=map_slug)
+    if request.method == 'POST':
+        form = EditCommentForm(request.POST)
+        if form.is_valid():
+            map.uploader_comment = form.cleaned_data['uploader_comment']
+            map.save()
+            return HttpResponseRedirect(map.get_absolute_url())
+    else:
+        form = EditCommentForm(instance=map)
+
+    context = {'form': form, 'map': map}
+
+    return render_to_response('wlmaps/edit_comment.html',
+                              context,
+                              context_instance=RequestContext(request))
+
+
+@login_required
+def upload(request):
     if request.method == 'POST':
         form = UploadMapForm(request.POST, request.FILES)
         if form.is_valid():
@@ -98,7 +113,7 @@
     else:
         form = UploadMapForm()
 
-    context = { 'form': form, }
-    return render_to_response( "wlmaps/upload.html",
+    context = {'form': form, }
+    return render_to_response('wlmaps/upload.html',
                               context,
                               context_instance=RequestContext(request))


Follow ups