def set_country_school_assignments(request, conference): if request.method == "POST": form = jEditableForm(data=request.POST) if form.is_valid(): country_pk = request.POST.get("id", "") country = get_object_or_404(Country, pk=country_pk) if country.conference == conference: country_positions = DelegatePosition.objects.filter(country=country) school_pk = form.cleaned_data["value"] if school_pk == "-1": set_country_school_assignment(country_positions, None) return HttpResponse(" ") else: school = get_object_or_404(School, pk=school_pk) if is_school_registered(conference, school): set_country_school_assignment(country_positions, school) return HttpResponse(school.name)
def set_country_school_assignments(request, conference): if request.method == 'POST': form = jEditableForm(data=request.POST) if form.is_valid(): country_pk = request.POST.get('id', '') country = get_object_or_404(Country, pk=country_pk) if country.conference == conference: country_positions = DelegatePosition.objects.filter(country=country) school_pk = form.cleaned_data['value'] if school_pk == "-1": set_country_school_assignment(country_positions, None) return HttpResponse(" ") else: school = get_object_or_404(School, pk=school_pk) if is_school_registered(conference, school): set_country_school_assignment(country_positions, school) return HttpResponse(school.name)
def set_individual_delegate_positions(request, conference): if request.method == 'POST': form = jEditableForm(data=request.POST) if form.is_valid(): position_id = request.POST.get('id', '') classes = request.POST.get('row_class', '') value = form.cleaned_data['value'] position = get_object_or_404(DelegatePosition, pk=position_id) if position.country.conference == conference: if "title" in classes and len(value) > 0: position.title = value position.save() return HttpResponse(position.title) elif "country" in classes: country = get_object_or_404(Country, pk=value) if country.conference == conference: position.country = country position.save() return HttpResponse(country.name) elif "committee" in classes: committee = get_object_or_404(Committee, pk=value) if committee.conference == conference: position.committee = committee position.save() return HttpResponse(committee.name) elif "school" in classes: if value == "-1": position.school = None position.save() return HttpResponse("") else: school = get_object_or_404(School, pk=value) if is_school_registered(conference, school): position.school = school position.save() return HttpResponse(school.name)
def set_individual_delegate_positions(request, conference): if request.method == "POST": form = jEditableForm(data=request.POST) if form.is_valid(): position_id = request.POST.get("id", "") classes = request.POST.get("row_class", "") value = form.cleaned_data["value"] position = get_object_or_404(DelegatePosition, pk=position_id) if position.country.conference == conference: if "title" in classes and len(value) > 0: position.title = value position.save() return HttpResponse(position.title) elif "country" in classes: country = get_object_or_404(Country, pk=value) if country.conference == conference: position.country = country position.save() return HttpResponse(country.name) elif "committee" in classes: committee = get_object_or_404(Committee, pk=value) if committee.conference == conference: position.committee = committee position.save() return HttpResponse(committee.name) elif "school" in classes: if value == "-1": position.school = None position.save() return HttpResponse("") else: school = get_object_or_404(School, pk=value) if is_school_registered(conference, school): position.school = school position.save() return HttpResponse(school.name)
def set_country_preferences(request, school, conference): if request.method == 'POST': try: delegation_request = DelegationRequest.objects.get(school=school,conference=conference) except ObjectDoesNotExist: delegation_request = DelegationRequest() delegation_request.conference = conference delegation_request.school = school delegation_request.save() # remove current preferences CountryPreference.objects.filter(request=delegation_request).delete() DelegateCountPreference.objects.filter(request=delegation_request).delete() country_names = [] count = 0 country_index = 0 now = datetime.now().strftime("%Y-%m-%d %H:%M:") # MySQL does not support microseconds, so we have to manually order the countries by seconds for pref_num, country_pk in request.POST.items(): if pref_num == 'total_count': try: count = int(country_pk) count_pref = DelegateCountPreference() count_pref.request = delegation_request count_pref.delegate_count = count count_pref.save() except TypeError: pass else: try: country = Country.objects.get(pk=country_pk) except Country.DoesNotExist: pass else: if is_school_registered(country.conference, school): # make sure this preference doesnt already exist if country.name not in country_names: pref = CountryPreference() pref.country = country pref.request = delegation_request pref.last_modified = now + str(country_index) pref.save() country_index = country_index + 1 country_names.append(country.name) if len(country_names) > 0: # send notification email sender = conference.email_address to = conference.email_address subject = "Country Preferences Submission: " + school.name # Body of the message (a plain-text and an HTML version). text = "Country preferences submitted for " + school.name + "\n" for i in range(len(country_names)): text += str(i+1) + ": " + country_names[i] + "\n" # Not sending HTML version for now, turning this off # html = """\ # <html> # <head></head> # <body> # <p>Country preferences submitted for <b> # """ # html += school.name + "</b>:<ol>" # for name in country_names: # html += "<li>" + name + "</li>" # # html += "</ol>Total delegates requested: " + str(count) + "</p></body></html>" send_mail( subject=subject, message=text, from_email=sender, recipient_list=[to], ) return simplejson.dumps({'prefs':get_country_preferences_html(school,conference)})
def set_country_preferences(request, school, conference): if request.method == 'POST': try: delegation_request = DelegationRequest.objects.get( school=school, conference=conference) except ObjectDoesNotExist: delegation_request = DelegationRequest() delegation_request.conference = conference delegation_request.school = school delegation_request.save() # remove current preferences CountryPreference.objects.filter(request=delegation_request).delete() DelegateCountPreference.objects.filter( request=delegation_request).delete() country_names = [] count = 0 country_index = 0 now = datetime.now().strftime( "%Y-%m-%d %H:%M:" ) # MySQL does not support microseconds, so we have to manually order the countries by seconds for pref_num, country_pk in request.POST.items(): if pref_num == 'total_count': try: count = int(country_pk) count_pref = DelegateCountPreference() count_pref.request = delegation_request count_pref.delegate_count = count count_pref.save() except TypeError: pass else: try: country = Country.objects.get(pk=country_pk) except Country.DoesNotExist: pass else: if is_school_registered(country.conference, school): # make sure this preference doesnt already exist if country.name not in country_names: pref = CountryPreference() pref.country = country pref.request = delegation_request pref.last_modified = now + str(country_index) pref.save() country_index = country_index + 1 country_names.append(country.name) if len(country_names) > 0: # send notification email sender = conference.email_address to = conference.email_address # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "Country Preferences Submission: " + school.name msg['From'] = sender msg['To'] = to # Body of the message (a plain-text and an HTML version). text = "Country preferences submitted for " + school.name + "\n" for i in range(len(country_names)): text += str(i + 1) + ": " + country_names[i] + "\n" html = """\ <html> <head></head> <body> <p>Country preferences submitted for <b> """ html += school.name + "</b>:<ol>" for name in country_names: html += "<li>" + name + "</li>" html += "</ol>Total delegates requested: " + str( count) + "</p></body></html>" # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and preferred. msg.attach(part1) msg.attach(part2) # Send the message via local SMTP server. s = smtplib.SMTP('localhost') s.sendmail(sender, to, msg.as_string()) s.quit() return simplejson.dumps( {'prefs': get_country_preferences_html(school, conference)})
def set_country_preferences(request, school, conference): if request.method == 'POST': try: delegation_request = DelegationRequest.objects.get(school=school,conference=conference) except ObjectDoesNotExist: delegation_request = DelegationRequest() delegation_request.conference = conference delegation_request.school = school delegation_request.save() # remove current preferences CountryPreference.objects.filter(request=delegation_request).delete() DelegateCountPreference.objects.filter(request=delegation_request).delete() country_names = [] count = 0 country_index = 0 now = datetime.now().strftime("%Y-%m-%d %H:%M:") # MySQL does not support microseconds, so we have to manually order the countries by seconds for pref_num, country_pk in request.POST.items(): if pref_num == 'total_count': try: count = int(country_pk) count_pref = DelegateCountPreference() count_pref.request = delegation_request count_pref.delegate_count = count count_pref.save() except TypeError: pass else: try: country = Country.objects.get(pk=country_pk) except Country.DoesNotExist: pass else: if is_school_registered(country.conference, school): # make sure this preference doesnt already exist if country.name not in country_names: pref = CountryPreference() pref.country = country pref.request = delegation_request pref.last_modified = now + str(country_index) pref.save() country_index = country_index + 1 country_names.append(country.name) if len(country_names) > 0: # send notification email sender = conference.email_address to = conference.email_address # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "Country Preferences Submission: " + school.name msg['From'] = sender msg['To'] = to # Body of the message (a plain-text and an HTML version). text = "Country preferences submitted for " + school.name + "\n" for i in range(len(country_names)): text += str(i+1) + ": " + country_names[i] + "\n" html = """\ <html> <head></head> <body> <p>Country preferences submitted for <b> """ html += school.name + "</b>:<ol>" for name in country_names: html += "<li>" + name + "</li>" html += "</ol>Total delegates requested: " + str(count) + "</p></body></html>" # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and preferred. msg.attach(part1) msg.attach(part2) # Send the message via local SMTP server. s = smtplib.SMTP('localhost') s.sendmail(sender, to, msg.as_string()) s.quit() return simplejson.dumps({'prefs':get_country_preferences_html(school,conference)})