Example #1
0
def check_new_bm_created(sender, request, benchmark, **kwargs):
    """
    send alert to all Superusers
    """
    question = benchmark.question.first()
    if question.type == 1:
        type = 'Multiple'
    elif question.type == 2:
        type = 'Ranking'
    elif question.type == 3:
        type = 'Numeric'
    elif question.type == 4:
        type = 'Yes/No'
    elif question.type == 5:
        type = 'Range'

    recipient_list = User.objects.filter(is_superuser=True, email__isnull=False)\
                         .exclude(email__exact='')\
                         .values_list('email', flat=True)
    template = loader.get_template('alerts/new_benchmark.html')
    messages.add_message(request, MESSAGE_BM_CREATED, 'New Benchmark was created - %s' % benchmark.name )
    raw_context = get_context_variables(benchmark)
    raw_context['type'] = type
    raw_context['remaining_before_closure'] = benchmark.days_left
    context = Context(raw_context)
    if len(recipient_list) > 0:
        send_mail('New Benchmark has been created', template.render(context), None, recipient_list)
Example #2
0
def send_welcome_alert(sender, request, user, benchmark,  **kwargs):
    if not QuestionResponse.objects.filter(user=user).count() > 1:
        messages.add_message(request, MESSAGE_FIRST_ANSWER, 'Hello')
        user_email = user.email
        recipient_list = [user_email]
        template = loader.get_template('alerts/welcome_alert_email.txt')
        raw_context = get_context_variables(benchmark)
        raw_context['remaining_before_closure'] = benchmark.days_left
        raw_context['contributor_first_name'] = user.first_name
        raw_context['site_link'] = request.get_host() + reverse('bm_create')
        context = Context(raw_context)
        send_mail('Welcome', template.render(context), None, recipient_list)
Example #3
0
 def post(self, *args, **kwargs):
     """
     Handles POST requests, instantiating a form instance with the passed
     POST variables and then checked for validity.
     """
     form_class = self.get_form_class()
     form = self.get_form(form_class)
     if form.is_valid():
             template = loader.get_template('alerts/declined_benchmark.html')
             email = form.cleaned_data['Owner email']
             benchmark = Benchmark.objects.get(pk=args[1])
             raw_context = get_context_variables(benchmark)
             raw_context['reason'] = form.cleaned_data['reason']
             raw_context['remaining_before_closure'] = benchmark.days_left
             context = Context(raw_context)
             send_mail('Declined Benchmark', template.render(context), None, [email])
             return HttpResponseRedirect('/admin/bm/benchmarkpending/')
     return render(self.request, 'admin/decline_form.html', {'form': form})