~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to notification/views.py

  • Committer: franku
  • Author(s): GunChleoc
  • Date: 2016-12-13 18:30:38 UTC
  • mfrom: (438.1.6 pyformat_util)
  • Revision ID: somal@arcor.de-20161213183038-5cgmvfh2fkgmoc1s
adding a script to run pyformat over the code base

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from notification.decorators import basic_auth_required, simple_basic_auth_callback
10
10
from notification.feeds import NoticeUserFeed
11
11
 
 
12
 
12
13
@basic_auth_required(realm='Notices Feed', callback_func=simple_basic_auth_callback)
13
14
def feed_for_user(request):
14
 
    url = "feed/%s" % request.user.username
 
15
    url = 'feed/%s' % request.user.username
15
16
    return Feed(request, url, {
16
 
        "feed": NoticeUserFeed,
 
17
        'feed': NoticeUserFeed,
17
18
    })
18
19
 
 
20
 
19
21
@login_required
20
22
def notices(request):
21
23
    notice_types = NoticeType.objects.all()
24
26
    for notice_type in NoticeType.objects.all():
25
27
        settings_row = []
26
28
        for medium_id, medium_display in NOTICE_MEDIA:
27
 
            form_label = "%s_%s" % (notice_type.label, medium_id)
28
 
            setting = get_notification_setting(request.user, notice_type, medium_id)
29
 
            if request.method == "POST":
30
 
                if request.POST.get(form_label) == "on":
 
29
            form_label = '%s_%s' % (notice_type.label, medium_id)
 
30
            setting = get_notification_setting(
 
31
                request.user, notice_type, medium_id)
 
32
            if request.method == 'POST':
 
33
                if request.POST.get(form_label) == 'on':
31
34
                    setting.send = True
32
35
                else:
33
36
                    setting.send = False
34
37
                setting.save()
35
38
            settings_row.append((form_label, setting.send))
36
 
        settings_table.append({"notice_type": notice_type, "cells": settings_row})
37
 
    
 
39
        settings_table.append(
 
40
            {'notice_type': notice_type, 'cells': settings_row})
 
41
 
38
42
    notice_settings = {
39
 
        "column_headers": [medium_display for medium_id, medium_display in NOTICE_MEDIA],
40
 
        "rows": settings_table,
 
43
        'column_headers': [medium_display for medium_id, medium_display in NOTICE_MEDIA],
 
44
        'rows': settings_table,
41
45
    }
42
 
    
43
 
    return render_to_response("notification/notices.html", {
44
 
        "notices": notices,
45
 
        "notice_types": notice_types,
46
 
        "notice_settings": notice_settings,
 
46
 
 
47
    return render_to_response('notification/notices.html', {
 
48
        'notices': notices,
 
49
        'notice_types': notice_types,
 
50
        'notice_settings': notice_settings,
47
51
    }, context_instance=RequestContext(request))
48
52
 
 
53
 
49
54
@login_required
50
55
def single(request, id):
51
56
    notice = get_object_or_404(Notice, id=id)
52
57
    if request.user == notice.user:
53
 
        return render_to_response("notification/single.html", {
54
 
            "notice": notice,
 
58
        return render_to_response('notification/single.html', {
 
59
            'notice': notice,
55
60
        }, context_instance=RequestContext(request))
56
61
    raise Http404
57
62
 
 
63
 
58
64
@login_required
59
65
def archive(request, noticeid=None, next_page=None):
60
66
    if noticeid:
69
75
            return HttpResponseRedirect(next_page)
70
76
    return HttpResponseRedirect(next_page)
71
77
 
 
78
 
72
79
@login_required
73
80
def delete(request, noticeid=None, next_page=None):
74
81
    if noticeid:
83
90
            return HttpResponseRedirect(next_page)
84
91
    return HttpResponseRedirect(next_page)
85
92
 
 
93
 
86
94
@login_required
87
95
def mark_all_seen(request):
88
96
    for notice in Notice.objects.notices_for(request.user, unseen=True):
89
97
        notice.unseen = False
90
98
        notice.save()
91
 
    return HttpResponseRedirect(reverse("notification_notices"))
92
 
    
 
 
b'\\ No newline at end of file'
 
99
    return HttpResponseRedirect(reverse('notification_notices'))