~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlmaps/views.py

  • Committer: franku
  • Date: 2018-11-21 17:54:32 UTC
  • mfrom: (508.1.1 widelands)
  • Revision ID: somal@arcor.de-20181121175432-8rc3h0332xmgmma4
merged trunk, resolved conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
                               })
25
25
 
26
26
 
27
 
def rate(request, map_slug):
28
 
    """Rate a given map."""
29
 
    if request.method != 'POST':
30
 
        return HttpResponseNotAllowed(['post'])
31
 
 
32
 
    m = get_object_or_404(models.Map, slug=map_slug)
33
 
 
34
 
    if not 'vote' in request.POST:
35
 
        return HttpResponseBadRequest()
36
 
    try:
37
 
        val = int(request.POST['vote'])
38
 
    except ValueError:
39
 
        return HttpResponseBadRequest()
40
 
 
41
 
    if not (0 < val <= 10):
42
 
        return HttpResponseBadRequest()
43
 
 
44
 
    m.rating.add(score=val, user=request.user,
45
 
                 ip_address=get_real_ip(request))
46
 
 
47
 
    # m.save() is called in djangoratings.fields.add for each instance
48
 
 
49
 
    return HttpResponseRedirect(reverse('wlmaps_view', kwargs= {'map_slug': m.slug}))
50
 
 
51
 
 
52
27
def download(request, map_slug):
53
28
    """Very simple view that just returns the binary data of this map and
54
29
    increases the download count."""