120
by Holger Rapp
Initital (unusable) version of wlmaps application |
1 |
#!/usr/bin/env python -tt
|
2 |
# encoding: utf-8
|
|
3 |
#
|
|
4 |
||
402.1.2
by franku
add_hint_to_map_views |
5 |
from forms import UploadMapForm, EditCommentForm |
489.1.1
by franku
url fixes; render_to_response() -> render(); disabled tracking |
6 |
from django.shortcuts import render, get_object_or_404 |
120
by Holger Rapp
Initital (unusable) version of wlmaps application |
7 |
from django.contrib.auth.decorators import login_required |
157
by Holger Rapp
Backend for map voting is completed. 'Only' the UI is missing |
8 |
from django.http import HttpResponseRedirect, HttpResponseNotAllowed, HttpResponse, HttpResponseBadRequest |
489.1.13
by franku
django.conf.urlresolvers -> django.urls |
9 |
from django.urls import reverse |
120
by Holger Rapp
Initital (unusable) version of wlmaps application |
10 |
import models |
325.1.9
by Shevonar
Maps modul reworked and adjusted to new style. |
11 |
from settings import MAPS_PER_PAGE |
423.1.6
by franku
added comment to wl_utils.py, fixed a missing import |
12 |
from wl_utils import get_real_ip |
121
by Holger Rapp
Wlmaps application is now in a usuable state |
13 |
import os |
120
by Holger Rapp
Initital (unusable) version of wlmaps application |
14 |
|
15 |
||
16 |
#########
|
|
17 |
# Views #
|
|
18 |
#########
|
|
402.1.2
by franku
add_hint_to_map_views |
19 |
def index(request): |
325.1.9
by Shevonar
Maps modul reworked and adjusted to new style. |
20 |
maps = models.Map.objects.all() |
489.1.1
by franku
url fixes; render_to_response() -> render(); disabled tracking |
21 |
return render(request, 'wlmaps/index.html', |
402.1.2
by franku
add_hint_to_map_views |
22 |
{'maps': maps, |
23 |
'maps_per_page': MAPS_PER_PAGE, |
|
489.1.1
by franku
url fixes; render_to_response() -> render(); disabled tracking |
24 |
})
|
402.1.2
by franku
add_hint_to_map_views |
25 |
|
26 |
||
27 |
def download(request, map_slug): |
|
28 |
"""Very simple view that just returns the binary data of this map and
|
|
29 |
increases the download count."""
|
|
30 |
m = get_object_or_404(models.Map, slug=map_slug) |
|
31 |
||
32 |
file = open(m.file.path, 'rb') |
|
161
by Holger Rapp
Attempt to fix wrong downloads when getting maps |
33 |
data = file.read() |
402.1.2
by franku
add_hint_to_map_views |
34 |
filename = os.path.basename('%s.wmf' % m.name) |
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
35 |
|
161
by Holger Rapp
Attempt to fix wrong downloads when getting maps |
36 |
# Remember that this has been downloaded
|
121
by Holger Rapp
Wlmaps application is now in a usuable state |
37 |
m.nr_downloads += 1 |
459
by franku
Send notifications only if the map is newly saved, not when updating some fields, e.g. nr_downloads |
38 |
m.save(update_fields=['nr_downloads']) |
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
39 |
|
404.2.12
by franku
runthrough deprecation timeline; fixed some things; added NOCOMMs |
40 |
response = HttpResponse(data, content_type='application/octet-stream') |
363.1.1
by Shevonar
several map uploader fixes |
41 |
response['Content-Disposition'] = 'attachment; filename="%s"' % filename |
121
by Holger Rapp
Wlmaps application is now in a usuable state |
42 |
|
43 |
return response |
|
173.2.3
by Holger Rapp
Made the site compatible to django 1.1 and all the various packages |
44 |
|
121
by Holger Rapp
Wlmaps application is now in a usuable state |
45 |
|
120
by Holger Rapp
Initital (unusable) version of wlmaps application |
46 |
def view(request, map_slug): |
402.1.2
by franku
add_hint_to_map_views |
47 |
map = get_object_or_404(models.Map, slug=map_slug) |
120
by Holger Rapp
Initital (unusable) version of wlmaps application |
48 |
context = { |
402.1.2
by franku
add_hint_to_map_views |
49 |
'map': map, |
120
by Holger Rapp
Initital (unusable) version of wlmaps application |
50 |
}
|
489.1.1
by franku
url fixes; render_to_response() -> render(); disabled tracking |
51 |
return render(request, 'wlmaps/map_detail.html', |
52 |
context) |
|
402.1.2
by franku
add_hint_to_map_views |
53 |
|
54 |
||
55 |
@login_required
|
|
56 |
def edit_comment(request, map_slug): |
|
57 |
map = get_object_or_404(models.Map, slug=map_slug) |
|
58 |
if request.method == 'POST': |
|
59 |
form = EditCommentForm(request.POST) |
|
60 |
if form.is_valid(): |
|
61 |
map.uploader_comment = form.cleaned_data['uploader_comment'] |
|
460
by franku
Prevend sending notices also if a map-comment is edited |
62 |
map.save(update_fields=['uploader_comment']) |
402.1.2
by franku
add_hint_to_map_views |
63 |
return HttpResponseRedirect(map.get_absolute_url()) |
64 |
else: |
|
65 |
form = EditCommentForm(instance=map) |
|
66 |
||
67 |
context = {'form': form, 'map': map} |
|
68 |
||
489.1.1
by franku
url fixes; render_to_response() -> render(); disabled tracking |
69 |
return render(request, 'wlmaps/edit_comment.html', |
70 |
context) |
|
402.1.2
by franku
add_hint_to_map_views |
71 |
|
72 |
||
73 |
@login_required
|
|
74 |
def upload(request): |
|
325.1.9
by Shevonar
Maps modul reworked and adjusted to new style. |
75 |
if request.method == 'POST': |
76 |
form = UploadMapForm(request.POST, request.FILES) |
|
77 |
if form.is_valid(): |
|
350
by Holger Rapp
Added support for PIL. Fixed some whitespace. Fixed tests for wlmaps. |
78 |
map = form.save(commit=False) |
325.1.9
by Shevonar
Maps modul reworked and adjusted to new style. |
79 |
map.uploader = request.user |
80 |
map.save() |
|
81 |
return HttpResponseRedirect(map.get_absolute_url()) |
|
82 |
else: |
|
83 |
form = UploadMapForm() |
|
350
by Holger Rapp
Added support for PIL. Fixed some whitespace. Fixed tests for wlmaps. |
84 |
|
402.1.2
by franku
add_hint_to_map_views |
85 |
context = {'form': form, } |
489.1.1
by franku
url fixes; render_to_response() -> render(); disabled tracking |
86 |
return render(request, 'wlmaps/upload.html', |
87 |
context) |