def cancelvisit(request, visit_id): if not request.user.is_staff: raise Http404 chapter = request.user.chapter v = get_object_or_404(SchoolVisit, pk=visit_id) if (v.chapter != chapter) and not request.user.is_superuser: raise Http404 if request.method == 'POST': cancelform = CancelForm(request.POST, user=request.user, visit=v) if cancelform.is_valid(): data = cancelform.cleaned_data message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True message.from_name = chapter.name message.scheduled = False # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() # Send to everyone who has been invited id_list = EventAttendee.objects.filter( event=v.id, rsvp_status=2).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) for one_user in users: recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() message.status = 0 message.save() Event.objects.filter(id=v.id).delete() messages.success(request, message=unicode( _("Visit cancelled successfully"))) return HttpResponseRedirect('/teaching/list/') else: cancelform = CancelForm(None, user=request.user, visit=v) return render_to_response('visit_cancel.html', { 'cancelform': cancelform, 'visit_id': visit_id }, context_instance=RequestContext(request))
def cancelvisit(request, visit_id): if not request.user.is_staff: raise Http404 chapter = request.user.chapter v = get_object_or_404(SchoolVisit, pk=visit_id) if (v.chapter != chapter) and not request.user.is_superuser: raise Http404 if request.method == 'POST': cancelform = CancelForm(request.POST, user=request.user, visit=v) if cancelform.is_valid(): data = cancelform.cleaned_data message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True message.from_name = chapter.name message.scheduled = False # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() # Send to everyone who has been invited id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=2).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) for one_user in users: recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() message.status = 0 message.save() Event.objects.filter(id=v.id).delete() messages.success(request, message=unicode(_("Visit cancelled successfully"))) return HttpResponseRedirect('/teaching/list/') else: cancelform = CancelForm(None, user=request.user, visit=v) return render_to_response('visit_cancel.html', {'cancelform': cancelform, 'visit_id': visit_id}, context_instance=RequestContext(request))
def rsvpemail(request, conf_id): # Superuser check if not request.user.is_superuser: raise Http404 conf = get_object_or_404(Conference, pk=conf_id) chapter = request.user.chapter # Determine if form has been POSTed back if request.method == 'POST': # Validate email form data emailform = EmailAttendeesForm(request.POST, conference=conf, user=request.user) if emailform.is_valid(): data = emailform.cleaned_data # Set up message message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True if int(data['from_type']) == 0: message.from_name = "Robogals" elif int(data['from_type']) == 1: message.from_name = request.user.chapter.name else: message.from_name = request.user.get_full_name() message.scheduled = False # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() # Start processing recipient list # Insert choices for attending, not attending etc here if request.POST['invitee_type'] == '1': # All # Using `ConferenceAttendee` users = ConferenceAttendee.objects.filter(conference=conf.id) # Using `User` # id_list = ConferenceAttendee.objects.filter(conference=conf.id).values_list('user_id') # users = User.objects.filter(id__in = id_list, is_active=True, email_reminder_optin=True).order_by('last_name') elif request.POST['invitee_type'] == '2': # Selected users = data['memberselect'] for one_user in users: recipient = EmailRecipient() recipient.message = message recipient.to_address = one_user.email # Using `ConferenceAttendee` recipient.user = one_user.user recipient.to_name = one_user.full_name() # Using `User` # recipient.user = one_user # recipient.to_name = one_user.get_full_name() recipient.save() # Send message message.status = 0 message.save() request.user.message_set.create(message=unicode(_("Email sent successfully"))) return HttpResponseRedirect('/conferences/' + str(conf.pk) + '/') else: emailform = EmailAttendeesForm(None, conference=conf, user=request.user) # Display email form return render_to_response('conf_rsvp_email.html', {'conf': conf, 'emailform': emailform}, context_instance=RequestContext(request))
def writeemail(request): memberstatustypes = MemberStatusType.objects.all() if not request.user.is_staff: raise Http404 if request.method == 'POST': typesel = request.POST['type'] schedsel = request.POST['scheduling'] statussel = request.POST['status'] if 'step' in request.POST: if request.POST['step'] == '1': emailform = WriteEmailForm(request.POST, user=request.user) request.session['emailform'] = emailform elif request.POST['step'] == '2': if 'emailform' not in request.session: raise Http404 emailform = request.session['emailform'] del request.session['emailform'] else: raise Http404 else: raise Http404 if emailform.is_valid(): data = emailform.cleaned_data if request.POST['step'] == '2': message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True if request.POST['scheduling'] == '1': message.scheduled = True message.scheduled_date = datetime.combine(data['schedule_date'], data['schedule_time']) try: message.scheduled_date_type = int(data['schedule_zone']) except Exception: message.scheduled_date_type = 1 else: message.scheduled = False if request.POST['type'] == '4': n = data['newsletters'] message.from_name = n.from_name message.from_address = n.from_email message.reply_address = n.from_email message.sender = n.from_user else: message.content_subtype = "html" if int(data['from_type']) == 0: message.from_name = "Robogals" elif int(data['from_type']) == 1: message.from_name = request.user.chapter.name else: message.from_name = request.user.get_full_name() # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() if request.POST['type'] == '1': if request.user.is_superuser: # "Email all members worldwide" feature disabled Nov 2010 - too much potential for abuse. # Can be re-enabled by uncommenting the following line, commenting the exception, # and removing the disabled tag from the relevant radio button in email_write.html #users = User.objects.filter(chapter__in=data['chapters'], is_active=True, email_chapter_optin=True) raise Exception else: users = User.objects.filter(chapter=request.user.chapter, is_active=True, email_chapter_optin=True).exclude(email='') elif request.POST['type'] == '2': if request.user.is_superuser: users = User.objects.filter(chapter__in=data['chapters_exec'], is_active=True, is_staff=True).exclude(email='') else: users = User.objects.filter(chapter=request.user.chapter, is_active=True, is_staff=True).exclude(email='') elif request.POST['type'] == '5': ul = data['list'] users = ul.users.all().exclude(email='') elif request.POST['type'] == '4': if request.user.is_superuser: # Special rule for The Amplifier if data['newsletters'].pk == 1: users = User.objects.filter(is_active=True, email_newsletter_optin=True).exclude(email='') else: users = User.objects.none() else: users = data['recipients'] usersfiltered = [] if statussel != '0' and request.POST['type'] != '4': for one_user in users: if one_user.membertype().pk == int(statussel): if request.POST['step'] == '1': usersfiltered.append(one_user) else: if str(one_user.pk) in request.POST.keys(): recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() else: for one_user in users: if request.POST['step'] == '1': usersfiltered.append(one_user) else: if str(one_user.pk) in request.POST.keys(): recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() subscribers = [] if request.POST['type'] == '4' and request.user.is_superuser: for one_subscriber in NewsletterSubscriber.objects.filter(newsletter=data['newsletters'], active=True): if request.POST['step'] == '1': subscribers.append(one_subscriber) else: if ('sub' + str(one_subscriber.pk)) in request.POST.keys(): recipient = EmailRecipient() recipient.message = message recipient.user = None recipient.to_name = one_subscriber.first_name + " " + one_subscriber.last_name recipient.to_address = one_subscriber.email recipient.save() if request.POST['step'] == '2': # Now mark it as OK to send. The email and all recipients are now in MySQL. # A background script on the server will process the queue. message.status = 0 message.save() if request.POST['step'] == '1': return render_to_response('email_users_confirm.html', {'usersfiltered': usersfiltered, 'subscribers': subscribers, 'type': request.POST['type'], 'scheduling': request.POST['scheduling'], 'status': request.POST['status']}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/messages/email/done/') else: if request.user.is_superuser: typesel = '2' else: typesel = '1' schedsel = '0' statussel = '1' emailform = WriteEmailForm(None, user=request.user) return render_to_response('email_write.html', {'memberstatustypes': memberstatustypes, 'emailform': emailform, 'chapter': request.user.chapter, 'typesel': typesel, 'schedsel': schedsel, 'statussel': statussel}, context_instance=RequestContext(request))
def emailvisitattendees(request, visit_id): if not request.user.is_staff: raise Http404 chapter = request.user.chapter v = get_object_or_404(SchoolVisit, pk=visit_id) if (v.chapter != chapter) and not request.user.is_superuser: raise Http404 if request.method == 'POST': emailform = EmailAttendeesForm(request.POST, user=request.user, visit=v) if emailform.is_valid(): data = emailform.cleaned_data message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True message.from_name = chapter.name message.scheduled = False # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() # Start processing recipient list # Send to all invitees if request.POST['invitee_type'] == '1': id_list = EventAttendee.objects.filter(event=v.id).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to invitees who have RSVP'd as attending elif request.POST['invitee_type'] == '2': id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=2).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to invitees who have RSVP'd as not attending elif request.POST['invitee_type'] == '3': id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=4).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to invitees who have yet to RSVP elif request.POST['invitee_type'] == '4': id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=1).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to specifically selected users elif request.POST['invitee_type'] == '5': users = data['memberselect'] for one_user in users: recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() message.status = 0 message.save() messages.success(request, message=unicode(_("Email sent succesfully"))) return HttpResponseRedirect('/teaching/' + str(v.pk) + '/') else: emailform = EmailAttendeesForm(None, user=request.user, visit=v) return render_to_response('visit_email.html', {'emailform': emailform, 'visit_id': visit_id}, context_instance=RequestContext(request))
def writeemail(request): memberstatustypes = MemberStatusType.objects.all() if not request.user.is_staff: raise Http404 if request.method == 'POST': typesel = request.POST['type'] schedsel = request.POST['scheduling'] statussel = request.POST['status'] if 'step' in request.POST: if request.POST['step'] == '1': emailform = WriteEmailForm(request.POST, user=request.user) request.session['emailid'] = datetime.utcnow().strftime('%y%m%d%H%M%S') request.session['emailform'] = emailform elif request.POST['step'] == '2': if ('emailform' not in request.session) or ('emailid' not in request.session): if 'emailform' in request.session: del request.session['emailform'] if 'emailid' in request.session: del request.session['emailid'] raise Http404 if request.session['emailid'] != request.POST['emailid']: raise Http404 warning = False msg = '' maxfilesize = 10 maxfilesetting = MessagesSettings.objects.filter(key='maxuploadfilesize') if maxfilesetting: maxfilesize = int(maxfilesetting[0].value) for f in request.FILES.getlist('upload_files'): if (f.name.__len__() > 70): msg += '<br>File name: "' + f.name + '" is longer than 70 characters' warning = True if (f.size > maxfilesize * 1024*1024): msg += '<br>File: "' + f.name + '" is larger than ' + str(maxfilesize) + ' MB' warning = True if warning: del request.session['emailform'] del request.session['emailid'] request.user.message_set.create(message=unicode(_('- Can not upload files. Reason(s): %s' % msg))) return HttpResponseRedirect('/messages/email/write/') emailform = request.session['emailform'] del request.session['emailform'] del request.session['emailid'] else: raise Http404 else: raise Http404 if emailform.is_valid(): data = emailform.cleaned_data if request.POST['step'] == '2': message = EmailMessage() message.subject = data['subject'] if data['header_list']: hl = data['header_list'] message.body = hl.upper_body + data['body'] + hl.lower_body else: message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True if request.POST['scheduling'] == '1': message.scheduled = True message.scheduled_date = datetime.combine(data['schedule_date'], data['schedule_time']) try: message.scheduled_date_type = int(data['schedule_zone']) except Exception: message.scheduled_date_type = 1 else: message.scheduled = False if request.POST['type'] == '4': n = data['newsletters'] message.from_name = n.from_name message.from_address = n.from_email message.reply_address = n.from_email message.sender = n.from_user else: message.content_subtype = "html" if int(data['from_type']) == 0: message.from_name = "Robogals" elif int(data['from_type']) == 1: message.from_name = request.user.chapter.name else: message.from_name = request.user.get_full_name() # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() if request.POST['type'] == '1': if request.user.is_superuser: # "Email all members worldwide" feature disabled Nov 2010 - too much potential for abuse. # Can be re-enabled by uncommenting the following line, commenting the exception, # and removing the disabled tag from the relevant radio button in email_write.html #users = User.objects.filter(chapter__in=data['chapters'], is_active=True, email_chapter_optin=True) raise Exception else: users = User.objects.filter(chapter=request.user.chapter, is_active=True, email_chapter_optin=True).exclude(email='') elif request.POST['type'] == '2': if request.user.is_superuser: users = User.objects.filter(chapter__in=data['chapters_exec'], is_active=True, is_staff=True).exclude(email='') else: users = User.objects.filter(chapter=request.user.chapter, is_active=True, is_staff=True).exclude(email='') elif request.POST['type'] == '5': ul = data['list'] users = ul.users.all().exclude(email='') elif request.POST['type'] == '4': if request.user.is_superuser: # Special rule for The Amplifier if data['newsletters'].pk == 1: users = User.objects.filter(is_active=True, email_newsletter_optin=True).exclude(email='') elif data['newsletters'].pk == 5: users = User.objects.filter(is_active=True, email_careers_newsletter_AU_optin=True).exclude(email='') else: users = User.objects.none() else: users = data['recipients'] usersfiltered = [] if statussel != '0' and request.POST['type'] != '4': for one_user in users: if one_user.membertype().pk == int(statussel): if request.POST['step'] == '1': usersfiltered.append(one_user) else: if str(one_user.pk) in request.POST.keys(): recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() else: for one_user in users: if request.POST['step'] == '1': usersfiltered.append(one_user) else: if str(one_user.pk) in request.POST.keys(): recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() subscribers = [] if request.POST['type'] == '4' and request.user.is_superuser: for one_subscriber in NewsletterSubscriber.objects.filter(newsletter=data['newsletters'], active=True): if request.POST['step'] == '1': subscribers.append(one_subscriber) else: if ('sub' + str(one_subscriber.pk)) in request.POST.keys(): recipient = EmailRecipient() recipient.message = message recipient.user = None recipient.to_name = one_subscriber.first_name + " " + one_subscriber.last_name recipient.to_address = one_subscriber.email recipient.save() if request.POST['step'] == '2': for f in request.FILES.getlist('upload_files'): ef = EmailFile(emailfile=f) ef.save() message.upload_files.add(ef) # Now mark it as OK to send. The email and all recipients are now in MySQL. # A background script on the server will process the queue. message.status = 0 message.save() if request.POST['step'] == '1': return render_to_response('email_users_confirm.html', {'usersfiltered': usersfiltered, 'subscribers': subscribers, 'type': request.POST['type'], 'scheduling': request.POST['scheduling'], 'status': request.POST['status'], 'emailid': request.session['emailid']}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/messages/email/done/') else: if request.user.is_superuser: typesel = '2' else: typesel = '1' schedsel = '0' statussel = '1' emailform = WriteEmailForm(None, user=request.user) return render_to_response('email_write.html', {'memberstatustypes': memberstatustypes, 'emailform': emailform, 'chapter': request.user.chapter, 'typesel': typesel, 'schedsel': schedsel, 'statussel': statussel}, context_instance=RequestContext(request))
def rsvpemail(request, conf_id): # Superuser check if not request.user.is_superuser: raise Http404 conf = get_object_or_404(Conference, pk=conf_id) chapter = request.user.chapter # Determine if form has been POSTed back if request.method == 'POST': # Validate email form data emailform = EmailAttendeesForm(request.POST, conference=conf, user=request.user) if emailform.is_valid(): data = emailform.cleaned_data # Set up message message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True if int(data['from_type']) == 0: message.from_name = "Robogals" elif int(data['from_type']) == 1: message.from_name = request.user.chapter.name else: message.from_name = request.user.get_full_name() message.scheduled = False # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() # Start processing recipient list # Insert choices for attending, not attending etc here if request.POST['invitee_type'] == '1': # All # Using `ConferenceAttendee` users = ConferenceAttendee.objects.filter(conference=conf.id) # Using `User` # id_list = ConferenceAttendee.objects.filter(conference=conf.id).values_list('user_id') # users = User.objects.filter(id__in = id_list, is_active=True, email_reminder_optin=True).order_by('last_name') elif request.POST['invitee_type'] == '2': # Selected users = data['memberselect'] for one_user in users: recipient = EmailRecipient() recipient.message = message recipient.to_address = one_user.email # Using `ConferenceAttendee` recipient.user = one_user.user recipient.to_name = one_user.full_name() # Using `User` # recipient.user = one_user # recipient.to_name = one_user.get_full_name() recipient.save() # Send message message.status = 0 message.save() messages.success(request, message=unicode(_("Email sent successfully"))) return HttpResponseRedirect('/conferences/' + str(conf.pk) + '/') else: emailform = EmailAttendeesForm(None, conference=conf, user=request.user) # Display email form return render_to_response('conf_rsvp_email.html', { 'conf': conf, 'emailform': emailform }, context_instance=RequestContext(request))
def emailvisitattendees(request, visit_id): if not request.user.is_staff: raise Http404 chapter = request.user.chapter v = get_object_or_404(SchoolVisit, pk=visit_id) if (v.chapter != chapter) and not request.user.is_superuser: raise Http404 if request.method == 'POST': emailform = EmailAttendeesForm(request.POST, user=request.user, visit=v) if emailform.is_valid(): data = emailform.cleaned_data message = EmailMessage() message.subject = data['subject'] message.body = data['body'] message.from_address = request.user.email message.reply_address = request.user.email message.sender = request.user message.html = True message.from_name = chapter.name message.scheduled = False # Don't send it yet until the recipient list is done message.status = -1 # Save to database so we get a value for the primary key, # which we need for entering the recipient entries message.save() # Start processing recipient list # Send to all invitees if request.POST['invitee_type'] == '1': id_list = EventAttendee.objects.filter( event=v.id).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to invitees who have RSVP'd as attending elif request.POST['invitee_type'] == '2': id_list = EventAttendee.objects.filter( event=v.id, rsvp_status=2).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to invitees who have RSVP'd as not attending elif request.POST['invitee_type'] == '3': id_list = EventAttendee.objects.filter( event=v.id, rsvp_status=4).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to invitees who have yet to RSVP elif request.POST['invitee_type'] == '4': id_list = EventAttendee.objects.filter( event=v.id, rsvp_status=1).values_list('user_id') users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True) # Send to specifically selected users elif request.POST['invitee_type'] == '5': users = data['memberselect'] for one_user in users: recipient = EmailRecipient() recipient.message = message recipient.user = one_user recipient.to_name = one_user.get_full_name() recipient.to_address = one_user.email recipient.save() message.status = 0 message.save() messages.success(request, message=unicode(_("Email sent succesfully"))) return HttpResponseRedirect('/teaching/' + str(v.pk) + '/') else: emailform = EmailAttendeesForm(None, user=request.user, visit=v) return render_to_response('visit_email.html', { 'emailform': emailform, 'visit_id': visit_id }, context_instance=RequestContext(request))