fix get_absolute_url

This commit is contained in:
2022-07-30 21:41:32 +00:00
parent 9eb476efe0
commit 718263b740
2 changed files with 8 additions and 19 deletions

View File

@@ -82,7 +82,11 @@ class Topic(models.Model):
return self.title
def get_absolute_url(self):
return reverse("intern:topic", kwargs={"slug": self.slug})
kwargs = {
"topic_group_slug": self.topic_group.slug,
"slug": self.slug,
}
return reverse("intern:topic", kwargs=kwargs)
def clean(self, *args, **kwargs):
self.slug = slugify(self.title)
@@ -115,10 +119,10 @@ class Attachment(models.Model):
def get_absolute_url(self):
kwargs = {
"topic_group_slug": self.topic.topic_group.slug,
"topic_slug": self.topic.slug,
"slug": self.slug,
}
return reverse("intern:attachment", kwargs=kwargs)
def clean(self, *args, **kwargs):

View File

@@ -96,9 +96,9 @@ class TopicDetailView(LoginRequiredMixin, DetailView):
class TopicUpdateView(LoginRequiredMixin, UpdateView):
form_class = TopicUpdateForm
model = Topic
template_name = "intern/topic/topic_update.html"
form_class = TopicUpdateForm
def form_valid(self, form):
form.instance.created_by = self.request.user
@@ -110,18 +110,11 @@ class TopicUpdateView(LoginRequiredMixin, UpdateView):
context["topic"] = self.object
return context
def get_success_url(self):
context = {
"topic_group_slug": self.object.topic_group.slug,
"slug": self.object.slug,
}
return reverse("intern:topic", kwargs=context)
class AttachmentCreateView(LoginRequiredMixin, CreateView):
form_class = AttachmentCreateForm
model = Attachment
template_name = "intern/attachment/attachment_create.html"
form_class = AttachmentCreateForm
def form_valid(self, form):
form.instance.created_by = self.request.user
@@ -195,14 +188,6 @@ class AttachmentUpdateView(LoginRequiredMixin, UpdateView):
Q(topic__topic_group__slug=topic_group_slug) & Q(topic__slug=topic_slug)
)
def get_success_url(self):
context = {
"topic_group_slug": self.object.topic.topic_group.slug,
"topic_slug": self.object.topic.slug,
"slug": self.object.slug,
}
return reverse("intern:attachment", kwargs=context)
class EtherpadCreateView(LoginRequiredMixin, CreateView):
form_class = EtherpadForm