Permalink
Browse files

Pre-alpha

  • Loading branch information...
1 parent 6712242 commit afa9fa2f26110f1419b8178ca77bb50eb53f1ec8 @ostronom ostronom committed Dec 27, 2012
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,60 @@
+var currentWidth;
+
+$(document).ready(
+ function() {
+ checkSizes();
+ $('.main_tab').on('click', function(){switchMainTabs(this)});
+
+
+ }
+);
+
+$(window).resize(
+ function(){
+ checkSizes();
+ }
+);
+
+function checkSizes() {
+ if ($(window).width() < 768) {
+ if ((currentWidth >= 768 || currentWidth === undefined) && ($('#main_gray_line').css('display') == 'none')) { /* the last condition is required to cope with weird firefox behavior */
+ $('#newspaper_block').insertAfter('#wod_block');
+ $('#navigation_block').insertBefore('#events_block');
+ $('#subjects_block').insertAfter('#navigation_block');
+ }
+ } else if ($(window).width() >= 768 && currentWidth < 768) {
+ $('#navigation_holder').append($('#navigation_block'));
+ $('#newspaper_holder').append($('#newspaper_block'));
+ $('#subjects_holder').append($('#subjects_block'));
+ }
+ currentWidth = $(window).width();
+}
+
+function switchMainTabs(which) {
+
+ $('.main_tab.active').toggleClass('active');
+
+ switch ($(which).attr('id')) {
+ case 'main_blogs_new_switch':
+ $('#main_blogs_new_switch').toggleClass('active');
+ $('#main_blogs_new').css('display', 'block');
+ $('#main_blogs_favorite').css('display', 'none');
+ $('#main_blogs_polemics').css('display', 'none');
+ break
+
+ case 'main_blogs_polemics_switch':
+ $('#main_blogs_polemics_switch').toggleClass('active');
+ $('#main_blogs_new').css('display', 'none');
+ $('#main_blogs_favorite').css('display', 'none');
+ $('#main_blogs_polemics').css('display', 'block');
+ break
+
+ case 'main_blogs_favorite_switch':
+ $('#main_blogs_favorite_switch').toggleClass('active');
+ $('#main_blogs_new').css('display', 'none');
+ $('#main_blogs_favorite').css('display', 'block');
+ $('#main_blogs_polemics').css('display', 'none');
+ break
+ }
+
+}
@@ -9,8 +9,10 @@ class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'status', 'rubric',)
search_fields = ('title',)
list_filter = ('status', 'rubric')
- filter_vertical = ('authors',)
+ filter_vertical = ('authors', 'topics')
+ def queryset(self, request):
+ return Article.everything.all()
admin.site.register(Article, ArticleAdmin)
admin.site.register(Rubric, MPTTModelAdmin)
@@ -2,7 +2,7 @@
import psycopg2
from django.core.management.base import BaseCommand
-from content.models import Rubric, Article
+from content.models import Rubric, Article, Topic
from siteuser.models import User
@@ -11,28 +11,27 @@ def dictify(desc, data):
class Command(BaseCommand):
- known_rubrics = {}
- known_authors = {}
+ rubrics = {}
+ authors = {}
+ topics = {}
top_rubrics = {}
def handle(self, *args, **kwargs):
- self.top_rubrics = {
- 'gazette': Rubric.objects.create(title=u'Газета'),
+ self.cleanup()
+ self.top_rubrics = {
+ 'gazette': Rubric.objects.create(title=u'Газета', slug='zeitung'),
'site': Rubric.objects.create(title=u'Сайт'),
'blogs': Rubric.objects.create(title=u'Блоги'),
'word_of_day': Rubric.objects.create(title=u'Слово дня', slug='wod'),
'editorial': Rubric.objects.create(title=u'Колонка редактора', slug='editorial'),
'special_project': Rubric.objects.create(title=u'Спецпроект')
}
+ Rubric.objects.create(title=u'Колонки', slug='columns', parent=self.top_rubrics['site'])
self.conn = psycopg2.connect("dbname=old_zavtra user=root")
- cursor = self.conn.cursor()
- [self.migrate_article(r) for r in self.simple_sql("""
- SELECT c.* FROM corecontent_contentitem AS c
- LEFT JOIN corecontent_rubric AS r
- ON r.id = c.rubric_id
- ORDER BY r.position
- """)]
- cursor.close()
+ self.migrate_rubrics()
+ self.migrate_authors()
+ self.migrate_topics()
+ self.migrate_articles()
self.conn.close()
def simple_sql(self, sql):
@@ -42,43 +41,86 @@ def simple_sql(self, sql):
yield dictify(cursor.description, record)
cursor.close()
- def get_rubric(self, id):
- if id in self.known_rubrics:
- return self.known_rubrics[id]
- r = list(self.simple_sql("SELECT * FROM corecontent_rubric WHERE id=%d" % id))
- published = list(self.simple_sql("SELECT COUNT(id) as cnt FROM corecontent_contentitem WHERE rubric_id=%d AND published=true" % id))[0]
- if published['cnt'] == 0:
- parent = self.top_rubrics['site']
- else:
- parent = self.top_rubrics['gazette']
- self.known_rubrics[id] = Rubric.objects.create(parent=parent, title=r[0]['title'], position=r[0]['position'])
- return self.known_rubrics[id]
+ def cleanup(self):
+ Rubric.objects.all().delete()
+ User.objects.all().delete()
+ Article.objects.all().delete()
+ Topic.objects.all().delete()
+
+ def migrate_rubrics(self):
+ for r in self.simple_sql("""
+ SELECT r.*, COUNT(c.id) as is_gazette
+ FROM corecontent_rubric AS r
+ LEFT JOIN corecontent_contentitem AS c
+ ON (c.rubric_id = r.id AND c.published = true)
+ GROUP BY r.id
+ ORDER BY r.position
+ """):
+ if r['is_gazette'] > 0:
+ parent = self.top_rubrics['gazette']
+ elif r['title'] in [u'90-е', u'Врезка']:
+ parent = self.top_rubrics['special_project']
+ else:
+ parent = self.top_rubrics['site']
+ self.rubrics[r['id']] = Rubric.objects.create(
+ title=r['title'],
+ position=r['position'],
+ slug=r['slug'],
+ parent=parent
+ )
+
+ def migrate_authors(self):
+ for r in self.simple_sql("SELECT * FROM auth_user WHERE is_staff=true"):
+ if r['email'] is None or len(r['email']) == 0:
+ email = 'fakeuseremail_%d@zavtra.ru' % r['id']
+ else:
+ email = r['email']
+ self.authors[r['id']] = User.objects.create(
+ email=email,
+ first_name=r['first_name'],
+ last_name=r['last_name'],
+ level=User.USER_LEVELS.staff
+ )
- def get_author(self, id):
- if id in self.known_authors:
- return self.known_authors[id]
- a = list(self.simple_sql("SELECT * FROM auth_user WHERE id=%d AND is_staff=True" % id))[0]
- email = a['email']
- if email is None or len(email) == 0:
- email = 'fakeuseremail_%d@zavtra.ru' % id
- self.known_authors[id] = User.objects.create(first_name=a['first_name'], last_name=a['last_name'], level=User.USER_LEVELS.staff, email=email)
- return self.known_authors[id]
+ def migrate_articles(self):
+ article_ctype = list(self.simple_sql("""SELECT id FROM django_content_type WHERE app_label='corecontent' AND model='article'"""))[0]['id']
+ for r in self.simple_sql("SELECT * FROM corecontent_contentitem"):
+ if r['rubric_id'] is None:
+ rubric = self.top_rubrics['blogs']
+ else:
+ rubric = self.rubrics[r['rubric_id']]
+ article = Article.objects.create(
+ title = r['title'],
+ slug = r['slug'],
+ subtitle = r['subtitle'],
+ status = Article.STATUS.ready,
+ type = r['kind'],
+ published_at = r['pub_date'],
+ rubric = rubric,
+ announce = r['description'], # clean html, extract cover
+ content = r['content'] # clean html
+ )
+ for a in self.simple_sql("SELECT user_id FROM corecontent_contentitem_authors WHERE contentitem_id=%d" % r['id']):
+ article.authors.add(self.authors[a['user_id']])
+ for t in self.simple_sql("""
+ SELECT
+ ft.featureditems_id AS id
+ FROM
+ corecontent_featureditems_tags AS ft
+ WHERE
+ ft.tag_id IN (
+ SELECT
+ tti.tag_id
+ FROM
+ taggit_taggeditem AS tti
+ WHERE
+ tti.content_type_id = %d
+ AND
+ tti.object_id = %d
+ )
+ """ % (article_ctype, r['id'])):
+ article.topics.add(self.topics[t['id']])
- def migrate_article(self, article):
- if article['rubric_id'] is None:
- rubric = self.top_rubrics['blogs']
- else:
- rubric = self.get_rubric(article['rubric_id'])
- created = Article.objects.create(
- title = article['title'],
- slug = article['slug'],
- subtitle = article['subtitle'],
- status = Article.STATUS.ready,
- type = article['kind'],
- published_at = article['pub_date'],
- rubric = rubric,
- announce = article['description'],
- content = article['content']
- )
- for a in self.simple_sql("SELECT user_id FROM corecontent_contentitem_authors WHERE contentitem_id=%d" % article['id']):
- created.authors.add(self.get_author(a['user_id']))
+ def migrate_topics(self):
+ for r in self.simple_sql("SELECT * FROM corecontent_featureditems"):
+ self.topics[r['id']] = Topic.objects.create(title=r['title'], slug=r['slug'], on_top=r['is_active'])
@@ -3,7 +3,7 @@
from django.db import models
from django.contrib.auth import get_user_model
-from zavtra.utils import cached
+from zavtra.utils import cached, oneday
class PublishedArticlesManager(models.Manager):
@@ -13,22 +13,28 @@ def get_query_set(self):
filter(status = self.model.STATUS.ready)
-class GazetteManager(PublishedArticlesManager):
+class ZeitungManager(PublishedArticlesManager):
def get_query_set(self):
from content.models import Rubric
- # TODO: cache this
- gazette = Rubric.objects.get(slug = 'gazeta').get_descendants(include_self = True)
- return super(GazetteManager, self).get_query_set().filter(rubric__in = gazette)
+ zeitung = Rubric.fetch_rubric('zeitung')
+ return super(ZeitungManager, self).get_query_set().filter(rubric__in = zeitung)
+ def issue(self, year, number):
+ npt = datetime(year=year, day=1, month=1) + 7 * oneday * (number - 1)
+ return self.get_query_set().filter(published_at__range = (npt, npt + 7 * oneday))
class ColumnsManager(PublishedArticlesManager):
def get_query_set(self):
def get_columnists():
user_model = get_user_model()
columnists = user_model.objects.filter(level__gte = user_model.USER_LEVELS.columnist)
return columnists.values('id')
+ from content.models import Rubric
columnists = cached(get_columnists, 'columnists')
- return super(ColumnsManager, self).get_query_set().filter(authors__in = columnists)
+ columns = Rubric.fetch_rubric('columns')
+ return super(ColumnsManager, self).get_query_set().\
+ filter(authors__in = columnists).\
+ filter(rubric__in = columns)
class BlogsManager(PublishedArticlesManager):
@@ -50,3 +56,10 @@ def get_query_set(self):
from content.models import Rubric
wods = Rubric.fetch_rubric('wod')
return super(WODManager, self).get_query_set().filter(rubric__in = wods)
+
+
+class EditorialManager(PublishedArticlesManager):
+ def get_query_set(self):
+ from content.models import Rubric
+ editorial = Rubric.fetch_rubric('editorial')
+ return super(EditorialManager, self).get_query_set().filter(rubric__in = editorial)
Oops, something went wrong. Retry.

0 comments on commit afa9fa2

Please sign in to comment.