back-end work complete for publish page

This commit is contained in:
Sanj 2011-07-09 18:17:12 +05:30
parent 9f6c7b16a8
commit 51a8c7cd58
3 changed files with 65 additions and 9 deletions

View File

@ -15,6 +15,7 @@ from tagging.fields import TagField
from tagging.models import Tag
from copy import deepcopy
from sorl.thumbnail import get_thumbnail
from django.db.models import Q
def addPx(val):
'''
@ -204,6 +205,11 @@ class Article(models.Model):
groups = models.ManyToManyField(Group, blank=True)
theme = models.ForeignKey(ArticleTheme, blank=True, null=True)
class Meta:
unique_together = ('product', 'order',)
ordering = ['-created']
'''
Return boolean for whether user can edit article on tool or not - must be passed a valid User object.
'''
@ -241,18 +247,27 @@ class Article(models.Model):
return False
@classmethod
def get_can_edit_list(kls, user, qset=False):
if not qset:
qset = kls.objects.all()
return qset.filter(Q(owner=user) | Q(users=user))
# for q in qset:
@classmethod
def get_published_list(kls, user, qset=False):
if not qset:
qset = kls.objects.all()
return qset.objects.filter(published=True)
return qset.filter(published=True).exclude(Q(owner=user) | Q(users=user))
@classmethod
def fts(kls, search, qset=False):
if not qset:
qset = kls.objects.all()
return qset.objects.filter(name__icontains=search)
return qset.filter(name__icontains=search)
@ -345,8 +360,17 @@ class Article(models.Model):
rList.append(p.get_dict(m))
return rList
class Meta:
unique_together = ('product', 'order',)
def get_list_dict(self, user):
return {
'id': self.id,
'title': self.name,
'can_edit': self.can_edit(user),
'edit_url': "/edit/article/%d/" % (self.id,),
'is_locked': self.locked,
'is_published': self.published,
'web_url': "/edit/web_frontend/%d/" % (self.id,)
}
class PermissionRequest(models.Model):
article = models.ForeignKey(Article)

View File

@ -4,6 +4,8 @@ import Image
import sys
from django.http import HttpResponse
from django.template import RequestContext
from editor.models import Article
from django.contrib.auth.decorators import login_required
def home(request):
context = RequestContext(request, {})
@ -17,8 +19,24 @@ def archive(request):
context = RequestContext(request, {})
return render_to_response("main/archive.html", context)
@login_required
def publish(request):
context = RequestContext(request, {})
user = request.user
can_edit_list = Article.get_can_edit_list(user)
published_list = Article.get_published_list(user)
own_list = []
pub_list = []
for c in can_edit_list:
own_list.append(c.get_list_dict(user))
for p in published_list:
pub_list.append(p.get_list_dict(user))
context = RequestContext(request, {
'own_list': own_list,
'pub_list': pub_list
})
return render_to_response("main/publish.html", context)
def browse(request):

View File

@ -33,10 +33,24 @@ If you are a participant looking to open a new account, please write to contact@
Tool link
</p> <br/>
<p>
Search for an existing article you were working on <br/>
Search for an existing article you were working on</p> <br/>
<ul id="ownList">
{% for o in own_list %}
<li>
<span class="articleTitle">{{ o.title }}</span>
</li>
{% endfor %}
</ul>
Or <br/>
Create a new one
</p>
<ul id="publishedList">
{% for p in pub_list %}
<li>
<span class="articleTitle">{{ p.title }}</span>
</li>
{% endfor %}
</ul>
<br/>
</div>