summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-01-27 19:04:37 +0200
committerYuval Adam <yuv.adm@gmail.com>2014-01-27 19:04:37 +0200
commit7e33509c9651b4f315bb1805762f634dc24272cd (patch)
treecb0ed56dcfd734d33d0bec2ef7470a4d06a05342
parentaed99a6272023d99e2cdea5a19a5922214c25661 (diff)
Add article lists and thumbnails
-rw-r--r--newsdiff/core/views.py22
-rw-r--r--newsdiff/settings/base.py3
-rw-r--r--newsdiff/settings/dokku.py20
-rw-r--r--newsdiff/templates/article.html6
-rw-r--r--newsdiff/templates/articles.html27
-rw-r--r--newsdiff/urls.py6
-rw-r--r--requirements.txt4
7 files changed, 77 insertions, 11 deletions
diff --git a/newsdiff/core/views.py b/newsdiff/core/views.py
index 29176d4..579f593 100644
--- a/newsdiff/core/views.py
+++ b/newsdiff/core/views.py
@@ -1,16 +1,14 @@
import reversion
-from django.views.generic import DetailView
+from django.views.generic import DetailView, ListView
from reversion.helpers import generate_patch_html
from reversion.models import Version
from .models import *
class ArticleView(DetailView):
-
context_object_name = 'article'
slug_url_kwarg = 'id'
-
template_name = 'article.html'
def get_context_data(self, **kwargs):
@@ -25,12 +23,26 @@ class ArticleView(DetailView):
class HaaretzArticleView(ArticleView):
-
model = HaaretzArticle
slug_field = 'haaretz_id'
class YnetArticleView(ArticleView):
-
model = YnetArticle
slug_field = 'ynet_id'
+
+
+class ArticleListView(ListView):
+ context_object_name = 'articles'
+ template_name = 'articles.html'
+ paginate_by = 10
+
+
+class HaaretzListView(ArticleListView):
+ model = HaaretzArticle
+ queryset = HaaretzArticle.objects.order_by('-date')
+
+
+class YnetListView(ArticleListView):
+ model = YnetArticle
+ queryset = YnetArticle.objects.order_by('-date')
diff --git a/newsdiff/settings/base.py b/newsdiff/settings/base.py
index 4e3d75d..e664a5b 100644
--- a/newsdiff/settings/base.py
+++ b/newsdiff/settings/base.py
@@ -37,7 +37,7 @@ STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
-SECRET_KEY = '65p2-o63(df#q7qq_pcj#y#l(bi#%ls)!-60lr$ric)6pb%tux'
+SECRET_KEY = 'N0_oNe_U53s_th1S_f#$^ing_k3y_:)'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
@@ -87,6 +87,7 @@ INSTALLED_APPS = (
'storages',
'celery',
'reversion',
+ 'sorl.thumbnail',
'newsdiff.core',
'newsdiff.docs',
diff --git a/newsdiff/settings/dokku.py b/newsdiff/settings/dokku.py
index 0854eb4..b8fd448 100644
--- a/newsdiff/settings/dokku.py
+++ b/newsdiff/settings/dokku.py
@@ -1,4 +1,5 @@
import dj_database_url
+import urlparse
from os import environ
from .base import *
@@ -13,7 +14,22 @@ DATABASES = {
'default': dj_database_url.config()
}
-BROKER_URL = environ.get('REDIS_URL')
+BROKER_URL = REDIS_URL = environ.get('REDIS_URL')
+redis_url = urlparse.urlparse(REDIS_URL)
+
+CACHES = {
+ 'default': {
+ 'BACKEND': 'redis_cache.RedisCache',
+ 'LOCATION': '{}:{}'.format(redis_url.hostname, redis_url.port),
+ 'OPTIONS': {
+ 'DB': 0,
+ 'PASSWORD': redis_url.password,
+ 'PARSER_CLASS': 'redis.connection.HiredisParser'
+ },
+ },
+}
+
+SECRET_KEY = environ.get('SECRET_KEY')
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = environ.get('AWS_ACCESS_KEY')
@@ -25,4 +41,4 @@ AWS_IS_GZIPPED = True
AWS_S3_SECURE_URLS = False
AWS_HEADERS = {
# 'Cache-Control': 'public, max-age=86400',
-} \ No newline at end of file
+}
diff --git a/newsdiff/templates/article.html b/newsdiff/templates/article.html
index 465f528..a54604b 100644
--- a/newsdiff/templates/article.html
+++ b/newsdiff/templates/article.html
@@ -1,3 +1,5 @@
+{% load thumbnail %}
+
<!doctype html>
<html>
<head>
@@ -7,7 +9,9 @@
<h1>{{ article.title }}</h1>
<h2>{{ article.subtitle }}</h2>
{% for image in article.images.all %}
- <a href="{{ image.image.url }}"><img src="{{ image.image.url }}" width="150"></a>
+ {% thumbnail image.image '150x120' as tim %}
+ <a href="{{ image.image.url }}"><img src="{{ tim.url }}"></a>
+ {% endthumbnail %}
{% endfor %}
<pre style="white-space: pre-wrap;">{{ article.text }}</pre>
{% for diff in diffs %}
diff --git a/newsdiff/templates/articles.html b/newsdiff/templates/articles.html
new file mode 100644
index 0000000..964b7ea
--- /dev/null
+++ b/newsdiff/templates/articles.html
@@ -0,0 +1,27 @@
+{% load thumbnail %}
+
+<!doctype html>
+<html>
+ <head>
+ <title>{{ article.title }}</title>
+ </head>
+ <body dir="rtl">
+ <h1>כתבות אחרונות</h1>
+ <ul style="list-style-type: none;">
+ {% for article in articles %}
+ <li>
+ <a href="{% url 'haaretz_article' article.haaretz_id %}">
+ {% if article.images.all %}
+ {% thumbnail article.images.all.0.image '60x60' as tim %}
+ <img src="{{ tim.url }}">
+ {% endthumbnail %}
+ {% else %}
+ <img src="http://placekitten.com/g/60/45">
+ {% endif %}
+ <span>{{ article.title }}</span>
+ </a>
+ </li>
+ {% endfor %}
+ </ul>
+ </body>
+</html>
diff --git a/newsdiff/urls.py b/newsdiff/urls.py
index 613516d..9b6071f 100644
--- a/newsdiff/urls.py
+++ b/newsdiff/urls.py
@@ -9,8 +9,10 @@ from newsdiff.core.views import *
admin.autodiscover()
urlpatterns = patterns('',
- url(r'^haaretz/(?P<id>[\d\.]+)$', HaaretzArticleView.as_view()),
- url(r'^ynet/(?P<id>[\d]+)$', YnetArticleView.as_view()),
+ url(r'^haaretz$', HaaretzListView.as_view(), name='haaretz_recent'),
+ url(r'^haaretz/(?P<id>[\d\.]+)$', HaaretzArticleView.as_view(), name='haaretz_article'),
+ url(r'^ynet$', YnetListView.as_view(), name='ynet_recent'),
+ url(r'^ynet/(?P<id>[\d]+)$', YnetArticleView.as_view(), name='ynet_article'),
url(r'^admin/', include(admin.site.urls)),
url(r'^robots.txt', lambda x: HttpResponse('User-agent: *\nDisallow: /', mimetype='text/plain'))
)
diff --git a/requirements.txt b/requirements.txt
index bcdfbe2..2ced78c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,6 @@
Django==1.6.1
PIL==1.1.7
+Pillow==2.3.0
South==0.8.4
Unipath==1.0
amqp==1.3.3
@@ -11,9 +12,11 @@ celery==3.1.6
diff-match-patch==20121119
dj-database-url==0.2.2
django-nose==1.2
+django-redis-cache==0.10.2
django-reversion==1.8.0
django-storages==1.1.8
gunicorn==18.0
+hiredis==0.1.2
honcho==0.5.0
kombu==3.0.7
lxml==3.2.4
@@ -22,4 +25,5 @@ psycopg2==2.5.1
pytz==2013.8
redis==2.8.0
requests==2.1.0
+sorl-thumbnail==11.12
wsgiref==0.1.2