1
- from braces .views import CsrfExemptMixin , JsonRequestResponseMixin
1
+ from braces .views import JSONResponseMixin
2
2
from django .contrib .auth .decorators import login_required
3
3
from django .utils .decorators import method_decorator
4
4
from django .views import View
7
7
8
8
9
9
@method_decorator (login_required , name = 'dispatch' )
10
- class GetChecklistItemsView (CsrfExemptMixin , JsonRequestResponseMixin , View ):
10
+ class GetChecklistItemsView (JSONResponseMixin , View ):
11
11
def get (self , request , * args , ** kwargs ):
12
12
checklist_items = ChecklistItem .objects .filter (checklist__user = request .user )
13
13
@@ -17,7 +17,7 @@ def get(self, request, *args, **kwargs):
17
17
18
18
19
19
@method_decorator (login_required , name = 'dispatch' )
20
- class GetChecklistItemsForTodayView (CsrfExemptMixin , JsonRequestResponseMixin , View ):
20
+ class GetChecklistItemsForTodayView (JSONResponseMixin , View ):
21
21
def get (self , request , * args , ** kwargs ):
22
22
current_matchday = Matchday .get_current ()
23
23
home_match_tomorrow = Match .objects .filter (
@@ -66,23 +66,8 @@ def get(self, request, *args, **kwargs):
66
66
return self .render_json_response (checklist_items_json )
67
67
68
68
69
- def _get_checklist_item_in_json (checklist_item ):
70
- checklist_item_json = dict ()
71
- checklist_item_json ['id' ] = checklist_item .id
72
- checklist_item_json ['name' ] = checklist_item .name
73
- if checklist_item .to_be_checked_if_home_match_tomorrow :
74
- checklist_item_json ['type_home_match' ] = checklist_item .to_be_checked_if_home_match_tomorrow
75
- if checklist_item .to_be_checked_on_matchdays is not None :
76
- checklist_item_json ['type_matchdays' ] = checklist_item .to_be_checked_on_matchdays
77
- if checklist_item .to_be_checked_on_matchday_pattern is not None :
78
- checklist_item_json ['type_matchday_pattern' ] = checklist_item .to_be_checked_on_matchday_pattern
79
- checklist_item_json ['checked' ] = checklist_item .last_checked_on_matchday == Matchday .get_current ()
80
-
81
- return checklist_item_json
82
-
83
-
84
69
@method_decorator (login_required , name = 'dispatch' )
85
- class CreateChecklistItemView (CsrfExemptMixin , JsonRequestResponseMixin , View ):
70
+ class CreateChecklistItemView (JSONResponseMixin , View ):
86
71
def get (self , request , * args , ** kwargs ):
87
72
checklist , _ = Checklist .objects .get_or_create (user = request .user )
88
73
new_checklist_item = ChecklistItem .objects .create (checklist = checklist , name = 'Neuer Eintrag' )
@@ -93,7 +78,7 @@ def get(self, request, *args, **kwargs):
93
78
94
79
95
80
@method_decorator (login_required , name = 'dispatch' )
96
- class UpdateChecklistPriorityView (CsrfExemptMixin , JsonRequestResponseMixin , View ):
81
+ class UpdateChecklistPriorityView (JSONResponseMixin , View ):
97
82
def post (self , request , * args , ** kwargs ):
98
83
checklist_priority = request .POST .get ('checklist_priority' )
99
84
@@ -107,7 +92,7 @@ def post(self, request, *args, **kwargs):
107
92
108
93
109
94
@method_decorator (login_required , name = 'dispatch' )
110
- class UpdateChecklistItemView (CsrfExemptMixin , JsonRequestResponseMixin , View ):
95
+ class UpdateChecklistItemView (JSONResponseMixin , View ):
111
96
def post (self , request , * args , ** kwargs ):
112
97
checklist_item_id = request .POST .get ('checklist_item_id' )
113
98
checklist_item_name = request .POST .get ('checklist_item_name' )
@@ -154,11 +139,26 @@ def _update_checklist_item_condition(checklist_item, checklist_item_matchdays, c
154
139
155
140
156
141
@method_decorator (login_required , name = 'dispatch' )
157
- class DeleteChecklistItemView (CsrfExemptMixin , JsonRequestResponseMixin , View ):
142
+ class DeleteChecklistItemView (JSONResponseMixin , View ):
158
143
def post (self , request , * args , ** kwargs ):
159
144
checklist_item_id = request .POST .get ('checklist_item_id' )
160
145
checklist_item = ChecklistItem .objects .get (checklist__user = request .user , id = checklist_item_id )
161
146
if checklist_item :
162
147
checklist_item .delete ()
163
148
return self .render_json_response ({'success' : True })
164
149
return self .render_json_response ({'success' : False })
150
+
151
+
152
+ def _get_checklist_item_in_json (checklist_item ):
153
+ checklist_item_json = dict ()
154
+ checklist_item_json ['id' ] = checklist_item .id
155
+ checklist_item_json ['name' ] = checklist_item .name
156
+ if checklist_item .to_be_checked_if_home_match_tomorrow :
157
+ checklist_item_json ['type_home_match' ] = checklist_item .to_be_checked_if_home_match_tomorrow
158
+ if checklist_item .to_be_checked_on_matchdays is not None :
159
+ checklist_item_json ['type_matchdays' ] = checklist_item .to_be_checked_on_matchdays
160
+ if checklist_item .to_be_checked_on_matchday_pattern is not None :
161
+ checklist_item_json ['type_matchday_pattern' ] = checklist_item .to_be_checked_on_matchday_pattern
162
+ checklist_item_json ['checked' ] = checklist_item .last_checked_on_matchday == Matchday .get_current ()
163
+
164
+ return checklist_item_json
0 commit comments