예제 #1
0
파일: tests.py 프로젝트: opinnmr/stjornbord
    def testSuggestionInUse(self):
        fname = u"Guðfríður"
        lname = u"Ýr Kvaran"
        suggestions1 = set(suggest_usernames(fname, lname))
        username = suggestions1.pop()

        ReserverdUsername.objects.create(username=username)

        suggestions2 = set(suggest_usernames(fname, lname))

        self.assertEqual(suggestions1, suggestions2)
예제 #2
0
파일: tests.py 프로젝트: opinnmr/stjornbord
    def testSuggestionsTwoNames(self):
        suggestions = suggest_usernames(u"Þorgerður", u"Ægisdóttir")

        # Remove expected suggestions
        suggestions.remove("thorgerdur%s" % self.YEAR)
        suggestions.remove("thorgerdura%s" % self.YEAR)
        suggestions.remove("aegisdottir%s" % self.YEAR)
        suggestions.remove("thorgerduraegisdottir%s" % self.YEAR)
        suggestions.remove("ta%s" % self.YEAR)

        # Verify that there are no unexpected suggestions
        self.assertEqual(suggestions, [])
예제 #3
0
파일: views.py 프로젝트: opinnmr/stjornbord
def register(request):
    context = {}
    
    if request.method == 'POST':
        kennitala_form = KennitalaForm(request.POST)
        if kennitala_form.is_valid():
            student = Student.objects.get(kennitala=kennitala_form.cleaned_data['kennitala'])
            suggested_usernames = suggest_usernames(student.first_name, student.last_name)

            # See if the user actually posted some stuff, other that its
            # kennitala to get to this page
            post_keys        = request.POST.keys()
            other_post_stuff = None
            if "id_username_0" in post_keys or "password" in post_keys:
                other_post_stuff = request.POST

            password_form = PasswordForm(other_post_stuff)
            username_form = UsernameForm(other_post_stuff)
            username_form.fields['username'].choices = [(x, x) for x in suggested_usernames]

            if username_form.is_valid() and password_form.is_valid():
                username = username_form.cleaned_data['username']
                log.info("Creating user %s for student %s (kt %s)", username,
                    student, student.kennitala)

                user = User.objects.create(username=username, password="******") # pw overridde below
                userp = UserProfile(
                            user      = user,
                            kennitala = student.kennitala,
                            user_type = ContentType.objects.get_for_model(student),
                            status = UserStatus.objects.get(pk=ACTIVE_USER),
                        )

                userp.set_password(password_form.cleaned_data['password'])
                userp.set_dirty()
                userp.save()
                
                return HttpResponseRedirect("/register/done/")
                
                
            context['password_form']  = password_form.as_ul()
            context['username_form']  = username_form.as_ul()
            context['student']  = student
    else:
        kennitala_form = KennitalaForm()


    context['kennitala_form'] = kennitala_form.as_ul()

    return render_to_response(
        'registration/register.html', context,
        context_instance=RequestContext(request))
예제 #4
0
파일: tests.py 프로젝트: opinnmr/stjornbord
    def testSuggestionsThreeNames(self):
        suggestions = suggest_usernames(u"Jóhann", u"Óli Guðmundsson")

        # Remove expected suggestions
        suggestions.remove("johann%s" % self.YEAR)
        suggestions.remove("johanno%s" % self.YEAR)
        suggestions.remove("johanng%s" % self.YEAR)
        suggestions.remove("johannog%s" % self.YEAR)
        suggestions.remove("oligudmundsson%s" % self.YEAR)
        suggestions.remove("johanngudmundsson%s" % self.YEAR)
        suggestions.remove("johannogudmundsson%s" % self.YEAR)
        suggestions.remove("gudmundsson%s" % self.YEAR)
        suggestions.remove("jog%s" % self.YEAR)
        suggestions.remove("johannoli%s" % self.YEAR)

        # Verify that there are no unexpected suggestions
        self.assertEqual(suggestions, [])
예제 #5
0
파일: tests.py 프로젝트: opinnmr/stjornbord
    def testSuggestionsFourNames(self):
        suggestions = suggest_usernames(u"Martin", u"Jónas Björn Swift")

        # Remove expected suggestions
        suggestions.remove("martin%s" % self.YEAR)
        suggestions.remove("martinswift%s" % self.YEAR)
        suggestions.remove("martinjbswift%s" % self.YEAR)
        suggestions.remove("martinbjorn%s" % self.YEAR)
        suggestions.remove("martinjonas%s" % self.YEAR)
        suggestions.remove("martinjb%s" % self.YEAR)
        suggestions.remove("martinjbs%s" % self.YEAR)
        suggestions.remove("martins%s" % self.YEAR)
        suggestions.remove("jonasswift%s" % self.YEAR)
        suggestions.remove("bjornswift%s" % self.YEAR)
        suggestions.remove("swift%s" % self.YEAR)
        suggestions.remove("mjbs%s" % self.YEAR)

        # Verify that there are no unexpected suggestions
        self.assertEqual(suggestions, [])