コード例 #1
0
ファイル: models.py プロジェクト: IntersectAustralia/asvo-tao
 def save(self, *args, **kwargs):
     super(Job, self).save(*args, **kwargs)
     if self.var_cache['status'] != getattr(self, 'status') and getattr(self, 'status') == Job.COMPLETED:
         send_mail('job-status',
                   {'job': self, 'user': self.user},
                   '[ASVO-TAO] Catalogue status update',
                   (self.user.email,))
コード例 #2
0
def register(request):
    if hasattr(request,'user') and hasattr(request.user,'account_registration_status'):
        if request.user.account_registration_status != TaoUser.RS_EMPTY:
            return redirect(account_status)
    from tao.forms import UserCreationForm
    if request.method == 'POST':
        form = UserCreationForm(request.POST, user=request.user)
        if form.is_valid():
            form.save()
            
            admin_emails = TaoUser.objects.admin_emails()
            context = Context({
                          'pending_requests_url': request.build_absolute_uri(reverse('access_requests')),
                          'user': form.cleaned_data
                      })
            send_mail("registration", context, "Registration submitted", admin_emails)
            
            messages.info(request, _("You will receive an email when your request has been approved."))
            return redirect(home)
    else:
        form = UserCreationForm(user=request.user)
        
    return render(request, "register.html", {
        'form': form,
        'user': request.user,
    })
コード例 #3
0
def support(request):
    if not hasattr(request,'user') or not hasattr(request.user,'is_aaf'):
        return redirect(login)
    if request.user.is_aaf() and request.user.account_registration_status == TaoUser.RS_EMPTY:
        return redirect(register)
    if request.user.is_aaf() and request.user.account_registration_status == TaoUser.RS_REJECTED:
        return redirect(account_status)
    from tao.forms import SupportForm
    if request.method == 'POST':
        form = SupportForm(request.POST)
        if form.is_valid():
            to_addrs = _get_support_recipients()
            context = Context({'subject': form.cleaned_data['subject'], 'message': form.cleaned_data['message'], 'user': request.user})
            username = request.user.username
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']
            user_email = models.TaoUser.objects.get(username=username).email
            logger.info('Support email from ' + username)
            logger.info('Subject: ' + subject)
            logger.info('Message: ' + message)
            send_mail('support-template', context, 'TAO Support: ' + subject, [user_email], bcc=to_addrs)
            return render(request, 'email_sent.html')
        else:
            message = 'Please fill in required fields'
            messages.info(request, mark_safe(message))
    else:
        form = SupportForm()

    return render(request, 'support.html', {
        'form': form,
    })
コード例 #4
0
def reject_user(request, user_id):
    reason = request.POST['reason']
    u = models.TaoUser.objects.get(pk=user_id)
    u.reject_user(reason)
    u.save()


    template_name = 'reject'
    context = Context({'title': u.title, 'first_name': u.first_name, 'last_name': u.last_name, 'reason': reason})
    subject = settings.EMAIL_REJECT_SUBJECT
    to_addrs = [u.email]

    send_mail(template_name, context, subject, to_addrs)

    return redirect(access_requests)
コード例 #5
0
def approve_user(request, user_id):
    u = models.TaoUser.objects.get(pk=user_id)
    u.activate_user()
    u.save()

    template_name = 'approve'
    subject = settings.EMAIL_ACCEPT_SUBJECT
    to_addrs = [u.email]
    context = Context({
        'title': u.title,
        'first_name': u.first_name,
        'last_name': u.last_name,
        'login_url': request.build_absolute_uri(reverse('login')),
    })

    send_mail(template_name, context, subject, to_addrs)

    return redirect(access_requests)