Permalink
Browse files

Add list of traanslations to each arcticle

  • Loading branch information...
1 parent c706ad7 commit 595bcb3d1ef5a11de100ea675ffb64fb76680aa6 Andrey Sokolov committed Nov 28, 2011
@@ -7,6 +7,7 @@
from django.db.models.aggregates import Count
from django.db.models.fields.files import ImageField
from django.db.models.signals import post_save
+from django.db.models import Q
from taggit.managers import TaggableManager
from techblog.functions import html_parser, binary_date, formatted_date
from techblog.constants import GENDER_MALE, GENDER_FEMALE
@@ -88,6 +89,15 @@ def __unicode__(self):
def get_published(cls):
return cls.objects.filter(is_public=True)
+ def get_translations(self):
+ query = self.get_published()
+ if self.is_original():
+ query = query.filter(original=self)
+ else:
+ query = query.filter(Q(original=self.original) | Q(id=self.original.id), ~Q(id=self.id))
+ query = query.select_related('author', 'lang')
+ return query
+
def save(self, *args, **kwargs):
from techblog.services.articles import ArticleService
@@ -245,7 +245,6 @@ def publish_article(self, article, user=None):
def unpublish_article(self, article, user=None):
article.is_public = False
article.save()
- self.mail_service.send_mail_on_article_unpublish(article, user)
@staticmethod
def render_markup(markup, raw_data):
@@ -3,14 +3,14 @@
class LanguageService(object):
- @staticmethod
- def get_languages_with_count(ids=None):
- languages = Language.objects.all()
- if ids:
- languages = languages.filter(article__id__in = ids)
+ @classmethod
+ def get_languages_with_count(cls, ids=None):
+ languages = cls.get_non_empty()
+# if ids:
+# languages = languages.filter(article__id__in = ids)
languages = languages.annotate(count=Count('article__id')).filter(count__gt=0).order_by('-count')
return languages
@classmethod
def get_non_empty(cls):
- return cls.objects.all().annotate(article_count = Count('article')).filter(article_count__gt=0)
+ return Language.objects.all().annotate(article_count = Count('article')).filter(article_count__gt=0)
@@ -126,16 +126,31 @@ <h2 class="article-title">
<div class="clear"></div> <!-- IE6 fix -->
</div>
-{% comment %} <div class="item-authors">
- {% for author in article.authors.all %}
- <div class="item-author-block">
- <div class="item-author-photo">
- <a href="/users/{{ author.username }}/">{% user_avatar author 50 %}</a>
+ {% with article.get_translations as translations %}
+ {% if translations %}
+ <div class="article-translations">
+ {% for translation in translations %}
+ <div class="translation-item {% if forloop.last %}last-item{% endif %}">
+ <span class="translation-lang">{{ translation.lang.slug }}</span>
+ <span class="translation-title">
+ <a href="{% url view_article article_id=translation.id %}">
+ {{ translation.title }}
+ </a>
+ </span>
+ <span class="translation-date">{{ translation.date|date:"d M Y H:i" }}</span>
+ {% if translation.is_original %}
+ <span class="type-original">Original</span>
+ {% else %}
+ <span class="type-translation">Translation</span>
+ {% endif %}
+ <span class="translation-author">
+ <a href="/users/{{ translation.author.username }}/">{% user_avatar translation.author 16 %}</a>
+ </span>
+ </div>
+ {% endfor %}
</div>
- <a class="item-author-title" href="/users/{{ author.username }}/">{{ author.username }}</a>
- </div>
- {% endfor %}
- </div>{% endcomment %}
+ {% endif %}
+ {% endwith %}
</div>
@@ -1,58 +1,61 @@
-{% extends 'abstract/base.html' %}
-
-{% block title %} {{ object.title }} / Статьи / PROGRESSORS {% endblock %}
-
-
-{% block meta_keywords %}
- {% with object as article %}
- <meta name="title" content="{{ article.title }}"/>
- <meta name="description" content="{{ article.short|striptags|safe|truncatewords:40 }}"/>
- <meta name="author" content="{{ article.author.get_full_name }}"/>
-
-
- <meta property="og:title" content="{{ article.title }}"/>
- <meta property="og:type" content="article"/>
- <meta property="og:url" content="http://{{ request.get_host }}{{ article.get_absolute_url }}/"/>
- <meta property="og:description" content="{{ article.short|striptags|safe|truncatewords:40 }}"/>
- {% include "include/facebook_common_og_tags.html" %}
- {% endwith %}
-{% endblock %}
-
-
-{% block css %}
- <link rel="stylesheet" href="/static/techblog/css/pages/articles.css"/>
- <link rel="stylesheet" href="/static/techblog/css/comments.css"/>
- <link rel="stylesheet" href="/static/pygments/css/default.css"/>
- {# <link rel="stylesheet" href="/static/pygments/css/tango.css" />#}
- {# <link rel="stylesheet" href="/static/pygments/css/friendly.css" />#}
- {# <link rel="stylesheet" href="/static/pygments/css/colorful.css" />#}
- {# <link rel="stylesheet" href="/static/pygments/css/highlight_native.css" />#}
-
- <link rel="stylesheet" href="/static/techblog/css/big_forms.css" />
-{% endblock css %}
-
-{% block script %}
- <script type="text/javascript" src="/static/techblog/js/comments.js"></script>
- <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
- <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
- <script type="text/javascript" src="http://platform.linkedin.com/in.js"></script>
-
-{% endblock %}
-
-
-{% block content %}
- <div class="article-list">
- {% with 'description' as article_mode %}
- {% with object as article %}
- {% if article %}
- {% include 'articles/article_item.html' %}
- {% else %}
- {% if not is_public %}
- Автор переместил статью в черновик!
- {% endif %}
- {% endif %}
- {% endwith %}
- {% endwith %}
- </div>
- {% include "articles/control_panel.html" %}
-{% endblock content %}
+{% extends 'abstract/base.html' %}
+
+{% block title %} {{ object.title }} / Статьи / PROGRESSORS {% endblock %}
+
+
+{% block meta_keywords %}
+ {% with object as article %}
+ <meta name="title" content="{{ article.title }}"/>
+ <meta name="description" content="{{ article.short|striptags|safe|truncatewords:40 }}"/>
+ <meta name="author" content="{{ article.author.get_full_name }}"/>
+
+
+ <meta property="og:title" content="{{ article.title }}"/>
+ <meta property="og:type" content="article"/>
+ <meta property="og:url" content="http://{{ request.get_host }}{{ article.get_absolute_url }}/"/>
+ <meta property="og:description" content="{{ article.short|striptags|safe|truncatewords:40 }}"/>
+ {% include "include/facebook_common_og_tags.html" %}
+ {% endwith %}
+{% endblock %}
+
+
+{% block css %}
+ <link rel="stylesheet" href="/static/techblog/css/pages/articles.css"/>
+ <link rel="stylesheet" href="/static/techblog/css/comments.css"/>
+ <link rel="stylesheet" href="/static/pygments/css/default.css"/>
+ {# <link rel="stylesheet" href="/static/pygments/css/tango.css" />#}
+ {# <link rel="stylesheet" href="/static/pygments/css/friendly.css" />#}
+ {# <link rel="stylesheet" href="/static/pygments/css/colorful.css" />#}
+ {# <link rel="stylesheet" href="/static/pygments/css/highlight_native.css" />#}
+
+ <link rel="stylesheet" href="/static/techblog/css/big_forms.css" />
+{% endblock css %}
+
+{% block script %}
+ <script type="text/javascript" src="/static/techblog/js/comments.js"></script>
+ <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
+ <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
+ <script type="text/javascript" src="http://platform.linkedin.com/in.js"></script>
+
+{% endblock %}
+
+
+{% block content %}
+ <div class="articles-block">
+ <div class="article-list">
+ {% with 'description' as article_mode %}
+ {% with object as article %}
+ {% if article %}
+ {% include 'articles/article_item.html' %}
+ {% else %}
+ {% if not is_public %}
+ Автор переместил статью в черновик!
+ {% endif %}
+ {% endif %}
+ {% endwith %}
+ {% endwith %}
+ </div>
+ </div>
+
+ {% include "articles/control_panel.html" %}
+{% endblock content %}
@@ -65,11 +65,20 @@ class TranslateArticle(CreateView):
form_class = ArticleForm
def form_valid(self, form, *args, **kwargs):
- form.instance.author = self.request.user
- form.save()
- form.instance.authors.add(self.request.user)
+ form.instance.author = self.request.user
- return redirect( reverse('view_article', args=(form.instance.id,)) )
+ if 'is_public' in self.request.POST:
+ form.instance.is_public = True
+ else:
+ form.instance.is_public = False
+
+ form.save()
+ form.instance.authors.add(self.request.user)
+
+ if form.instance.is_public:
+ MailService().send_mail_on_first_article_publish(form.instance, self.request.user)
+
+ return redirect( reverse('view_article', args=(form.instance.id,)) )
def get_initial(self):
initial = super(TranslateArticle, self).get_initial().copy()
@@ -169,4 +178,6 @@ def get_redirect_url(self, **kwargs):
if article.author == self.request.user:
if action == 'publish':
self.article_service.publish_article(article, self.request.user)
+ elif action == 'unpublish':
+ self.article_service.unpublish_article(article, self.request.user)
return url
@@ -285,6 +285,55 @@
}
+/* Article translations */
+.article-translations {
+
+}
+
+.article-translations .translation-item {
+ background-color: #DDDDDD;
+ padding: 3px;
+
+}
+
+
+.article-translations .translation-item span {
+ color: #01317D;
+}
+
+
+.article-translations .last-item {
+ border-bottom-left-radius: 5px;
+ border-bottom-right-radius: 5px;
+}
+
+.article-translations .translation-lang {
+
+}
+
+.article-translations .translation-title {
+
+}
+
+
+.article-translations .translation-date {
+
+}
+
+.article-translations .type-original {
+
+}
+
+.article-translations .type-translation {
+
+}
+
+.article-translations .translation-author {
+
+}
+
+
+
/* Details */
.article-details {
padding-top: 40px;

0 comments on commit 595bcb3

Please sign in to comment.