def reset_password(request): '''Reset a user's password.''' if request.method == 'POST': username = request.POST.get('username') new_password = HuxleyUser.reset_password(username) if new_password: if True: user.email_user("Huxley Password Reset", "Your password has been reset to %s.\nThank you for using Huxley!" % (new_password), from_email="*****@*****.**") return render_template(request, 'password-reset-success.html') else: return render_template(request, 'password-reset.html', {'error': True}) return render_template(request, 'password-reset.html')
def welcome(request): """ Display and/or edit the advisor's profile information. """ school = request.user.school if request.method == 'GET': return render_template(request, 'welcome.html', {'school': school}) elif request.method == 'POST': # TODO (wchieng): refactor this into a Django form. request.user.first_name = request.POST.get('firstname') request.user.last_name = request.POST.get('lastname') request.user.save(); school.name = request.POST.get('schoolname') school.address = request.POST.get('address') school.city = request.POST.get('city') school.zip_code = request.POST.get('zip_code') school.program_type = request.POST.get('program_type') school.times_attended = request.POST.get('attendance') school.primary_name = request.POST.get('primary_name') school.primary_email = request.POST.get('primary_email') school.primary_phone = request.POST.get('primary_phone') school.secondary_name = request.POST.get('secname') school.secondary_email = request.POST.get('secemail') school.secondary_phone = request.POST.get('secphone') school.min_delegation_size = request.POST.get('minDel') school.max_delegation_size = request.POST.get('maxDel') school.save(); return HttpResponse()
def help(request): """ Display a FAQ view. """ questions = { category.name: HelpQuestion.objects.filter(category=category) for category in HelpCategory.objects.all() } return render_template(request, 'help.html', {'categories': questions})
def index(request): user_dict = {}; if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data context = {'user_json': json.dumps(user_dict)} return render_template(request, 'www.html', context)
def reset_password(request): '''Reset a user's password.''' if request.method == 'POST': username = request.POST.get('username') new_password = HuxleyUser.reset_password(username) if new_password: if True: user.email_user( "Huxley Password Reset", "Your password has been reset to %s.\nThank you for using Huxley!" % (new_password), from_email="*****@*****.**") return render_template(request, 'password-reset-success.html') else: return render_template(request, 'password-reset.html', {'error': True}) return render_template(request, 'password-reset.html')
def press_release(request): """ Display the Press Release page for chairs. """ com = request.user.committee if request.method == 'POST': delegate_slots = simplejson.loads(request.POST['delegate_slots']) for slot_data in delegate_slots: delegate = Delegate.objects.get(delegate_slot=DelegateSlot.objects.get(id=slot_data['id'])) delegate.release = slot_data['textfield'] delegate.save() return HttpResponse() delegate_slots = DelegateSlot.objects.filter(assignment__committee=com).order_by('assignment__country__name') return render_template(request, 'pressrelease.html', {'delegate_slots': delegate_slots})
def roster(request): """ Display the advisor's editable roster, or update information as necessary. """ school = request.user.school if request.method == 'POST': slot_data = json.loads(request.POST['delegates']) school.update_delegate_slots(slot_data) return HttpResponse() slots = school.get_delegate_slots() return render_template(request, 'roster_edit.html', {'slots' : slots})
def attendance(request): """ Display a page allowing the chair to take attendance. """ committee = request.user.committee if request.method == 'POST': delegate_slots = simplejson.loads(request.POST['delegate_slots']) for slot_data in delegate_slots: slot = DelegateSlot.objects.get(id=slot_data['id']) slot.update_delegate_attendance(slot_data) return HttpResponse() delegate_slots = DelegateSlot.objects.filter(assignment__committee=committee).order_by('assignment__country__name') return render_template(request, 'take_attendance.html', {'delegate_slots': delegate_slots})
def index(request): user_dict = {}; if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render_template(request, 'www.html', context)
def login_user(request): '''Log in a user or render the login template.''' if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user, error = HuxleyUser.authenticate(username, password) if error: return render_json({'success': False, 'error': error}) redirect = HuxleyUser.login(request, user) return render_json({'success': True, 'redirect': redirect}) return render_template(request, 'login.html')
def register(request): '''Register a new user and school.''' if not Conference.objects.get(session=62).open_reg: return render_template(request, 'registration-closed.html') if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): new_school = form.create_school() new_user = form.create_user(new_school) form.add_country_preferences(new_school) form.add_committee_preferences(new_school) if new_school.waitlist: return render_template(request, 'registration-waitlist.html') if not settings.DEBUG: new_user.email_user( "Thanks for registering for BMUN 62!", "We're looking forward to seeing %s at BMUN 62. " "You can find information on deadlines and fees at " "http://bmun.org/bmun/timeline/. If you have any " "more questions, please feel free to email me at " "[email protected]. See you soon!\n\nBest,\n\nShrey Goel" "\nUSG of External Relations, BMUN 62" % new_school.name, "*****@*****.**") Conference.auto_country_assign(new_school) return render_template(request, 'registration-success.html') form = RegistrationForm() context = { 'form': form, 'state': '', 'countries': Country.objects.filter(special=False).order_by('name'), 'committees': Committee.objects.filter(special=True), 'waitlist': Conference.objects.get(session=62).waitlist_reg } return render_template(request, 'registration.html', context)
def register(request): '''Register a new user and school.''' if not Conference.objects.get(session=62).open_reg: return render_template(request, 'registration-closed.html') if request.method =='POST': form = RegistrationForm(request.POST) if form.is_valid(): new_school = form.create_school() new_user = form.create_user(new_school) form.add_country_preferences(new_school) form.add_committee_preferences(new_school) if new_school.waitlist: return render_template(request, 'registration-waitlist.html') if not settings.DEBUG: new_user.email_user("Thanks for registering for BMUN 62!", "We're looking forward to seeing %s at BMUN 62. " "You can find information on deadlines and fees at " "http://bmun.org/bmun/timeline/. If you have any " "more questions, please feel free to email me at " "[email protected]. See you soon!\n\nBest,\n\nShrey Goel" "\nUSG of External Relations, BMUN 62" % new_school.name, "*****@*****.**") Conference.auto_country_assign(new_school) return render_template(request, 'registration-success.html') form = RegistrationForm() context = { 'form': form, 'state': '', 'countries': Country.objects.filter(special=False).order_by('name'), 'committees': Committee.objects.filter(special=True), 'waitlist': Conference.objects.get(session=62).waitlist_reg } return render_template(request, 'registration.html', context)
def process_request(self, request): app_name = resolve(request.path_info).app_name if not app_name in ('advisors', 'chairs'): return if not request.user.is_authenticated(): return render_template(request, 'login.html') if app_name == 'advisors' and not request.user.is_advisor(): return HttpResponseForbidden() if app_name == 'chairs' and not request.user.is_chair(): return HttpResponseForbidden()
def login_user(request): '''Log in a user or render the login template.''' if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') try: user = HuxleyUser.authenticate(username, password) except AuthenticationError as e: return render_json({'success': False, 'error': str(e)}) redirect = HuxleyUser.login(request, user) return render_json({'success': True, 'redirect': redirect}) return render_template(request, 'login.html')
def attendance(request): """ Display a page allowing the chair to take attendance. """ committee = request.user.committee if request.method == 'POST': delegate_slots = json.loads(request.POST['delegate_slots']) for slot_data in delegate_slots: slot = DelegateSlot.objects.get(id=slot_data['id']) slot.update_delegate_attendance(slot_data) return HttpResponse() delegate_slots = DelegateSlot.objects.filter( assignment__committee=committee).order_by('assignment__country__name') return render_template(request, 'take_attendance.html', {'delegate_slots': delegate_slots})
def summaries(request): """ Display the summaries page for chairs. """ com = request.user.committee if request.method == 'POST': delegate_slots = json.loads(request.POST['delegate_slots']) for slot_data in delegate_slots: delegate = Delegate.objects.get( delegate_slot=DelegateSlot.objects.get(id=slot_data['id'])) delegate.summary = slot_data['textfield'] delegate.save() return HttpResponse() delegate_slots = DelegateSlot.objects.filter( assignment__committee=com).order_by('assignment__country__name') return render_template(request, 'summaries.html', {'delegate_slots': delegate_slots})
def index(request): if request.user.is_superuser: return redirect(reverse('admin:index')) user_dict = {}; if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render_template(request, 'www.html', context)
def index(request): if request.user.is_superuser: return redirect(reverse('admin:index')) user_dict = {}; if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'conference_session': Conference.objects.all().aggregate(Max('session'))['session__max'], 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render_template(request, 'www.html', context)
def preferences(request): """ Display and/or update the advisor's country and committee preferences. """ return render_to_response('coming-soon.html') school = request.user.school if request.method == 'POST': country_ids = request.POST.getlist('CountryPrefs') committee_ids = request.POST.getlist('CommitteePrefs') school.update_country_preferences(country_ids) school.update_committee_preferences(committee_ids) return HttpResponse() context = { 'countries': Country.objects.filter(special=False).order_by('name'), 'countryprefs': CountryPreference.shuffle(school.get_country_preferences()), 'committees': pairwise(Committee.objects.filter(special=True)), 'committeeprefs': school.committeepreferences.all() } return render_template(request, 'preferences.html', context)
def index(request): if request.user.is_superuser: return redirect(reverse('admin:index')) user_dict = {}; if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data conference = Conference.get_current() conference_dict = { 'session': conference.session, 'start_date': { 'month': conference.start_date.strftime('%B'), 'day': conference.start_date.strftime('%d'), 'year': conference.start_date.strftime('%Y') }, 'end_date': { 'month': conference.end_date.strftime('%B'), 'day': conference.end_date.strftime('%d'), 'year': conference.end_date.strftime('%Y') }, 'external': conference.external, 'registration_fee': int(conference.registration_fee), 'delegate_fee': int(conference.delegate_fee), 'registration_open': conference.open_reg, 'registration_waitlist': conference.waitlist_reg, } context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'conference_json': json.dumps(conference_dict), 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render_template(request, 'www.html', context)
def index(request): if request.user.is_superuser: return redirect(reverse('admin:index')) user_dict = {} if request.user.is_authenticated(): user_dict = UserSerializer(request.user).data conference = Conference.get_current() conference_dict = { 'session': conference.session, 'start_date': { 'month': conference.start_date.strftime('%B'), 'day': conference.start_date.strftime('%d'), 'year': conference.start_date.strftime('%Y') }, 'end_date': { 'month': conference.end_date.strftime('%B'), 'day': conference.end_date.strftime('%d'), 'year': conference.end_date.strftime('%Y') }, 'external': conference.external, 'registration_fee': int(conference.registration_fee), 'delegate_fee': int(conference.delegate_fee), 'registration_open': conference.open_reg, 'registration_waitlist': conference.waitlist_reg, } context = { 'user_json': json.dumps(user_dict).replace('</', '<\\/'), 'conference_json': json.dumps(conference_dict), 'gender_constants': ContactGender.to_json(), 'contact_types': ContactType.to_json(), 'program_types': ProgramTypes.to_json(), } return render_template(request, 'www.html', context)
def bugs(request): """ Display a bug reporting view. """ return render_template(request, 'bugs.html')
def help(request): """ Display a FAQ view. """ questions = {category.name: HelpQuestion.objects.filter(category=category) for category in HelpCategory.objects.all()} return render_template(request, 'help.html', {'categories': questions})
def attendance(request): """ Display the advisor's attendance list. """ context = {'delegate_slots': request.user.school.get_delegate_slots()} return render_template(request, 'check-attendance.html', context)
def summaries_advisors(request): context = {'delegate_slots': request.user.school.get_delegate_slots()} return render_template(request, 'summaries_advisors.html', context)