basic things for browse page

This commit is contained in:
Sanj 2011-07-09 20:12:26 +05:30
parent 264a41ce03
commit 6550fc97b2
5 changed files with 44 additions and 10 deletions

View File

@ -204,11 +204,11 @@ class Article(models.Model):
users = models.ManyToManyField(User, related_name='article_user', blank=True) users = models.ManyToManyField(User, related_name='article_user', blank=True)
groups = models.ManyToManyField(Group, blank=True) groups = models.ManyToManyField(Group, blank=True)
theme = models.ForeignKey(ArticleTheme, blank=True, null=True) theme = models.ForeignKey(ArticleTheme, blank=True, null=True)
published_date = models.DateTimeField(blank=True, null=True)
class Meta: class Meta:
unique_together = ('product', 'order',) 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. 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() qset = kls.objects.all()
return qset.filter(published=True).exclude(Q(owner=user) | Q(users=user)) 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 @classmethod
def fts(kls, search, qset=False): def fts(kls, search, qset=False):
@ -368,7 +377,8 @@ class Article(models.Model):
'edit_url': "/edit/article/%d/" % (self.id,), 'edit_url': "/edit/article/%d/" % (self.id,),
'is_locked': self.locked, 'is_locked': self.locked,
'is_published': self.published, '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,)
} }

View File

@ -29,7 +29,7 @@ urlpatterns = patterns('',
(r'^print_article/$', views.article_pdf), (r'^print_article/$', views.article_pdf),
(r'^article_frontend/(?P<product_id>\d+)/(?P<article_order>\d+)/$', views.article_frontend), (r'^article_frontend/(?P<product_id>\d+)/(?P<article_order>\d+)/$', views.article_frontend),
(r'^article_web/(?P<article_id>\d+)/', views.article_webalone), (r'^article_web/(?P<article_id>\d+)/', views.article_webalone),
(r'^articlesByTheme/', views.articlesByTheme),
(r'^articleTitle/$', views.articleTitle), (r'^articleTitle/$', views.articleTitle),
(r'^lockArticle/$', views.lockArticle), (r'^lockArticle/$', views.lockArticle),
(r'^publishArticle/$', views.publishArticle), (r'^publishArticle/$', views.publishArticle),

View File

@ -19,7 +19,7 @@ import os
from print_pdf import print_url_list from print_pdf import print_url_list
import math import math
from utils.decorators import user_passes_test_json from utils.decorators import user_passes_test_json
import datetime
@login_required @login_required
def editor(request): def editor(request):
@ -567,6 +567,8 @@ def publishArticle(request):
published = request.POST.get("published", "false") published = request.POST.get("published", "false")
if published == "true": if published == "true":
article.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." msg = "article published. it will now be browsable on public pages."
else: else:
article.published = False article.published = False
@ -599,6 +601,17 @@ def create_article(request):
others.append(a) others.append(a)
return render_to_response("create_article.html", {'templates': templates, 'others': others}) 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): def article_frontend(request, product_id, article_order):
product = Product.objects.get(pk=product_id) product = Product.objects.get(pk=product_id)
article = Article.objects.filter(product=product, order=article_order)[0] article = Article.objects.filter(product=product, order=article_order)[0]

View File

@ -4,7 +4,7 @@ import Image
import sys import sys
from django.http import HttpResponse from django.http import HttpResponse
from django.template import RequestContext from django.template import RequestContext
from editor.models import Article from editor.models import Article, ArticleTheme
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
def home(request): def home(request):
@ -40,7 +40,10 @@ def publish(request):
return render_to_response("main/publish.html", context) return render_to_response("main/publish.html", context)
def browse(request): 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) return render_to_response("main/browse.html", context)
def faq(request): def faq(request):

View File

@ -15,9 +15,11 @@ Browse Publications
{% block content %} {% block content %}
<div id="browseWrapper"> <div id="browseWrapper">
<div id="browsePublicationsleft"> <div id="browsePublicationsleft">
<h5>Recent Publications:</h5> <!-- <h5>Recent Publications:</h5> -->
<a href=""><img src="http://camputer.org/ftp/public/Issue00.jpg"></a> <iframe src="{{ first_article.iframe_url }}" width="310" height="400" id="iframePreview"></iframe>
<!-- <img src="http://camputer.org/ftp/public/Issue00.jpg"></a> -->
<p> <p>
Issue 00:<em>Instructions for printing</em> July 2011 Issue 00:<em>Instructions for printing</em> July 2011
</p><br/> </p><br/>
@ -34,12 +36,18 @@ Browse Publications
<div id="browseArticlesright"> <div id="browseArticlesright">
<h5>Published or in-progress articles by type of Study:</h5> <h5>Published or in-progress articles by type of Study:</h5>
<p> <p>
<select name="articleThemes"> <select name="articleThemes" id="articleThemes">
<option value="0">All Themes</option>
{% for t in themes %}
<option value="{{ t.id }}">{{ t.name }}</option>
{% endfor %}
<!--
<option value="Milk">Things That Could be Done</option> <option value="Milk">Things That Could be Done</option>
<option value="Cheese">Things that Have Happened</option> <option value="Cheese">Things that Have Happened</option>
<option value="Bread">Theories of the Possible</option> <option value="Bread">Theories of the Possible</option>
<option value="Cow">Things without a Name</option> <option value="Cow">Things without a Name</option>
<option value="Pig">Etc.</option> <option value="Pig">Etc.</option>
-->
</select> </select>
</p> </p>
</div> </div>