Skip to content

Commit a3075d8

Browse files
committed
#99 refactored checklist update view
1 parent a923f2c commit a3075d8

File tree

5 files changed

+71
-30
lines changed

5 files changed

+71
-30
lines changed

core/checklist_urls.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22

33
from core.views.checklist_views import CreateChecklistItemView, DeleteChecklistItemView, \
44
GetChecklistItemsForTodayView, GetChecklistItemsView, \
5-
UpdateChecklistItemView, UpdateChecklistPriorityView
5+
UpdateChecklistItemNameView, UpdateChecklistPriorityView, \
6+
UpdateChecklistItemStatusView, UpdateChecklistItemConditionView
67

78
app_name = 'checklist'
9+
10+
811
urlpatterns = [
912
url(r'^get_checklist_items/?$', GetChecklistItemsView.as_view(),
1013
name='get_checklist_items'),
1114
url(r'^get_checklist_items_for_today/?$', GetChecklistItemsForTodayView.as_view(),
1215
name='get_checklist_items_for_today'),
1316
url(r'^add_checklist_item/?$', CreateChecklistItemView.as_view(),
1417
name='add_checklist_item'),
15-
url(r'^update_checklist_item/?$', UpdateChecklistItemView.as_view(),
16-
name='update_checklist_item'),
1718
url(r'^delete_checklist_item/?$', DeleteChecklistItemView.as_view(),
1819
name='delete_checklist_item'),
20+
21+
url(r'^update_checklist_item_name/?$', UpdateChecklistItemNameView.as_view(),
22+
name='update_checklist_item_name'),
23+
url(r'^update_checklist_item_condition/?$', UpdateChecklistItemConditionView.as_view(),
24+
name='update_checklist_item_condition'),
25+
url(r'^update_checklist_item_status/?$', UpdateChecklistItemStatusView.as_view(),
26+
name='update_checklist_item_status'),
1927
url(r'^update_checklist_priority/?$', UpdateChecklistPriorityView.as_view(),
2028
name='update_checklist_priority'),
2129
]

