Permalink
Browse files

Initial refactor of django_website; moving things around.

  • Loading branch information...
jacobian committed May 27, 2010
1 parent 1608660 commit d5c2cc56595de74ac020432e87350a90ba39a823
Showing with 186 additions and 1,236 deletions.
  1. 0 django_website/{apps → accounts}/__init__.py
  2. 0 django_website/{apps → }/accounts/forms.py
  3. 0 django_website/{apps → }/accounts/urls.py
  4. 0 django_website/{apps/accounts → aggregator}/__init__.py
  5. +3 −1 django_website/{apps → }/aggregator/admin.py
  6. +75 −0 django_website/aggregator/bin/update_feeds.py
  7. +3 −1 django_website/{apps → }/aggregator/feeds.py
  8. 0 django_website/{apps → }/aggregator/models.py
  9. 0 django_website/{apps/aggregator → aggregator/templatetags}/__init__.py
  10. +26 −0 django_website/aggregator/templatetags/aggregator.py
  11. 0 django_website/apps/docs/__init__.py
  12. +0 −180 django_website/apps/docs/builder.py
  13. +0 −19 django_website/apps/docs/models.py
  14. +0 −879 django_website/apps/docs/smartypants.py
  15. +0 −12 django_website/apps/docs/urls.py
  16. +0 −121 django_website/apps/docs/views.py
  17. 0 django_website/{apps/aggregator/management/commands → blog}/__init__.py
  18. +3 −1 django_website/{apps → }/blog/admin.py
  19. +4 −2 django_website/{apps → }/blog/feeds.py
  20. 0 django_website/{apps → }/blog/models.py
  21. 0 django_website/{apps/blog → blog/templatetags}/__init__.py
  22. +3 −1 django_website/{apps → }/blog/templatetags/weblog.py
  23. +3 −1 django_website/{apps → }/blog/urls.py
  24. 0 django_website/{apps/blog/templatetags → contact}/__init__.py
  25. 0 django_website/{apps → }/contact/forms.py
  26. +3 −1 django_website/{apps → }/contact/urls.py
  27. 0 django_website/{apps/contact/__init__.py → legacy/__init_.py}
  28. +18 −0 django_website/legacy/docurls.py
  29. +10 −0 django_website/legacy/views.py
  30. +16 −0 django_website/middleware.py
  31. +4 −10 django_website/settings.py
  32. +4 −2 django_website/sitemaps.py
  33. +7 −5 django_website/urls.py
  34. +4 −0 requirements.txt
