From e0e95e2db1546811f1fafa69e07a8db2c6cf86c7 Mon Sep 17 00:00:00 2001 From: Ivan Kovalkovskyi Date: Thu, 15 Oct 2015 13:03:31 +0300 Subject: [PATCH] Article bug fixes --- article/admin.py | 9 +++++---- article/forms.py | 2 ++ templates/client/article/news_list.html | 2 +- templates/client/includes/article_theme.html | 4 ++-- theme/urls.py | 1 + theme/views.py | 16 +++++++++++++++- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/article/admin.py b/article/admin.py index 15cc4268..131ff9c4 100644 --- a/article/admin.py +++ b/article/admin.py @@ -171,7 +171,10 @@ class BlogView(FormView): article = self.obj data = {} data['slug'] = article.slug - data['theme'] = [item.id for item in article.blog_theme.all()] + if self.obj.type == Article.blog: + data['theme'] = [item.id for item in article.blog_theme.all()] + else: + data['theme'] = [item.id for item in article.theme.all()] if article.exposition: data['exposition'] = article.exposition.id if article.conference: @@ -200,13 +203,10 @@ class BlogView(FormView): else: return form_class() - - def get_context_data(self, **kwargs): context = super(BlogView, self).get_context_data(**kwargs) self.set_obj() - context['article'] = self.obj if context['article']: context['file_form'] = FileForm(initial={'model': 'article.Article'}) @@ -229,6 +229,7 @@ class NewsList(ListView): context['news_flag'] = True return context + class NewsView(BlogView): form_class = NewsForm template_name = 'article/blog_form.html' diff --git a/article/forms.py b/article/forms.py index 787b31ee..dee1d954 100644 --- a/article/forms.py +++ b/article/forms.py @@ -108,8 +108,10 @@ class NewsForm(BlogForm): article = super(NewsForm, self).save(author, article) exposition = self.cleaned_data.get('exposition') conference = self.cleaned_data.get('conference') + theme = self.cleaned_data.get('theme') article.exposition = exposition article.conference = conference + article.theme = theme article.save() return article diff --git a/templates/client/article/news_list.html b/templates/client/article/news_list.html index 9e671309..c35d5838 100644 --- a/templates/client/article/news_list.html +++ b/templates/client/article/news_list.html @@ -48,7 +48,7 @@ }, tags:{ placeholder:"{% trans 'Выберите ключевые теги' %}", - url:'http://{{ request.get_host }}/theme/get-tag/' + url:'http://{{ request.get_host }}/theme/get-news-tag/' } }); diff --git a/templates/client/includes/article_theme.html b/templates/client/includes/article_theme.html index b31570bd..039ee796 100644 --- a/templates/client/includes/article_theme.html +++ b/templates/client/includes/article_theme.html @@ -1,6 +1,6 @@ -{% with theme=obj.theme.all %} - {% for theme in obj.theme.all %} +{% with theme=obj.blog_theme.all %} + {% for theme in obj.blog_theme.all %} {{ theme.name }}{% if forloop.counter != themes|length %},{% endif %} {% endfor %} {% endwith %} \ No newline at end of file diff --git a/theme/urls.py b/theme/urls.py index 88a81794..276cfe2a 100644 --- a/theme/urls.py +++ b/theme/urls.py @@ -4,4 +4,5 @@ from django.conf.urls import patterns, url urlpatterns = patterns('', url(r'^get-tag/$', 'theme.views.get_tag'), url(r'^get-article-tags/$', 'theme.views.get_article_tags'), + url(r'^get-news-tag/$', 'theme.views.get_news_tags'), ) \ No newline at end of file diff --git a/theme/views.py b/theme/views.py index ce83a38a..29efa6bf 100644 --- a/theme/views.py +++ b/theme/views.py @@ -7,7 +7,7 @@ def get_tag(request): #if request.is_ajax(): themes = request.GET.getlist('themes[]') term = request.GET['term'].capitalize() - qs = Tag.objects.language().exclude(theme__article__id=None).distinct() + qs = Tag.objects.language().distinct() if term: qs = qs.filter(translations__name__contains=term) if themes: @@ -28,4 +28,18 @@ def get_article_tags(request): result = [{'id': tag.id, 'label': '%s (%s)'%(tag.name, tag.theme.name)} for tag in qs] result = sorted(result, key=lambda x:x['label']) + return HttpResponse(json.dumps(result), content_type='application/json') + + +def get_news_tags(request): + themes = request.GET.getlist('themes[]') + term = request.GET['term'].capitalize() + qs = Tag.objects.language().exclude(article=None).filter(article__type=2).distinct() + if term: + qs = qs.filter(translations__name__contains=term) + if themes: + qs = qs.filter(theme__id__in=themes).order_by('translations__name') + result = [{'id': tag.id, 'label': '%s (%s)'%(tag.name, tag.theme.name)} for tag in qs] + result = sorted(result, key=lambda x:x['label']) + return HttpResponse(json.dumps(result), content_type='application/json') \ No newline at end of file