def form_valid(self, form): obj = form.save(commit=False) if not hasattr(obj, 'user'): obj.user = self.request.user info(self.request, "Тема создана") else: info(self.request, "Тема отредактирована") # filter for html content by Bleach obj.content = html_validator(obj.content) obj.save() # saving keywords keywords = Keyword.objects assigned_keywords = list() request_keywords = list(set(unicode(self.request.POST.get( 'keywords_1', False)).replace(' ', '').split(','))) if len(request_keywords) >= 1: for keyword in request_keywords: keyword = keywords.filter(title=keyword) if len(keyword) >= 1: assigned_keywords.append( AssignedKeyword(keyword_id=keyword[0].id)) obj.keywords = assigned_keywords # dirty solution to save category try: obj.categories = self.request.POST.getlist('categories', False) except: pass obj.save() return HttpResponseRedirect( reverse('topic_detail', kwargs={'slug': obj.slug}))
def form_valid(self, form): obj = form.save(commit=False) obj.featured_image = self.request.POST.get( 'featured_image', False).replace('/static/media/', '').strip() if not hasattr(obj, 'user'): obj.user = self.request.user # filter for html content by Bleach obj.content = html_validator(obj.content) obj.save() # dirty solution to save keywords keywords = Keyword.objects assigned_keywords = list() request_keywords = list(set(unicode(self.request.POST.get( 'keywords_1', False)).replace(' ', '').split(','))) if len(request_keywords) >= 1: for keyword in request_keywords: keyword = keywords.filter(title=keyword) if len(keyword) >= 1: assigned_keywords.append( AssignedKeyword(keyword_id=keyword[0].id)) obj.keywords = assigned_keywords # dirty solution to save category try: obj.categories = self.request.POST.getlist('categories', False) except: pass obj.save() if obj.status == 1: info(self.request, "Черновик сохранен") return HttpResponseRedirect( reverse( 'blog_list_user', kwargs={'username': self.request.user} ) ) elif obj.status == 2: info(self.request, "Запись сохранена") return HttpResponseRedirect( reverse('blog_post_detail', kwargs={'slug': obj.slug}))