# HG changeset patch # User Brian Neal # Date 1332290840 18000 # Node ID 0e51e5be34b99ef9605b0931d0e6b50b695f6fa9 # Parent 358c7640ab60450bd1dbd3ca7854c0e330b115cf For issue #4, create an articles application and import old data. diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/articles/admin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/articles/admin.py Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,21 @@ +""" +Automatic admin definitions for the articles application. + +""" +from django.contrib import admin +from django.conf import settings + +from articles.models import Article + + +class ArticleAdmin(admin.ModelAdmin): + save_on_top = True + list_filter = ['date'] + list_display = ['title', 'date'] + search_fields = ['text', 'title'] + + class Media: + js = settings.THIRD_PARTY_JS['tiny_mce'] + + +admin.site.register(Article, ArticleAdmin) diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/articles/management/commands/import_old_articles.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/articles/management/commands/import_old_articles.py Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,59 @@ +""" +import_old_articles.py - For importing articles from the older version of this +website. + +""" +import datetime + +from django.conf import settings +from django.core.management.base import LabelCommand +from django.utils import simplejson as json +from django.utils.html import linebreaks +import textile + +from articles.models import Article + + +class Command(LabelCommand): + args = '' + help = 'Imports older articles in JSON format' + + def handle_label(self, filename, **options): + """ + Process the file of older articles in JSON. Convert to the new model + scheme. + + """ + with open(filename, 'rb') as f: + items = json.load(f) + + for item in items: + if item['model'] == 'band.article': + self.process_item(item) + + def process_item(self, item): + + fields = item['fields'] + + content = fields['text'].strip() + if fields['markup_enabled']: + text = textile.textile(content, encoding='utf-8', output='utf-8') + else: + text = linebreaks(fields['text']) + + source = linebreaks(fields['source'].strip()) + + pdf = fields['pdf'].strip() + if pdf: + pdf = u"%s%s" % (settings.MEDIA_URL, pdf.replace('\\', '/')) + + article = Article( + id=item['pk'], + title=fields['title'].strip(), + date=datetime.datetime.strptime(fields['date'], '%Y-%m-%d'), + text=text, + source=source, + url=fields['url'].strip(), + pdf=pdf) + + article.save() diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/articles/models.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/articles/models.py Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,28 @@ +""" +Models for the articles application. + +""" +from django.db import models + + +class Article(models.Model): + title = models.CharField(max_length=64) + date = models.DateTimeField(db_index=True) + text = models.TextField() + source = models.TextField(help_text="Enter the source/author for the " + "article, copyright info, etc; it will appear under the article.") + url = models.URLField(blank=True, verify_exists=False, + help_text = 'Link to original article; optional') + pdf = models.FileField(upload_to = 'pdf/articles/%Y/%m/%d/', blank=True, + help_text="If you want to make the original article available as " + "a PDF download, you may upload it here.") + + def __unicode__(self): + return self.title + + class Meta: + ordering = ['-date'] + + @models.permalink + def get_absolute_url(self): + return ('articles-item', [], {'pk': str(self.id)}) diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/articles/urls.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/articles/urls.py Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,21 @@ +""" +Urls for the articles application. + +""" +from django.conf.urls.defaults import patterns, url +from django.views.generic import DetailView, ListView + +from articles.models import Article + + +urlpatterns = patterns('', + url(r'^$', + ListView.as_view( + model=Article, + paginate_by=10, + context_object_name='article_list'), + name='articles-index'), + url(r'^(?P\d+)/$', + DetailView.as_view(model=Article, context_object_name='article'), + name='articles-item') +) diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/articles/views.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/articles/views.py Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,1 @@ +# Create your views here. diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/band/urls.py --- a/madeira/band/urls.py Thu Mar 15 20:04:42 2012 -0500 +++ b/madeira/band/urls.py Tue Mar 20 19:47:20 2012 -0500 @@ -15,8 +15,8 @@ (r'^news_old/$', 'news'), (r'^photos/$', 'photos_index'), (r'^photos/(\d+)$', 'photo_detail'), - (r'^press/$', 'press_index'), - (r'^press/(\d+)$', 'press_detail'), + (r'^press_old/$', 'press_index'), + (r'^press_old/(\d+)$', 'press_detail'), (r'^songs/$', 'songs'), (r'^videos/$', 'videos_index'), (r'^videos/(\d+)$', 'video_detail'), diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/settings/base.py --- a/madeira/settings/base.py Thu Mar 15 20:04:42 2012 -0500 +++ b/madeira/settings/base.py Tue Mar 20 19:47:20 2012 -0500 @@ -105,6 +105,7 @@ 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.staticfiles', + 'articles', 'band', 'gigs', 'news', diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/templates/articles/article_detail.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/templates/articles/article_detail.html Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,19 @@ +{% extends 'band/base.html' %} +{% block title %}The Madeira | Press | {{ article.title }}{% endblock %} +{% block content %} +

{{ article.title }}

+
{{ article.text|safe }}
+
{{ article.source|safe }}
+{% if article.url %} +Original article +{% endif %} +{% if article.pdf and article.url %} +| +{% endif %} +{% if article.pdf %} +Original article as PDF + + Adobe Reader +{% endif %} +{% endblock %} diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/templates/articles/article_list.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/templates/articles/article_list.html Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,29 @@ +{% extends 'band/base.html' %} +{% block title %}The Madeira | Press{% endblock %} +{% block content %} +

Madeira Press, Articles, & Reviews

+{% if article_list %} + {% for article in article_list %} +

{{ article.title }}

+
{{ article.text|safe }}
+
{{ article.source|safe }}
+ {% if article.url %} + Original article + {% endif %} + {% if article.pdf and article.url %} + | + {% endif %} + {% if article.pdf %} + Original article as PDF + + Adobe Reader + {% endif %} + {% endfor %} + + {% include 'pagination.html' %} + +{% else %} +

No articles at this time.

+{% endif %} +{% endblock %} diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/templates/news/news_list.html --- a/madeira/templates/news/news_list.html Thu Mar 15 20:04:42 2012 -0500 +++ b/madeira/templates/news/news_list.html Tue Mar 20 19:47:20 2012 -0500 @@ -11,23 +11,11 @@ {% endif %}
{{ story.content|safe }}
{% endfor %} + + {% include 'pagination.html' %} + {% else %}

No news at this time.

{% endif %} - {% endblock %} diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/templates/pagination.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/madeira/templates/pagination.html Tue Mar 20 19:47:20 2012 -0500 @@ -0,0 +1,15 @@ + diff -r 358c7640ab60 -r 0e51e5be34b9 madeira/urls.py --- a/madeira/urls.py Thu Mar 15 20:04:42 2012 -0500 +++ b/madeira/urls.py Tue Mar 20 19:47:20 2012 -0500 @@ -9,6 +9,7 @@ (r'^', include('band.urls')), (r'^gigs/', include('gigs.urls')), (r'^news/', include('news.urls')), + (r'^press/', include('articles.urls')), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/', include(admin.site.urls)), (r'^photologue/', include('photologue.urls')), diff -r 358c7640ab60 -r 0e51e5be34b9 static/css/theme.css --- a/static/css/theme.css Thu Mar 15 20:04:42 2012 -0500 +++ b/static/css/theme.css Tue Mar 20 19:47:20 2012 -0500 @@ -40,6 +40,7 @@ h2 { font: italic 20px verdana, tahoma, arial, sans-serif; padding-top: 5px; + margin-top: 1.5em; color: #6B969C; border-top: solid 1px #6B969C; }