Exemplo n.º 1
0
 def request_changes(self, request, pk=None):
     candidate_user = self.get_object()
     try:
         auth_hooks.request_user_changes(candidate_user)
         candidate_user.save()
         send_user_email(
             candidate_user.user,
             'apella/emails/user_profile_request_changes_subject.txt',
             'apella/emails/user_profile_request_changes_body.txt')
     except ValidationError as ve:
         return Response(ve.detail, status=status.HTTP_400_BAD_REQUEST)
     return Response(request.data, status=status.HTTP_200_OK)
Exemplo n.º 2
0
 def reject_application(self, request, pk=None):
     application = self.get_object()
     try:
         application.state = 'rejected'
         application.updated_at = datetime.utcnow()
         application.save()
     except ValidationError as ve:
         return Response(ve.detail, status=status.HTTP_400_BAD_REQUEST)
     send_user_email(application.user,
                     'apella/emails/user_application_accepted_subject.txt',
                     'apella/emails/user_application_rejected_body.txt',
                     {'application': application})
     return Response(request.data, status=status.HTTP_200_OK)
Exemplo n.º 3
0
 def reject_user(self, request, pk=None):
     candidate_user = self.get_object()
     try:
         reason = None
         if 'rejected_reason' in request.data:
             reason = request.data['rejected_reason']
         auth_hooks.reject_user(candidate_user, reason=reason)
         candidate_user.save()
         logger.info('user %s rejected profile %r' %
                     (request.user.username, candidate_user.id))
         send_user_email(candidate_user.user,
                         'apella/emails/user_rejected_profile_subject.txt',
                         'apella/emails/user_rejected_profile_body.txt')
     except ValidationError as ve:
         return Response(ve.detail, status=status.HTTP_400_BAD_REQUEST)
     return Response(request.data, status=status.HTTP_200_OK)
Exemplo n.º 4
0
def send_registry_emails(members, department):
    department_title_el = department.title.el
    department_title_en = department.title.en
    institution_title_el = department.institution.title.el
    institution_title_en = department.institution.title.en

    for professor in members:
        send_user_email(
            professor.user,
            'apella/emails/registry_add_member_to_member_subject.txt',
            'apella/emails/registry_add_member_to_member_body.txt',
            extra_context={
                'department_title_el': department_title_el,
                'department_title_en': department_title_en,
                'institution_title_el': institution_title_el,
                'institution_title_en': institution_title_en
            })
Exemplo n.º 5
0
    def handle(self, *args, **options):
        template_body = options['template_body']
        shibboleth = options['shibboleth']
        candidate = options['candidate']
        foreign = options['foreign']
        subject = options['template_subject']
        list_emails = options['list']

        if not subject:
            raise CommandError('no subject')

        if not template_body:
            raise CommandError('no body')

        emails = []
        if shibboleth:
            emails = OldUsers.objects. \
                filter(role_status='ACTIVE'). \
                exclude(shibboleth_id=''). \
                values_list('email', flat=True).distinct()
        elif foreign:
            emails = OldUsers.objects. \
                filter(role_status='ACTIVE', is_foreign='t'). \
                values_list('email', flat=True).distinct()
        elif candidate:
            candidates = OldUsers.objects.filter(
                role_status='ACTIVE', shibboleth_id='',
                permanent_auth_token='', role='candidate')
            for c in candidates:
                if not OldUsers.objects.filter(
                    email=c.email, role='professor').exists():
                        emails.append(c.email)



        for email in emails:
            if list_emails:
                self.stdout.write(email)
            else:
                old_users = OldUsers.objects.filter(email__iexact=email)
                send_user_email(
                    old_users[0],
                    subject,
                    template_body
                    )
                self.stdout.write('email sent to %s' % email)
Exemplo n.º 6
0
 def verify_user(self, request, pk=None):
     candidate_user = self.get_object()
     try:
         auth_hooks.verify_user(candidate_user)
         if isinstance(candidate_user, ProfessorModel) and not\
             candidate_user.user.shibboleth_id and \
             candidate_user.institution and \
             candidate_user.institution.has_shibboleth:
             candidate_user.user.can_set_academic = True
             candidate_user.user.save()
         candidate_user.save()
         logger.info('user %s verified profile %r' %
                     (request.user.username, candidate_user.id))
         send_user_email(candidate_user.user,
                         'apella/emails/user_verified_profile_subject.txt',
                         'apella/emails/user_verified_profile_body.txt')
     except ValidationError as ve:
         return Response(ve.detail, status=status.HTTP_400_BAD_REQUEST)
     return Response(request.data, status=status.HTTP_200_OK)