def handle(self, request, goal_slug, suggestion_slug): suggestion = get_object_or_404(Suggestion, slug=suggestion_slug) is_posting = request.method == 'POST' submit = request.POST.get('submit', 'none') bound_form = None if is_posting: if submit == 'cancel': return self.on_cancel(request.goal.slug) if submit == 'delete': suggestion.delete() return self.on_cancel(request.goal.slug) bound_form = SuggestionForm.get_posted_form(request, suggestion) if bound_form.create_new_revision(suggestion): return self.on_save(request.goal.slug, suggestion.slug) form = (bound_form if is_posting else SuggestionForm.get_populated_form(request, suggestion)) context = { 'form': form, 'show_image_form': False, 'show_errors': True, 'post_button_label': "Update", 'submit_button_header': 'Press Update to publish your changes', 'show_delete_button': True, } return render(request, 'suggestion/edit_suggestion.html', context)
def handle(self, request, goal_slug, suggestion_slug): suggestion = get_object_or_404(Suggestion, slug=suggestion_slug) is_posting = request.method == 'POST' submit = request.POST.get('submit', 'none') bound_form = None if is_posting: if submit == 'cancel': return self.on_cancel(request.goal.slug) if submit == 'delete': suggestion.delete() return self.on_cancel(request.goal.slug) bound_form = SuggestionForm.get_posted_form(request, suggestion) if bound_form.create_new_revision(suggestion): return self.on_save(request.goal.slug, suggestion.slug) form = ( bound_form if is_posting else SuggestionForm.get_populated_form(request, suggestion) ) context = { 'form': form, 'show_image_form': False, 'show_errors': True, 'post_button_label': "Update", 'submit_button_header': 'Press Update to publish your changes', 'show_delete_button': True, } return render(request, 'suggestion/edit_suggestion.html', context)
def handle(self, request, goal_slug): suggestion = SuggestionForm.get_or_create_draft( request.goal, request.global_user) is_posting = request.method == 'POST' submit = request.POST.get('submit', 'none') bound_form = None if is_posting: bound_form = SuggestionForm.get_posted_form(request, suggestion) should_accept_data = bound_form.update_suggestion_and_save( suggestion, submit) if should_accept_data and submit == 'save': return self.on_save(request.goal.slug, suggestion.slug) elif submit == 'cancel': return self.on_cancel(request.goal.slug) if is_posting and submit == 'save': form = bound_form else: form = SuggestionForm.get_populated_form(request, suggestion) context = { 'form': form, 'crop_settings': { 'url': suggestion.image.url if suggestion.image else "", 'klass': 'suggestion--image crop-image', 'output_key': form.cropped_image_key, 'jcrop': dict( aspectRatio=360.0 / 200.0, setSelect=[0, 0, 10000, 10000], ), }, 'show_image_form': True, 'show_errors': submit == 'save', 'post_button_label': 'Submit', 'submit_button_header': ('All done, press Submit to publish your suggestion'), 'show_delete_button': False } return render(request, 'suggestion/edit_suggestion.html', context)
def handle(self, request, goal_slug): suggestion = SuggestionForm.get_or_create_draft( request.goal, request.global_user) is_posting = request.method == 'POST' submit = request.POST.get('submit', 'none') bound_form = None if is_posting: bound_form = SuggestionForm.get_posted_form(request, suggestion) should_accept_data = bound_form.update_suggestion_and_save( suggestion, submit) if should_accept_data and submit == 'save': return self.on_save(request.goal.slug, suggestion.slug) elif submit == 'cancel': return self.on_cancel(request.goal.slug) if is_posting and submit == 'save': form = bound_form else: form = SuggestionForm.get_populated_form(request, suggestion) context = { 'form': form, 'crop_settings': { 'url': suggestion.image.url if suggestion.image else "", 'klass': 'suggestion--image crop-image', 'output_key': form.cropped_image_key, 'jcrop': dict( aspectRatio=360.0 / 200.0, setSelect=[0, 0, 10000, 10000], ), }, 'show_image_form': True, 'show_errors': submit == 'save', 'post_button_label': 'Submit', 'submit_button_header': ( 'All done, press Submit to publish your suggestion' ), 'show_delete_button': False } return render(request, 'suggestion/edit_suggestion.html', context)