示例#1
0
 def test_too_long_signature_miniprofile_form(self):
     data = {
         'biography': '',
         'site': '',
         'avatar_url': '',
         'sign': stringof251chars
     }
     form = MiniProfileForm(data=data)
     self.assertFalse(form.is_valid())
示例#2
0
 def test_valid_change_miniprofile_form(self):
     data = {
         'biography': '',
         'site': '',
         'avatar_url': '',
         'sign': ''
     }
     form = MiniProfileForm(data=data)
     self.assertTrue(form.is_valid())
示例#3
0
    def test_too_long_site_url_miniprofile_form(self):

        # url is one char too long
        data = {
            'biography': '',
            'site': stringof2001chars,
            'avatar_url': '',
            'sign': ''
        }
        form = MiniProfileForm(data=data)
        self.assertFalse(form.is_valid())
示例#4
0
文件: views.py 项目: firm1/zds-member
def settings_mini_profile(request, user_name):
    """Minimal settings of users for staff."""

    # extra information about the current user
    profile = get_object_or_404(Profile, user__username=user_name)
    if request.method == "POST":
        form = MiniProfileForm(request.POST)
        data = {"form": form, "profile": profile}
        if form.is_valid():
            profile.biography = form.data["biography"]
            profile.site = form.data["site"]
            profile.avatar_url = form.data["avatar_url"]
            profile.sign = form.data["sign"]

            # Save the profile and redirect the user to the configuration space
            # with message indicate the state of the operation

            try:
                profile.save()
            except:
                messages.error(request, _(u"An error has occurred."))
                return redirect(reverse("member.views.settings_mini_profile"))

            messages.success(request, _(u"The profile has been updated."))
            return redirect(reverse("member-detail", args=[profile.user.username]))
        else:
            return render(request, "member/settings/profile.html", data)
    else:
        form = MiniProfileForm(initial={
            "biography": profile.biography,
            "site": profile.site,
            "avatar_url": profile.avatar_url,
            "sign": profile.sign,
        })
        data = {"form": form, "profile": profile}
        return render(request, "member/settings/profile.html", data)