Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        if not self.secret_hash:
            self.secret_hash = random_hash(length=16)

        if not self.slug:
            self.slug = generate_unique_slug(User, self.full_name, separator="")

        self.updated_at = datetime.utcnow()
        return super().save(*args, **kwargs)
Exemplo n.º 2
0
def edit_account(request, user_slug):
    if user_slug == "me":
        return redirect("edit_account", request.me.slug, permanent=False)

    user = get_object_or_404(User, slug=user_slug)
    if user.id != request.me.id and not request.me.is_moderator:
        raise Http404()

    if request.method == "POST" and request.POST.get("regenerate"):
        user.secret_hash = random_hash(length=16)
        user.save()
        return redirect("edit_account", user.slug, permanent=False)

    return render(request, "users/edit/account.html", {"user": user})