Permalink
Browse files

fixed many pep8 violation and general source code cleanups.

git-svn-id: file:///Users/brian/Backups/S3/backups/Wednesday/brian/svn/djog/trunk@87 95ab7de8-677b-4562-a266-b8acc9dd993c
  • Loading branch information...
1 parent f887ef4 commit 1ef1e4a493b8c5784de40023ec4ae2a540497791 @brosner committed Dec 19, 2007
Showing with 73 additions and 15 deletions.
  1. +1 −0 djog/context_processors.py
  2. +22 −4 djog/feeds.py
  3. +13 −2 djog/forms.py
  4. +3 −1 djog/management.py
  5. +5 −0 djog/managers.py
  6. +23 −6 djog/models.py
  7. +2 −2 djog/sites.py
  8. +4 −0 djog/templatetags/djog_utils.py
@@ -1,6 +1,7 @@
from djog import site
+
def blog(request):
return dict(
site = site,
View
@@ -9,7 +9,11 @@
from djog import site
from djog.models import Entry, Tag
+
class EntryFeed(Feed):
+ """
+ Feed of the latest 10 entries.
+ """
def title(self):
return "%s: Latest Entries" % site.get_blog().title
@@ -22,7 +26,11 @@ def description(self):
def items(self):
return Entry.objects.order_by('-pub_date')[:10]
+
class CommentsByEntryFeed(Feed):
+ """
+ Feed of the latest 10 comments on a specific entry.
+ """
def get_object(self, bits):
if len(bits) != 4:
raise ObjectDoesNotExist
@@ -42,14 +50,21 @@ def items(self, obj):
content_type__model = 'entry').filter(
object_id = obj.pk).order_by('-submit_date')[:10]
+
class EntriesByTagFeed(Feed):
+ """
+ Feed of latest 10 entries of a given tag.
+ """
def get_object(self, bits):
if len(bits) != 1:
raise ObjectDoesNotExist
return Tag.objects.get(slug__exact=bits[0])
def title(self, obj):
- return "%s: Entries Tagged with \"%s\"" % (site.get_blog().title, obj.tag)
+ return "%s: Entries Tagged with \"%s\"" % (
+ site.get_blog().title,
+ obj.tag,
+ )
def link(self, obj):
return "%s" % obj.get_absolute_url()
@@ -60,7 +75,11 @@ def description(self, obj):
def items(self, obj):
return Entry.objects.filter(tags__tag=obj.tag)[:10]
+
class SearchFeed(Feed):
+ """
+ Feed of results for a given search term.
+ """
def get_object(self, bits):
if len(bits) != 1:
raise ObjectDoesNotExist
@@ -76,6 +95,5 @@ def description(self, obj):
return "Search results for \"%s\"" % obj
def items(self, obj):
- return Entry.objects.filter(Q(title__icontains=obj) | Q(text__icontains=obj))
-
-
+ return Entry.objects.filter(
+ Q(title__icontains=obj) | Q(text__icontains=obj))
View
@@ -1,5 +1,16 @@
+
from django import newforms as forms
+from django.utils.translation import ugettext_lazy as _
+
class CommentForm(forms.Form):
- person_name = forms.CharField(label='Name (required)', widget=forms.TextInput(attrs={'size':'22'}))
- comment = forms.CharField(label='', widget=forms.Textarea(attrs={'cols':'60'}))
+ """
+ A form representing a comment on an entry.
+ """
+ person_name = forms.CharField(
+ label = _("Name (required)"),
+ widget = forms.TextInput(attrs=dict(size="22")))
+
+ comment = forms.CharField(
+ label = "",
+ widget = forms.Textarea(attrs=dict(cols="60")))
View
@@ -6,6 +6,7 @@
from djog.models import Blog
from djog import models as blog_app
+
def create_default_blog(app, created_models, verbosity):
if Blog in created_models and Site in created_models:
if verbosity >= 2:
@@ -15,4 +16,5 @@ def create_default_blog(app, created_models, verbosity):
b = Blog(site=s, title='Default Blog')
b.save()
-dispatcher.connect(create_default_blog, sender=blog_app, signal=signals.post_syncdb)
+dispatcher.connect(create_default_blog, sender = blog_app,
+ signal = signals.post_syncdb)
View
@@ -1,7 +1,12 @@
from django.db import models
+
class EntryManager(models.Manager):
+ """
+ An Entry Manager class.
+ """
+
def of_type(self, type_):
"""
Returns a queryset filtering the entries to the given type.
View
@@ -1,5 +1,9 @@
-import datetime, httplib, urllib, urlparse, re
+import re
+import urllib
+import httplib
+import datetime
+import urlparse
from django.core import urlresolvers
from django.db import models
@@ -11,6 +15,7 @@
from djog.managers import EntryManager
+
class Blog(models.Model):
site = models.ForeignKey(Site)
title = models.CharField(_("title"), max_length=100)
@@ -31,7 +36,12 @@ def __unicode__(self):
def get_absolute_url(self):
return urlresolvers.reverse('djog_index')
+
class Entry(models.Model):
+ """
+ Represents either a blog post or page in the blog.
+ """
+
TYPE_POST = 0
TYPE_PAGE = 1
@@ -42,13 +52,17 @@ class Entry(models.Model):
blog = models.ForeignKey(Blog, verbose_name=_("blog"))
title = models.CharField(_("title"), max_length=100, unique=True)
- slug = models.SlugField(_("slug"), prepopulate_from=("title",), max_length=100, unique=True)
+ slug = models.SlugField(_("slug"), max_length=100, unique=True,
+ prepopulate_from=("title",))
text = models.TextField(_("text"))
author = models.ForeignKey(User, verbose_name=_("author"))
- tags = models.ManyToManyField("Tag", verbose_name=_("tag"), filter_interface=models.HORIZONTAL)
- pub_date = models.DateTimeField(_("publish date"), default=datetime.datetime.now)
+ tags = models.ManyToManyField("Tag", verbose_name=_("tag"),
+ filter_interface=models.HORIZONTAL)
+ pub_date = models.DateTimeField(_("publish date"),
+ default=datetime.datetime.now)
entry_type = models.IntegerField(_("entry type"), choices=ENTRY_TYPES,
- help_text=_("Select what type of entry this is, currently there are regular blog posts, and pages (ex. about or contact page)."),
+ help_text=_("Select what type of entry this is, currently there are "
+ "regular blog posts, and pages (ex. about or contact page)."),
radio_admin=True, default=TYPE_POST)
objects = EntryManager()
@@ -91,6 +105,7 @@ def get_rss_url(self):
def get_trackback_url(self):
return urlresolvers.reverse('djog_trackback', kwargs=dict(id=self.pk))
+
class Tag(models.Model):
blog = models.ForeignKey(Blog, verbose_name=_("blog"))
tag = models.CharField(_("tag"), max_length=50, unique=True, core=True)
@@ -123,6 +138,7 @@ def get_rss_url(self):
url = 'tags/%s' % self.slug
))
+
class TrackBack(models.Model):
entry = models.ForeignKey(Entry, verbose_name=_("entry"), edit_inline=models.STACKED, num_in_admin=1)
url = models.URLField(_("URL"), max_length=255, core=True)
@@ -192,6 +208,7 @@ def save(self, **kwargs):
self.ping()
super(TrackBack, self).save(**kwargs)
+
class IncomingTrackBack(models.Model):
title = models.CharField(_("title"), max_length=255, null=True, blank=True, editable=False)
excerpt = models.CharField(_("excerpt"), max_length=255, null=True, blank=True, editable=False)
@@ -210,11 +227,11 @@ class Meta:
class Admin:
pass
+
class Configuration(models.Model):
blog = models.ForeignKey(Blog, verbose_name=_("blog"))
option = models.CharField(_("option"), max_length=255)
value = models.CharField(_("option"), max_length=255)
def __unicode__(self):
return "%s: %s" % (self.option, self.value)
-
View
@@ -9,9 +9,9 @@
from django.contrib.comments.views.comments import post_free_comment
from django.contrib.syndication.views import feed
+from djog.forms import CommentForm
from djog.models import Blog, Tag, Entry
-from djog.forms import CommentForm
class DjogSite(object):
@@ -115,7 +115,7 @@ def feed(self, request, url):
return feed(request, url, self.feeds)
def search(self, request):
- if not request.GET.has_key('s'):
+ if "s" not in request.GET:
return HttpResponseRedirect(urlresolvers.reverse('djog_index'))
search = smart_str(request.GET['s'])
results = Entry.objects.filter(
@@ -8,11 +8,13 @@ def show_entry(entry):
return dict(entry=entry)
register.inclusion_tag("entry.html")(show_entry)
+
def show_tags():
tags = Tag.objects.all().order_by("tag")
return {"tags": [tag for tag in tags if tag.num_stories > 0]}
register.inclusion_tag("tags.html")(show_tags)
+
def show_archive():
entries = Entry.objects.of_type(Entry.TYPE_POST)
dates = []
@@ -24,11 +26,13 @@ def show_archive():
return {"counts": dates}
register.inclusion_tag("monthly.html")(show_archive)
+
def show_pages():
pages = Entry.objects.of_type(Entry.TYPE_PAGE)
return {"pages": pages}
register.inclusion_tag("pages.html")(show_pages)
+
def searchify(term):
return "search/%s" % term
register.filter("searchify", searchify)

0 comments on commit 1ef1e4a

Please sign in to comment.