def school_admin(request, conference_slug, school_slug): conference = get_object_or_404(Conference, url_name=conference_slug) school = get_object_or_404(School, url_name=school_slug) feestructure = conference.feestructure sponsors = FacultySponsor.objects.filter( school=school, conferences__id__exact=conference.id) other_sponsors = FacultySponsor.objects.filter(school=school).exclude( conferences__id__exact=conference.id).exclude(user=request.user) fees_table = get_fees_table_from_data(school, \ conference, \ feestructure, \ school.get_filled_delegate_positions_count(conference), \ school.get_delegations_count(conference), \ school.get_sponsors_count(conference), \ school.total_payments(conference)) country_preferences = get_country_preferences_html(school, conference) delegations = school.get_delegations(conference) return render_response( request, 'school/index.html', { 'conference': conference, 'school': school, 'fees_table': fees_table, 'country_preferences': country_preferences, 'sponsors': sponsors, 'other_sponsors': other_sponsors, 'delegations': delegations })
def create_conference(request): if request.method == 'POST' and staff_authenticate(request): conference_form = ConferenceForm(request.POST) user_form = SecretariatUserForm(request.POST) if conference_form.is_valid() and user_form.is_valid(): new_conference = conference_form.save(commit=False) new_conference.url_name = slugify( conference_form.cleaned_data['name']) new_conference.no_refunds_start_date = new_conference.start_date new_conference.save() # create default countries defaultCountriesList = MEDIA_ROOT + "default_countries.csv" countriesListReader = UnicodeCSVReader(open(defaultCountriesList)) for row in countriesListReader: new_country = Country() new_country.conference = new_conference new_country.name = row[0].strip() new_country.url_name = slugify(new_country.name) new_country.country_code = row[1].strip() new_country.save() # create default committees and delegate positions defaultCommitteesList = MEDIA_ROOT + "default_committees.csv" committeesListReader = UnicodeCSVReader( open(defaultCommitteesList)) for row in committeesListReader: new_committee = Committee() new_committee.conference = new_conference new_committee.name = row[0].strip() new_committee.url_name = slugify(new_committee.name) new_committee.save() # default fee structure (free conference) feeStructure = FeeStructure() feeStructure.conference = new_conference feeStructure.save() user = user_form.save(commit=False) user.email = new_conference.email_address user.save() secretariat_user = Secretariat() secretariat_user.user = user secretariat_user.save() secretariat_user.conferences.add(new_conference) return HttpResponseRedirect('/' + new_conference.url_name + '/secretariat/') else: conference_form = ConferenceForm() user_form = SecretariatUserForm() return render_response(request, 'conference/create-conference.html', { 'conference_form': conference_form, 'secretariat_form': user_form })
def create_conference(request): if request.method == 'POST' and staff_authenticate(request): conference_form = ConferenceForm(request.POST) user_form = SecretariatUserForm(request.POST) if conference_form.is_valid() and user_form.is_valid(): new_conference = conference_form.save(commit=False) new_conference.url_name = slugify(conference_form.cleaned_data['name']) new_conference.no_refunds_start_date = new_conference.start_date new_conference.save() # create default countries defaultCountriesList = MEDIA_ROOT + "default_countries.csv" countriesListReader = UnicodeCSVReader(open(defaultCountriesList)) for row in countriesListReader: new_country = Country() new_country.conference = new_conference new_country.name = row[0].strip() new_country.url_name = slugify(new_country.name) new_country.country_code = row[1].strip() new_country.save() # create default committees and delegate positions defaultCommitteesList = MEDIA_ROOT + "default_committees.csv" committeesListReader = UnicodeCSVReader(open(defaultCommitteesList)) for row in committeesListReader: new_committee = Committee() new_committee.conference = new_conference new_committee.name = row[0].strip() new_committee.url_name = slugify(new_committee.name) new_committee.save() # default fee structure (free conference) feeStructure = FeeStructure() feeStructure.conference = new_conference feeStructure.save() user = user_form.save(commit=False) user.email = new_conference.email_address user.save() secretariat_user = Secretariat() secretariat_user.user = user secretariat_user.save() secretariat_user.conferences.add(new_conference) return HttpResponseRedirect('/' + new_conference.url_name + '/secretariat/') else: conference_form = ConferenceForm() user_form = SecretariatUserForm() return render_response(request, 'conference/create-conference.html', { 'conference_form': conference_form, 'secretariat_form' : user_form })
def grant_school_access(request, conference_slug, school_slug): school = get_object_or_404(School, url_name=school_slug) if request.method == 'POST': access_code = request.POST.get("access_code", "") redirect_to = request.POST.get("next", '') if access_code == school.access_code: # grant access to this school sponsor = FacultySponsor() sponsor.user = request.user sponsor.school = school sponsor.save() if not redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to): redirect_to = settings.LOGIN_REDIRECT_URL return HttpResponseRedirect(redirect_to) return render_response(request, "school/wrong-access-code.html", {'school' : school})
def school_admin(request, conference_slug, school_slug): conference = get_object_or_404(Conference, url_name=conference_slug) school = get_object_or_404(School, url_name=school_slug) feestructure = conference.feestructure sponsors = FacultySponsor.objects.filter(school=school, conferences__id__exact=conference.id) other_sponsors = FacultySponsor.objects.filter(school=school).exclude(conferences__id__exact=conference.id).exclude(user=request.user) fees_table = get_fees_table_from_data(school, \ conference, \ feestructure, \ school.get_filled_delegate_positions_count(conference), \ school.get_delegations_count(conference), \ school.get_sponsors_count(conference), \ school.total_payments(conference)) country_preferences = get_country_preferences_html(school, conference) delegations = school.get_delegations(conference) return render_response(request, 'school/index.html', {'conference' : conference, 'school' : school, 'fees_table' : fees_table, 'country_preferences' : country_preferences, 'sponsors' : sponsors, 'other_sponsors':other_sponsors, 'delegations':delegations})
def register_school(request, conference_slug): conference = get_object_or_404(Conference, url_name=conference_slug) if request.method == 'POST': school_form = NewSchoolForm(request.POST) sponsor_form = NewFacultySponsorForm(request.POST) captcha_response = get_recaptcha_response(request) if school_form.is_valid(): if request.user.is_authenticated() or sponsor_form.is_valid(): if captcha_response.is_valid or not settings.ENABLE_CAPTCHA: new_school = School() new_school.name = school_form.cleaned_data['school_name'] new_school.url_name = slugify( school_form.cleaned_data['school_name']) new_school.address_line_1 = school_form.cleaned_data[ 'school_address_line_1'] new_school.address_line_2 = school_form.cleaned_data[ 'school_address_line_2'] new_school.city = school_form.cleaned_data['school_city'] new_school.state = school_form.cleaned_data['school_state'] new_school.zip = school_form.cleaned_data['school_zip'] new_school.address_country = school_form.cleaned_data[ 'school_address_country'] new_school.access_code = User.objects.make_random_password( ) new_school.save() new_school.conferences.add(conference) new_sponsor = FacultySponsor() new_sponsor.school = new_school if hasattr(sponsor_form, 'cleaned_data'): new_sponsor.phone = sponsor_form.cleaned_data[ 'sponsor_phone'] new_user = request.user if not request.user.is_authenticated(): new_user = User() new_user.username = sponsor_form.cleaned_data[ 'sponsor_username'] new_user.first_name = sponsor_form.cleaned_data[ 'sponsor_first_name'] new_user.last_name = sponsor_form.cleaned_data[ 'sponsor_last_name'] new_user.email = sponsor_form.cleaned_data[ 'sponsor_email'] new_user.set_password( sponsor_form.cleaned_data['sponsor_password']) new_user.save() else: try: # delete any existing faculty sponsor ties existing_sponsor = FacultySponsor.objects.get( user=new_user) new_sponsor.phone = existing_sponsor.phone existing_sponsor.delete() except ObjectDoesNotExist: pass new_sponsor.user = new_user new_sponsor.save() new_sponsor.conferences.add(conference) return HttpResponseRedirect( reverse(school_admin, args=( conference.url_name, new_school.url_name, ))) else: school_form._errors.setdefault( "school_name", ErrorList()).append( "The reCAPTCHA wasn't entered correctly.") else: try: school = request.user.faculty_sponsor.school try: school.conferences.get(id=conference.id) except Conference.DoesNotExist: school.conferences.add(conference) try: request.user.faculty_sponsor.conferences.get(id=conference.id) except Conference.DoesNotExist: request.user.faculty_sponsor.conferences.add(conference) return HttpResponseRedirect( reverse(school_admin, args=( conference.url_name, school.url_name, ))) except: school_form = NewSchoolForm() sponsor_form = NewFacultySponsorForm() return render_response( request, 'register-new-school.html', { 'school_form': school_form, 'sponsor_form': sponsor_form, 'conference': conference })
def school_index(request, slug): school = get_object_or_404(School, url_name=slug) return render_response(request, 'school_detail.html', {'school': school})
def register_school(request, conference_slug): conference = get_object_or_404(Conference, url_name=conference_slug) if request.method == 'POST': school_form = NewSchoolForm(request.POST) sponsor_form = NewFacultySponsorForm(request.POST) captcha_response = get_recaptcha_response(request) if school_form.is_valid(): if request.user.is_authenticated() or sponsor_form.is_valid(): if captcha_response.is_valid or not settings.ENABLE_CAPTCHA: new_school = School() new_school.name = school_form.cleaned_data['school_name'] new_school.url_name = slugify(school_form.cleaned_data['school_name']) new_school.address_line_1 = school_form.cleaned_data['school_address_line_1'] new_school.address_line_2 = school_form.cleaned_data['school_address_line_2'] new_school.city = school_form.cleaned_data['school_city'] new_school.state = school_form.cleaned_data['school_state'] new_school.zip = school_form.cleaned_data['school_zip'] new_school.address_country = school_form.cleaned_data['school_address_country'] new_school.access_code = User.objects.make_random_password() new_school.save() new_school.conferences.add(conference) new_sponsor = FacultySponsor() new_sponsor.school = new_school if hasattr(sponsor_form, 'cleaned_data'): new_sponsor.phone = sponsor_form.cleaned_data['sponsor_phone'] new_user = request.user if not request.user.is_authenticated(): new_user = User() new_user.username = sponsor_form.cleaned_data['sponsor_username'] new_user.first_name = sponsor_form.cleaned_data['sponsor_first_name'] new_user.last_name = sponsor_form.cleaned_data['sponsor_last_name'] new_user.email = sponsor_form.cleaned_data['sponsor_email'] new_user.set_password(sponsor_form.cleaned_data['sponsor_password']) new_user.save() else: try: # delete any existing faculty sponsor ties existing_sponsor = FacultySponsor.objects.get(user=new_user) new_sponsor.phone = existing_sponsor.phone existing_sponsor.delete() except ObjectDoesNotExist: pass new_sponsor.user = new_user new_sponsor.save() new_sponsor.conferences.add(conference) return HttpResponseRedirect(reverse(school_admin, args=(conference.url_name, new_school.url_name,))) else: school_form._errors.setdefault("school_name", ErrorList()).append("The reCAPTCHA wasn't entered correctly.") else: try: school = request.user.faculty_sponsor.school try: school.conferences.get(id=conference.id) except Conference.DoesNotExist: school.conferences.add(conference) try: request.user.faculty_sponsor.conferences.get(id=conference.id) except Conference.DoesNotExist: request.user.faculty_sponsor.conferences.add(conference) return HttpResponseRedirect(reverse(school_admin, args=(conference.url_name, school.url_name,))) except: school_form = NewSchoolForm() sponsor_form = NewFacultySponsorForm() return render_response(request, 'register-new-school.html', { 'school_form': school_form, 'sponsor_form': sponsor_form, 'conference' : conference })
def school_index(request, slug): school = get_object_or_404(School, url_name=slug) return render_response(request, 'school_detail.html', {'school' : school})