diff options
author | 2019-07-01 15:17:52 -0400 | |
---|---|---|
committer | 2019-07-02 08:22:36 -0400 | |
commit | 08ed74b95826a907ba8f9797002ef98eb2e82424 (patch) | |
tree | f4dc0936b418fed16a6e18f3338a5b6760d241bf /src/workflow/models.py | |
parent | 8149a888fe6f7c1c3b1b3be2b3996c6d225d5a53 (diff) |
add post to steps (LAAS-32)
Change-Id: I3fa53c399f914d7daa8ffb5d8640a153de555421
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/workflow/models.py')
-rw-r--r-- | src/workflow/models.py | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/workflow/models.py b/src/workflow/models.py index 6c6bd9a..866f442 100644 --- a/src/workflow/models.py +++ b/src/workflow/models.py @@ -8,8 +8,7 @@ ############################################################################## -from django.shortcuts import render -from django.contrib import messages +from django.template.loader import get_template from django.http import HttpResponse from django.utils import timezone @@ -219,12 +218,19 @@ class WorkflowStep(object): return context def render(self, request): - self.context = self.get_context() - return render(request, self.template, self.context) + return HttpResponse(self.render_to_string(request)) + + def render_to_string(self, request): + template = get_template(self.template) + return template.render(self.get_context(), request) def post_render(self, request): + self.post(request.POST, request.user) return self.render(request) + def post(self, post_content, user): + raise Exception("WorkflowStep subclass of type " + str(type(self)) + " has no concrete post() method") + def test_render(self, request): if request.method == "POST": return self.post_render(request) @@ -263,22 +269,18 @@ class AbstractSelectOrCreate(WorkflowStep): def alert_bundle_missing(self): # override in subclasses to change message if field isn't filled out self.set_invalid("Please select a valid bundle") - def post_render(self, request): - context = self.get_context() - form = self.form(request.POST, queryset=self.get_form_queryset()) + def post(self, post_data, user): + form = self.form(post_data, queryset=self.get_form_queryset()) if form.is_valid(): bundle = form.get_validated_bundle() if not bundle: self.alert_bundle_missing() - return render(request, self.template, context) + return self.repo_put(self.select_repo_key, bundle) self.put_confirm_info(bundle) self.set_valid("Step Completed") else: self.alert_bundle_missing() - messages.add_message(request, messages.ERROR, "Form Didn't Validate", fail_silently=True) - - return self.render(request) def get_context(self): default = [] @@ -323,8 +325,8 @@ class Confirmation_Step(WorkflowStep): if errors: return errors - def post_render(self, request): - form = ConfirmationForm(request.POST) + def post(self, post_data, user): + form = ConfirmationForm(post_data) if form.is_valid(): data = form.cleaned_data['confirm'] context = self.get_context() @@ -332,20 +334,18 @@ class Confirmation_Step(WorkflowStep): context["bypassed"] = "true" errors = self.flush_to_db() if errors: - messages.add_message(request, messages.ERROR, "ERROR OCCURRED: " + errors) + self.set_invalid("ERROR OCCURRED: " + errors) else: - messages.add_message(request, messages.SUCCESS, "Confirmed") + self.set_valid("Confirmed") - return HttpResponse('') elif data == "False": context["bypassed"] = "true" - messages.add_message(request, messages.SUCCESS, "Canceled") - return render(request, self.template, context) + self.set_valid("Canceled") else: - pass + self.set_invalid("Bad Form Contents") else: - pass + self.set_invalid("Bad Form Contents") class Repository(): |