~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlmaps/views.py

  • Committer: franku
  • Date: 2018-05-06 08:20:39 UTC
  • mto: This revision was merged to the branch mainline in revision 494.
  • Revision ID: somal@arcor.de-20180506082039-v8n40alffhi2ulct
This is an Attribute error

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
 
27
52
def download(request, map_slug):
28
53
    """Very simple view that just returns the binary data of this map and
29
54
    increases the download count."""