Esempio n. 1
0
 def get_next_state(self, request, application, auth):
     """ Retrieve the next state. """
     application.reopen()
     link, is_secret = base.get_email_link(application)
     emails.send_invite_email(application, link, is_secret)
     messages.success(request, "Sent an invitation to %s." % (application.applicant.email))
     return self._on_success
Esempio n. 2
0
 def view(self, request, application, label, auth, actions):
     """ Django view method. """
     if self.check_authorised(request, application, auth):
         auth['can_approve'] = True
     if label == "approve" and auth['can_approve']:
         tmp_actions = []
         if 'approve' in actions:
             tmp_actions.append("approve")
         if 'duplicate' in actions:
             tmp_actions.append("duplicate")
         actions = tmp_actions
         application_form = self.get_approve_form(
             request, application, auth)
         form = application_form(request.POST or None, instance=application)
         if request.method == 'POST':
             if 'duplicate' in request.POST:
                 return 'duplicate'
             if form.is_valid():
                 form.save()
                 return "approve"
         return render_to_response(
             self.template_approve,
             {'application': application, 'form': form,
                 'authorised_text': self.authorised_text,
                 'actions': actions, 'auth': auth},
             context_instance=RequestContext(request))
     elif label == "decline" and auth['can_approve']:
         actions = ['cancel']
         if request.method == 'POST':
             form = EmailForm(request.POST)
             if form.is_valid():
                 to_email = application.applicant.email
                 subject, body = form.get_data()
                 emails.send_mail(
                     subject, body,
                     settings.ACCOUNTS_EMAIL, [to_email])
                 return "cancel"
         else:
             link, is_secret = base.get_email_link(application)
             subject, body = emails.render_email(
                 'common_declined',
                 {'receiver': application.applicant,
                     'authorised_text': self.authorised_text,
                     'application': application,
                     'link': link, 'is_secret': is_secret})
             initial_data = {'body': body, 'subject': subject}
             form = EmailForm(initial=initial_data)
         return render_to_response(
             self.template_decline,
             {'application': application, 'form': form,
                 'authorised_text': self.authorised_text,
                 'actions': actions, 'auth': auth},
             context_instance=RequestContext(request))
     self.context = {
         'authorised_text': self.authorised_text,
     }
     return super(StateWaitingForApproval, self).view(
         request, application, label, auth, actions)
Esempio n. 3
0
 def view(self, request, application, label, auth, actions):
     """ Django view method. """
     if label is None and auth["is_applicant"] and not auth["is_admin"]:
         for action in actions:
             if action in request.POST:
                 return action
         link, is_secret = base.get_email_link(application)
         return render_to_response(
             "applications/software_introduction.html",
             {"actions": actions, "application": application, "auth": auth, "link": link, "is_secret": is_secret},
             context_instance=RequestContext(request),
         )
     return super(StateIntroduction, self).view(request, application, label, auth, actions)
Esempio n. 4
0
 def view(self, request, application, label, auth, actions):
     """ Django view method. """
     if application.content_type.model == 'applicant':
         if not application.applicant.email_verified:
             application.applicant.email_verified = True
             application.applicant.save()
     for action in actions:
         if action in request.POST:
             return action
     link, is_secret = base.get_email_link(application)
     return render_to_response('applications/project_aed_introduction.html',
             {'actions': actions, 'application': application, 'auth': auth,
             'link': link, 'is_secret': is_secret },
             context_instance=RequestContext(request))
Esempio n. 5
0
    def get_next_state(self, request, application, auth):
        """ Retrieve the next state. """
        # Check for serious errors in submission.
        # Should only happen in rare circumstances.
        errors = application.check()
        if len(errors) > 0:
            for error in errors:
                messages.error(request, error)
            return self._on_error

        # approve application
        approved_by = request.user
        created_person, created_account = application.approve(approved_by)

        # send email
        link, is_secret = base.get_email_link(application)
        emails.send_approved_email(application, created_person, created_account, link, is_secret)

        if created_person or created_account:
            return self._on_password_needed
        else:
            return self._on_password_ok
Esempio n. 6
0
 def view(self, request, application, label, auth, actions):
     """ Django view method. """
     if self.check_authorised(request, application, auth):
         auth["can_approve"] = True
     if label == "approve" and auth["can_approve"]:
         tmp_actions = []
         if "approve" in actions:
             tmp_actions.append("approve")
         if "duplicate" in actions:
             tmp_actions.append("duplicate")
         actions = tmp_actions
         application_form = self.get_approve_form(request, application, auth)
         form = application_form(request.POST or None, instance=application)
         if request.method == "POST":
             if form.is_valid():
                 form.save()
                 return "approve"
         return render_to_response(
             self.template_approve,
             {
                 "application": application,
                 "form": form,
                 "authorised_text": self.authorised_text,
                 "actions": actions,
                 "auth": auth,
             },
             context_instance=RequestContext(request),
         )
     elif label == "decline" and auth["can_approve"]:
         actions = ["cancel"]
         if request.method == "POST":
             form = EmailForm(request.POST)
             if form.is_valid():
                 to_email = application.applicant.email
                 subject, body = form.get_data()
                 emails.send_mail(subject, body, settings.ACCOUNTS_EMAIL, [to_email])
                 return "cancel"
         else:
             link, is_secret = base.get_email_link(application)
             subject, body = emails.render_email(
                 "common_declined",
                 {
                     "receiver": application.applicant,
                     "authorised_text": self.authorised_text,
                     "application": application,
                     "link": link,
                     "is_secret": is_secret,
                 },
             )
             initial_data = {"body": body, "subject": subject}
             form = EmailForm(initial=initial_data)
         return render_to_response(
             self.template_decline,
             {
                 "application": application,
                 "form": form,
                 "authorised_text": self.authorised_text,
                 "actions": actions,
                 "auth": auth,
             },
             context_instance=RequestContext(request),
         )
     self.context = {"authorised_text": self.authorised_text}
     return super(StateWaitingForApproval, self).view(request, application, label, auth, actions)