def editable(self, user): """ 帖子在发布60秒之后才能编辑 """ if user == self.author: if time_zone_now() < self.created + datetime.timedelta(seconds=settings.FORUMS_EDIT_TIMEOUT): return True return False
def editable(self, user): """ 帖子在发布60秒之后才能编辑 """ if user == self.author: if time_zone_now() < self.created + datetime.timedelta( seconds=settings.FORUMS_EDIT_TIMEOUT): return True return False
def edit_topic(request, topic_id): topic = Topic.objects.get(id=topic_id) if request.method == 'GET': form = TopicUEditorForm(initial={'Content': topic.content, 'Name': topic.title} ) ctx = { 'topic': topic, 'form': form, } return render(request, 'deepin/topic_edit.html', ctx) if request.method == 'POST': form = TopicUEditorForm(request.POST, request.FILES) if form.is_valid(): topic.title = form.cleaned_data['Name'] topic.content = form.cleaned_data['Content'] topic.forum = topic.forum topic.updated = time_zone_now() topic.save() return HttpResponseRedirect(reverse('bb:topic_view', kwargs={'pk': topic.pk}))
def edit_topic(request, topic_id): topic = Topic.objects.get(id=topic_id) if request.method == 'GET': form = TopicUEditorForm(initial={ 'Content': topic.content, 'Name': topic.title }) ctx = { 'topic': topic, 'form': form, } return render(request, 'deepin/topic_edit.html', ctx) if request.method == 'POST': form = TopicUEditorForm(request.POST, request.FILES) if form.is_valid(): topic.title = form.cleaned_data['Name'] topic.content = form.cleaned_data['Content'] topic.forum = topic.forum topic.updated = time_zone_now() topic.save() return HttpResponseRedirect( reverse('bb:topic_view', kwargs={'pk': topic.pk}))
def save(self, *args, **kwargs): created_time = time_zone_now() if self.created is None: self.created = created_time new = self.pk is None topic_changed = False old_post = None if not new: old_post = Post.objects.get(pk=self.pk) if old_post.topic != self.topic: topic_changed = True super(Post, self).save(*args, **kwargs) if self.topic.head == self and not self.is_manage and self.topic.is_manage: self.topic.is_manage = False self.topic.update_counters() self.topic.forum.update_counters() if topic_changed: old_post.topic.update_counters() old_post.topic.forum.update_counters()
def upload_to(instance, filename): now = time_zone_now() base, ext = os.path.splitext(filename) ext = ext.lower() return f"users/{now:%Y/%m/%Y%m%d%H%M%S}{ext}"