@@ -1,5 +1,7 @@
+from __future__ import absolute_import
+
from django.contrib import admin
-from django_website.apps.aggregator.models import Feed, FeedItem, FeedType
+from .models import Feed, FeedItem, FeedType
admin.site.register(Feed,
list_display = ["title", "public_url", "is_defunct"],
@@ -0,0 +1,75 @@
+"""
+Update feeds for Django community page. Requires Mark Pilgrim's excellent
+Universal Feed Parser (http://feedparser.org)
+"""
+
+import os
+import sys
+import time
+import socket
+import optparse
+import datetime
+import feedparser
+
+LOCKFILE = "/tmp/update_feeds.lock"
+def update_feeds(verbose=False):
+ from django_website.apps.aggregator.models import Feed, FeedItem
+ for feed in Feed.objects.filter(is_defunct=False):
+ if verbose:
+ print feed
+ parsed_feed = feedparser.parse(feed.feed_url)
+ for entry in parsed_feed.entries:
+ title = entry.title.encode(parsed_feed.encoding, "xmlcharrefreplace")
+ guid = entry.get("id", entry.link).encode(parsed_feed.encoding, "xmlcharrefreplace")
+ link = entry.link.encode(parsed_feed.encoding, "xmlcharrefreplace")
+
+ if not guid:
+ guid = link
+
+ if hasattr(entry, "summary"):
+ content = entry.summary
+ elif hasattr(entry, "content"):
+ content = entry.content[0].value
+ elif hasattr(entry, "description"):
+ content = entry.description
+ else:
+ content = u""
+ content = content.encode(parsed_feed.encoding, "xmlcharrefreplace")
+
+ try:
+ if entry.has_key('modified_parsed'):
+ date_modified = datetime.datetime.fromtimestamp(time.mktime(entry.modified_parsed))
+ elif parsed_feed.feed.has_key('modified_parsed'):
+ date_modified = datetime.datetime.fromtimestamp(time.mktime(parsed_feed.feed.modified_parsed))
+ elif parsed_feed.has_key('modified'):
+ date_modified = datetime.datetime.fromtimestamp(time.mktime(parsed_feed.modified))
+ else:
+ date_modified = datetime.datetime.now()
+ except TypeError:
+ date_modified = datetime.datetime.now()
+
+ try:
+ feed.feeditem_set.get(guid=guid)
+ except FeedItem.DoesNotExist:
+ feed.feeditem_set.create(title=title, link=link, summary=content, guid=guid, date_modified=date_modified)
+
+def main(argv):
+ socket.setdefaulttimeout(15)
+ parser = optparse.OptionParser()
+ parser.add_option('--settings')
+ parser.add_option('-v', '--verbose', action="store_true")
+ options, args = parser.parse_args(argv)
+ if options.settings:
+ os.environ["DJANGO_SETTINGS_MODULE"] = options.settings
+ update_feeds(options.verbose)
+
+if __name__ == '__main__':
+ try:
+ lockfile = os.open(LOCKFILE, os.O_CREAT | os.O_EXCL)
+ except OSError:
+ sys.exit(0)
+ try:
+ sys.exit(main(sys.argv))
+ finally:
+ os.close(lockfile)
+ os.unlink(LOCKFILE)
@@ -1,5 +1,7 @@
+from __future__ import absolute_import
+
from django.contrib.syndication.feeds import Feed
-from django_website.apps.aggregator.models import FeedItem
+from .models import FeedItem
class CommunityAggregatorFeed(Feed):
title = "The Django community aggregator"
@@ -0,0 +1,26 @@
+from __future__ import absolute_import
+
+from django import template
+from .models import Feed
+
+class FeedListNode(template.Node):
+ def __init__(self, varname):
+ self.varname = varname
+
+ def render(self, context):
+ context[self.varname] = Feed.objects.filter(is_defunct=False)
+ return ''
+
+def do_get_feed_list(parser, token):
+ """
+ {% get_feed_list as feed_list %}
+ """
+ bits = token.contents.split()
+ if len(bits) != 3:
+ raise template.TemplateSyntaxError, "'%s' tag takes two arguments" % bits[0]
+ if bits[1] != "as":
+ raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0]
+ return FeedListNode(bits[2])
+
+register = template.Library()
+register.tag('get_feed_list', do_get_feed_list)
No changes.
@@ -1,180 +0,0 @@
-"""
-Code to do the ReST --> HTML generation for the docs.
-"""
-
-import re
-import compiler
-import smartypants
-from docutils import nodes
-from docutils.core import publish_parts
-from docutils.writers import html4css1
-
-def build_document(text):
- """
- Build a doc file into a dict of HTML bits.
- """
- return publish_parts(text, writer=DjangoHTMLWriter(), settings_overrides={'initial_header_level': 2})
-
-docstring_re = re.compile(r"([\"']{3})(.*?)(\1)", re.DOTALL|re.MULTILINE)
-def build_model_document(text):
- """
- Build a test example into a dict of HTML bits.
- """
- # We need to parse the model file without actually executing it.
- tree = compiler.parse(text)
-
- # Get the title and blurb from the module's docstring
- title, blurb = tree.doc.strip().split('\n', 1)
- parts = publish_parts(blurb, writer=DjangoHTMLWriter(), settings_overrides={'initial_header_level': 2})
- parts["title"] = title
-
- # Walk the tree and parse out the bits we care about.
- visitor = compiler.walk(tree, ModelSourceVistor())
- parts["api_usage"] = visitor.doctest
- parts["models"] = visitor.models
-
- # Parse out the model source.
- try:
- model_source = text[:text.index("__test__")]
- except ValueError:
- model_source = text
- parts["model_source"] = model_source.replace(tree.doc, "").replace('""""""\n', '\n').strip()
-
- return parts
-
-class ModelSourceVistor:
- """AST visitor for a model module."""
-
- def __init__(self):
- self.doctest = ""
- self.models = []
-
- def visitAssign(self, node):
- assname, valtree = node.getChildren()
- if assname.name == "__test__":
- self.doctest = valtree.getChildren()[1].value
-
- def visitClass(self, node):
- if node.bases and isinstance(node.bases[0], compiler.ast.Getattr) and node.bases[0].attrname == "Model":
- self.models.append(node.name)
-
-class DjangoHTMLWriter(html4css1.Writer):
- """
- HTML writer that adds a "toc" key to the set of doc parts.
- """
- def __init__(self):
- html4css1.Writer.__init__(self)
- self.translator_class = DjangoHTMLTranslator
-
- def translate(self):
- # build the document
- html4css1.Writer.translate(self)
-
- # build the contents
- contents = self.build_contents(self.document)
- contents_doc = self.document.copy()
- contents_doc.children = contents
- contents_visitor = self.translator_class(contents_doc)
- contents_doc.walkabout(contents_visitor)
- self.parts['toc'] = "<ul class='toc'>%s</ul>" % ''.join(contents_visitor.fragment)
-
- def build_contents(self, node, level=0):
- level += 1
- sections = []
- i = len(node) - 1
- while i >= 0 and isinstance(node[i], nodes.section):
- sections.append(node[i])
- i -= 1
- sections.reverse()
- entries = []
- autonum = 0
- depth = 4 # XXX FIXME
- for section in sections:
- title = section[0]
- entrytext = title
- try:
- reference = nodes.reference('', '', refid=section['ids'][0], *entrytext)
- except IndexError:
- continue
- ref_id = self.document.set_id(reference)
- entry = nodes.paragraph('', '', reference)
- item = nodes.list_item('', entry)
- if level < depth:
- subsects = self.build_contents(section, level)
- item += subsects
- entries.append(item)
- if entries:
- contents = nodes.bullet_list('', *entries)
- return contents
- else:
- return []
-
-class DjangoHTMLTranslator(html4css1.HTMLTranslator):
- """
- reST -> HTML translator subclass that fixes up the parts of docutils I don't like.
- """
-
- # Prevent name attributes from being generated
- named_tags = []
-
- def __init__(self, document):
- html4css1.HTMLTranslator.__init__(self, document)
- self._in_literal = 0
-
- # Remove the default border=1 from <table>
- def visit_table(self, node):
- self.body.append(self.starttag(node, 'table', CLASS='docutils'))
-
- # Prevent <h3> from becoming <h3><a id>
- #def visit_title(self, node, move_ids=1):
- # if isinstance(node.parent, nodes.Admonition):
- # self.body.append(self.starttag(node, 'p', '', CLASS='admonition-title'))
- # self.context.append("</p>\n")
- # else:
- # html4css1.HTMLTranslator.visit_title(self, node, move_ids=0)
-
- #
- # Apply smartypants to content when not inside literals
- #
- def visit_literal_block(self, node):
- self._in_literal += 1
- html4css1.HTMLTranslator.visit_literal_block(self, node)
-
- def depart_literal_block(self, node):
- html4css1.HTMLTranslator.depart_literal_block(self, node)
- self._in_literal -= 1
-
- def visit_literal(self, node):
- self._in_literal += 1
- try:
- html4css1.HTMLTranslator.visit_literal(self, node)
- finally:
- self._in_literal -= 1
-
- def encode(self, text):
- text = html4css1.HTMLTranslator.encode(self, text)
- if self._in_literal <= 0:
- text = smartypants.smartyPants(text, "qde")
- return text
-
- #
- # Avoid <blockquote>s around merely indented nodes.
- # Adapted from http://thread.gmane.org/gmane.text.docutils.user/742/focus=804
- #
-
- _suppress_blockquote_child_nodes = (
- nodes.bullet_list, nodes.enumerated_list, nodes.definition_list,
- nodes.literal_block, nodes.doctest_block, nodes.line_block, nodes.table
- )
- def _bq_is_valid(self, node):
- return len(node.children) != 1 or not isinstance(node.children[0], self._suppress_blockquote_child_nodes)
-
- def visit_block_quote(self, node):
- if self._bq_is_valid(node):
- html4css1.HTMLTranslator.visit_block_quote(self, node)
-
- def depart_block_quote(self, node):
- if self._bq_is_valid(node):
- html4css1.HTMLTranslator.depart_block_quote(self, node)
-
-
@@ -1,19 +0,0 @@
-from django.db import models
-
-class DocumentRelease(models.Model):
- version = models.CharField(max_length=20, unique=True)
- repository_path = models.CharField(max_length=50, help_text="(i.e. 'tags/releases/0.95' or 'branches/0.95-bugfixes')")
- release_date = models.DateField()
-
- class Meta:
- ordering = ('-release_date',)
-
- class Admin:
- list_display = ("version", "repository_path", "release_date")
-
- def __unicode__(self):
- return self.version
-
- def get_absolute_url(self):
- return "/documentation/%s/" % (self.version)
-
Oops, something went wrong.

0 comments on commit d5c2cc5

Please sign in to comment.