Пример #1
0
def register(request):
    """ Registers a new user and school. """

    # Registration is closed. TODO: Implement the waitlist.
    #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 not settings.DEBUG:
                new_user.email_user("Thanks for registering for BMUN 61!",
                                    "We're looking forward to seeing %s at BMUN 61. "
                                    "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\nNishita Agarwal"
                                    "\nUSG of External Relations, BMUN 61" % new_school.name,
                                    "*****@*****.**")            
            return render_template(request, 'thanks.html')    
    
    form = RegistrationForm()
    context = {
        'form': form,
        'state': '',
        'countries': Country.objects.filter(special=False).order_by('name'),
        'committees': Committee.objects.filter(special=True)
    }

    return render_template(request, 'registration.html', context) 
Пример #2
0
def forgot_password(request):
    """ Resets a user's password. """
    if request.method == 'POST':
        form = ForgotPasswordForm(request.POST)
        if form.is_valid():
            user = form.get_user()
            new_pass = form.reset_pass(user)
            user.email_user("Huxley Password Reset",
                            "Your password has been reset to %s.\nThank you for using Huxley!" % (new_pass),
                            from_email="*****@*****.**")
            return render_template(request, 'reset_success.html')

    form = ForgotPasswordForm()
    return render_template(request, 'forgot_password.html', {'form': form})
Пример #3
0
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 not settings.DEBUG:
                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')
Пример #4
0
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()    
Пример #5
0
def roster(request):
    """ Display the advisor's editable roster, or update information as
        necessary. """
    school = request.user.school
    if request.method == 'POST':
        slot_data = simplejson.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})
Пример #6
0
def login_user(request):
    """ Logs in a user or renders 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, 'auth.html')
Пример #7
0
    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, 'auth.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()
Пример #8
0
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')

    return render_template(request,
                           'take_attendance.html',
                           {'delegate_slots': delegate_slots,
                            'committee': committee})
Пример #9
0
def preferences(request):
    """ Display and/or update the advisor's country and committee
        preferences. """
    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, shuffled=True)
        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)
Пример #10
0
def bugs(request):
    """ Display a bug reporting view. """
    return render_template(request, 'bugs.html')
Пример #11
0
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})
Пример #12
0
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)