mirror of https://github.com/scrapy/scrapy.git
Add publish field
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40114
This commit is contained in:
parent
9f8ce8f116
commit
e421206573
|
|
@ -22,12 +22,15 @@ class Article(models.Model):
|
|||
default=False, help_text=MAIN_HELP_TEXT)
|
||||
position = models.IntegerField(_("position"), core=True, blank=False,
|
||||
default=0)
|
||||
|
||||
publish = models.BooleanField(_("publish"), core=True, default=False)
|
||||
|
||||
# automatic dates
|
||||
created = models.DateTimeField(core=True, editable=False)
|
||||
updated = models.DateTimeField(core=True, editable=False)
|
||||
|
||||
def toggle_publish(self):
|
||||
self.publish = not self.publish
|
||||
self.save()
|
||||
|
||||
def position_up(self):
|
||||
self.position += 1
|
||||
|
|
@ -46,7 +49,7 @@ class Article(models.Model):
|
|||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
# ugly, but django-admin isn't very versatile right now
|
||||
def position_link(self):
|
||||
return _("%(position)s (<a href='/admin/article/article/%(id)s/position/up/'>Up</a>" \
|
||||
|
|
@ -54,10 +57,20 @@ class Article(models.Model):
|
|||
{ "position": self.position, "id": self.id }
|
||||
position_link.short_description = u"position"
|
||||
position_link.allow_tags = True
|
||||
|
||||
|
||||
def publish_link(self):
|
||||
img_url = "/media/img/admin/icon-%s.gif" % \
|
||||
(self.publish and "yes" or "no")
|
||||
html = _('<img alt="%s" src="' + img_url + '"/> ' \
|
||||
'(<a href="%s/publish/toggle/">Toggle</a>)')
|
||||
return html % (_(str(self.publish)), self.id)
|
||||
publish_link.short_description = u"publish"
|
||||
publish_link.allow_tags = True
|
||||
|
||||
class Admin:
|
||||
list_display = ("title", "main", "position_link", "updated")
|
||||
list_filter = ("main", "created")
|
||||
list_display = ("title", "main", "position_link", "publish_link",
|
||||
"updated")
|
||||
list_filter = ("main", "created", "publish")
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("article")
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class LoadArticlesNode(template.Node):
|
|||
self.var_name = var_name
|
||||
|
||||
def render(self, context):
|
||||
articles = Article.objects.all()
|
||||
articles = Article.objects.filter(publish=True)
|
||||
if self.only_main:
|
||||
articles = articles.filter(main=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ from scrapyorg.article.views import *
|
|||
urlpatterns = patterns('',
|
||||
(r"^(?P<article_id>\d+)/position/up/$", position_up),
|
||||
(r"^(?P<article_id>\d+)/position/down/$", position_down),
|
||||
(r"^(?P<article_id>\d+)/publish/toggle/$", publish_toggle),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -16,3 +16,9 @@ def position_down(request, article_id):
|
|||
article = get_object_or_404(Article, pk=article_id)
|
||||
article.position_down()
|
||||
return HttpResponseRedirect("/admin/article/article/")
|
||||
|
||||
@staff_member_required
|
||||
def publish_toggle(request, article_id):
|
||||
article = get_object_or_404(Article, pk=article_id)
|
||||
article.toggle_publish()
|
||||
return HttpResponseRedirect("/admin/article/article/")
|
||||
|
|
|
|||
Loading…
Reference in New Issue