core/static/core/js/checklist_settings_handler.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ $('document').ready( function (){
9393
checklist_item_id: elem.closest('.checklist_item_container').attr('id'),
9494
checklist_item_name: elem.val()
9595
};
96-
$.post("/checklist/update_checklist_item", params);
96+
$.post("/checklist/update_checklist_item_name", params);
9797
elem.closest('.checklist_item_container').find('.checklist_item_saved').removeClass('invisible');
9898
}
9999
$('#checklist_items').on('focusout', '.checklist_item_name', function() {
@@ -126,7 +126,8 @@ $('document').ready( function (){
126126
checklist_item_id: elem.closest('.checklist_item_container').attr('id'),
127127
checklist_item_matchdays: matchdays_comma_seperated
128128
};
129-
$.post("/checklist/update_checklist_item", params);
129+
$.post("/checklist/update_checklist_item_condition", params);
130+
console.log(params);
130131
elem.closest('.checklist_item_container').find('.checklist_item_saved').removeClass('invisible');
131132
}
132133
$('#checklist_items').on('focusout', '.checklist_item_matchdays', function() {
@@ -157,7 +158,7 @@ $('document').ready( function (){
157158
checklist_item_id: elem.closest('.checklist_item_container').attr('id'),
158159
checklist_item_matchday_pattern: matchday_pattern
159160
};
160-
$.post("/checklist/update_checklist_item", params);
161+
$.post("/checklist/update_checklist_item_condition", params);
161162
elem.closest('.checklist_item_container').find('.checklist_item_saved').removeClass('invisible');
162163
}
163164
$('#checklist_items').on('focusout', '.checklist_item_matchday_pattern', function() {
@@ -220,7 +221,7 @@ $('document').ready( function (){
220221
params['checklist_item_everyday'] = true;
221222
}
222223

223-
$.post("/checklist/update_checklist_item", params);
224+
$.post("/checklist/update_checklist_item_condition", params);
224225
});
225226

226227

core/static/core/js/checklist_user_handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $('document').ready( function (){
5252
checklist_item_id: $(this).attr('id'),
5353
checklist_item_checked: checklistItemGotChecked
5454
};
55-
$.post("/checklist/update_checklist_item", params);
55+
$.post("/checklist/update_checklist_item_status", params);
5656

5757
if (checklistItemGotChecked) {
5858
checklistItem.removeClass('glyphicon-unchecked');

core/tests/unit/views/test_checklist_settings_view.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_create_standard_checklist_item(self):
5757

5858
def test_update_checklist_item_name(self):
5959
self.client.login(username='temporary', password='temporary')
60-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
60+
response = self.client.post(reverse('core:checklist:update_checklist_item_name'),
6161
{'checklist_item_id': self.checklist_item.id,
6262
'checklist_item_name': 'do even more unit tests'
6363
})
@@ -73,7 +73,7 @@ def test_update_checklist_item_name(self):
7373

7474
def test_update_checklist_item_home_match(self):
7575
self.client.login(username='temporary', password='temporary')
76-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
76+
response = self.client.post(reverse('core:checklist:update_checklist_item_condition'),
7777
{'checklist_item_id': self.checklist_item.id,
7878
'checklist_item_home_match': True
7979
})
@@ -95,7 +95,7 @@ def test_update_checklist_item_home_match(self):
9595

9696
def test_update_checklist_item_matchday(self):
9797
self.client.login(username='temporary', password='temporary')
98-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
98+
response = self.client.post(reverse('core:checklist:update_checklist_item_condition'),
9999
{'checklist_item_id': self.checklist_item.id,
100100
'checklist_item_matchdays': '4'
101101
})
@@ -117,7 +117,7 @@ def test_update_checklist_item_matchday(self):
117117

118118
def test_update_checklist_item_matchdays(self):
119119
self.client.login(username='temporary', password='temporary')
120-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
120+
response = self.client.post(reverse('core:checklist:update_checklist_item_condition'),
121121
{'checklist_item_id': self.checklist_item.id,
122122
'checklist_item_matchdays': '3,33'
123123
})
@@ -139,7 +139,7 @@ def test_update_checklist_item_matchdays(self):
139139

140140
def test_update_checklist_item_matchday_pattern(self):
141141
self.client.login(username='temporary', password='temporary')
142-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
142+
response = self.client.post(reverse('core:checklist:update_checklist_item_condition'),
143143
{'checklist_item_id': self.checklist_item.id,
144144
'checklist_item_matchday_pattern': 2
145145
})
@@ -161,7 +161,7 @@ def test_update_checklist_item_matchday_pattern(self):
161161

162162
def test_update_checklist_item_everyday(self):
163163
self.client.login(username='temporary', password='temporary')
164-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
164+
response = self.client.post(reverse('core:checklist:update_checklist_item_condition'),
165165
{'checklist_item_id': self.checklist_item.id,
166166
'checklist_item_everyday': True
167167
})
@@ -182,7 +182,7 @@ def test_update_checklist_item_everyday(self):
182182

183183
def test_update_checklist_item_checked(self):
184184
self.client.login(username='temporary', password='temporary')
185-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
185+
response = self.client.post(reverse('core:checklist:update_checklist_item_status'),
186186
{'checklist_item_id': self.checklist_item.id,
187187
'checklist_item_checked': 'true'
188188
})
@@ -199,7 +199,7 @@ def test_update_checklist_item_checked(self):
199199

200200
def test_update_checklist_item_unchecked(self):
201201
self.client.login(username='temporary', password='temporary')
202-
response = self.client.post(reverse('core:checklist:update_checklist_item'),
202+
response = self.client.post(reverse('core:checklist:update_checklist_item_status'),
203203
{'checklist_item_id': self.checklist_item.id,
204204
'checklist_item_checked': 'false'
205205
})

core/views/checklist_views.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,42 +92,74 @@ def post(self, request, *args, **kwargs):
9292

9393

9494
@method_decorator(login_required, name='dispatch')
95-
class UpdateChecklistItemView(JSONResponseMixin, View):
95+
class UpdateChecklistItemNameView(JSONResponseMixin, View):
9696
def post(self, request, *args, **kwargs):
9797
checklist_item_id = request.POST.get('checklist_item_id')
9898
checklist_item_name = request.POST.get('checklist_item_name')
99+
100+
checklist_item = ChecklistItem.objects.get(checklist__user=request.user, id=checklist_item_id)
101+
102+
if checklist_item:
103+
checklist_item.name = checklist_item_name
104+
checklist_item.save()
105+
return self.render_json_response({'success': True})
106+
107+
return self.render_json_response({'success': False})
108+
109+
110+
@method_decorator(login_required, name='dispatch')
111+
class UpdateChecklistItemStatusView(JSONResponseMixin, View):
112+
def post(self, request, *args, **kwargs):
113+
checklist_item_id = request.POST.get('checklist_item_id')
114+
checklist_item_checked = request.POST.get('checklist_item_checked')
115+
116+
checklist_item = ChecklistItem.objects.get(checklist__user=request.user, id=checklist_item_id)
117+
118+
if checklist_item:
119+
if checklist_item_checked == 'true':
120+
checklist_item.last_checked_on_matchday = Matchday.get_current()
121+
elif checklist_item_checked == 'false':
122+
checklist_item.last_checked_on_matchday = None
123+
checklist_item.save()
124+
return self.render_json_response({'success': True})
125+
126+
return self.render_json_response({'success': False})
127+
128+
129+
@method_decorator(login_required, name='dispatch')
130+
class UpdateChecklistItemConditionView(JSONResponseMixin, View):
131+
def post(self, request, *args, **kwargs):
132+
checklist_item_id = request.POST.get('checklist_item_id')
99133
checklist_item_matchdays = request.POST.get('checklist_item_matchdays')
100134
checklist_item_matchday_pattern = request.POST.get('checklist_item_matchday_pattern')
101135
checklist_item_home_match = request.POST.get('checklist_item_home_match')
102136
checklist_item_everyday = request.POST.get('checklist_item_everyday')
103-
checklist_item_checked = request.POST.get('checklist_item_checked')
137+
print(checklist_item_id)
138+
print(checklist_item_matchdays)
139+
print(checklist_item_matchday_pattern)
140+
print(checklist_item_home_match)
141+
print(checklist_item_everyday)
104142

105143
checklist_item = ChecklistItem.objects.get(checklist__user=request.user, id=checklist_item_id)
106144

107145
if checklist_item:
108-
self._handle_checklist_item_update(checklist_item, checklist_item_checked, checklist_item_everyday,
109-
checklist_item_home_match, checklist_item_matchday_pattern,
110-
checklist_item_matchdays, checklist_item_name)
146+
self._handle_checklist_item_update(checklist_item, checklist_item_everyday, checklist_item_home_match,
147+
checklist_item_matchday_pattern, checklist_item_matchdays)
111148
return self.render_json_response({'success': True})
149+
112150
return self.render_json_response({'success': False})
113151

114-
def _handle_checklist_item_update(self, checklist_item, checklist_item_checked, checklist_item_everyday,
152+
def _handle_checklist_item_update(self, checklist_item, checklist_item_everyday,
115153
checklist_item_home_match, checklist_item_matchday_pattern,
116-
checklist_item_matchdays, checklist_item_name):
117-
if checklist_item_name:
118-
checklist_item.name = checklist_item_name
119-
elif checklist_item_matchdays:
154+
checklist_item_matchdays):
155+
if checklist_item_matchdays:
120156
self._update_checklist_item_condition(checklist_item, checklist_item_matchdays, None, False)
121157
elif checklist_item_matchday_pattern:
122158
self._update_checklist_item_condition(checklist_item, None, checklist_item_matchday_pattern, False)
123159
elif checklist_item_home_match:
124160
self._update_checklist_item_condition(checklist_item, None, None, True)
125161
elif checklist_item_everyday:
126162
self._update_checklist_item_condition(checklist_item, None, None, False)
127-
elif checklist_item_checked == 'true':
128-
checklist_item.last_checked_on_matchday = Matchday.get_current()
129-
elif checklist_item_checked == 'false':
130-
checklist_item.last_checked_on_matchday = None
131163
checklist_item.save()
132164

133165
@staticmethod

0 commit comments

Comments
 (0)