From 6550fc97b2d2250217d67fd75a1624dc52f4f9e1 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 9 Jul 2011 20:12:26 +0530 Subject: [PATCH] basic things for browse page --- edgware/editor/models.py | 16 +++++++++++++--- edgware/editor/urls.py | 2 +- edgware/editor/views.py | 15 ++++++++++++++- edgware/main/views.py | 7 +++++-- edgware/templates/main/browse.html | 14 +++++++++++--- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/edgware/editor/models.py b/edgware/editor/models.py index 315a28b..452a1a5 100644 --- a/edgware/editor/models.py +++ b/edgware/editor/models.py @@ -204,11 +204,11 @@ class Article(models.Model): users = models.ManyToManyField(User, related_name='article_user', blank=True) groups = models.ManyToManyField(Group, blank=True) theme = models.ForeignKey(ArticleTheme, blank=True, null=True) - + published_date = models.DateTimeField(blank=True, null=True) class Meta: unique_together = ('product', 'order',) - ordering = ['-created'] + ordering = ['-published_date', '-created'] ''' Return boolean for whether user can edit article on tool or not - must be passed a valid User object. @@ -262,6 +262,15 @@ class Article(models.Model): qset = kls.objects.all() return qset.filter(published=True).exclude(Q(owner=user) | Q(users=user)) + @classmethod + def get_theme_list(kls, theme_id): + qset = Article.objects.filter(published=True) + try: + theme = ArticleTheme.objects.get(pk=theme_id) + qset = qset.filter(theme=theme) + except: + qset = qset + return qset @classmethod def fts(kls, search, qset=False): @@ -368,7 +377,8 @@ class Article(models.Model): 'edit_url': "/edit/article/%d/" % (self.id,), 'is_locked': self.locked, 'is_published': self.published, - 'web_url': SITE_BASE + "/edit/article_web/%d/" % (self.id,) + 'web_url': SITE_BASE + "/edit/article_web/%d/" % (self.id,), + 'iframe_url': "/edit/view_article/%d/?m=0.375" % (self.id,) } diff --git a/edgware/editor/urls.py b/edgware/editor/urls.py index a4ba4dc..6376783 100644 --- a/edgware/editor/urls.py +++ b/edgware/editor/urls.py @@ -29,7 +29,7 @@ urlpatterns = patterns('', (r'^print_article/$', views.article_pdf), (r'^article_frontend/(?P\d+)/(?P\d+)/$', views.article_frontend), (r'^article_web/(?P\d+)/', views.article_webalone), - + (r'^articlesByTheme/', views.articlesByTheme), (r'^articleTitle/$', views.articleTitle), (r'^lockArticle/$', views.lockArticle), (r'^publishArticle/$', views.publishArticle), diff --git a/edgware/editor/views.py b/edgware/editor/views.py index 705794b..e4ca798 100644 --- a/edgware/editor/views.py +++ b/edgware/editor/views.py @@ -19,7 +19,7 @@ import os from print_pdf import print_url_list import math from utils.decorators import user_passes_test_json - +import datetime @login_required def editor(request): @@ -567,6 +567,8 @@ def publishArticle(request): published = request.POST.get("published", "false") if published == "true": article.published = True + if article.published_date == None: + article.published_date = datetime.datetime.now() msg = "article published. it will now be browsable on public pages." else: article.published = False @@ -599,6 +601,17 @@ def create_article(request): others.append(a) return render_to_response("create_article.html", {'templates': templates, 'others': others}) + +def articlesByTheme(request): + user = request.user + theme_id = request.GET.get("theme_id", "0") + article_list = Article.get_theme_list(theme_id) + articles = [] + for article in article_list: + articles.append(article.get_list_dict(user)) + return HttpResponse(json.dumps(articles), mimetype="application/javascript") + + def article_frontend(request, product_id, article_order): product = Product.objects.get(pk=product_id) article = Article.objects.filter(product=product, order=article_order)[0] diff --git a/edgware/main/views.py b/edgware/main/views.py index fd89cee..ff46803 100644 --- a/edgware/main/views.py +++ b/edgware/main/views.py @@ -4,7 +4,7 @@ import Image import sys from django.http import HttpResponse from django.template import RequestContext -from editor.models import Article +from editor.models import Article, ArticleTheme from django.contrib.auth.decorators import login_required def home(request): @@ -40,7 +40,10 @@ def publish(request): return render_to_response("main/publish.html", context) def browse(request): - context = RequestContext(request, {}) + user = request.user + themes = ArticleTheme.objects.all() + first_article = Article.objects.all()[0].get_list_dict(user) + context = RequestContext(request, {'themes': themes, 'first_article': first_article}) return render_to_response("main/browse.html", context) def faq(request): diff --git a/edgware/templates/main/browse.html b/edgware/templates/main/browse.html index 60e4090..a8df83a 100644 --- a/edgware/templates/main/browse.html +++ b/edgware/templates/main/browse.html @@ -15,9 +15,11 @@ Browse Publications {% block content %}
-
Recent Publications:
+ - + + +

Issue 00:Instructions for printing July 2011


@@ -34,12 +36,18 @@ Browse Publications
Published or in-progress articles by type of Study:

- + + {% for t in themes %} + + {% endfor %} +