Hey all, I'm working on my first real Django app.  I've been tinkering
with it since last June, but I actually get to use it now.  So my
question is about what's the Django standard for what I'm doing...

It's a Bible application, and so far, I have a url pattern:
urlpatterns = patterns('',
  (r'^(?P<version>\w+)?/?(?P<book>\w+)/?(?P<chapter>\d+)?/?(?P<verse>\d
+)?(\-)?(?P<verse2>\d+)?/$', verses),
)

which correlates to the method verses:
def verses(request, version, book, chapter, verse, verse2):

  logging.debug("version: " + version)
  logging.debug("book   : " + book)

  # for multi-word books "1 Kings", remove _ and replace with space
  book = re.sub('_', ' ', book)

  if chapter is None:
    verses = Verse.objects.filter(version__iexact=version,
book__iexact=book)
  elif verse is None:
    logging.debug("chapter: " + chapter)
    verses = Verse.objects.filter(version__iexact=version,
book__iexact=book, chapter__iexact=chapter)
  elif verse2 is None:
    logging.debug("chapter: " + chapter)
    logging.debug("verse  : " + verse)
    verses = Verse.objects.filter(version__iexact=version,
book__iexact=book, chapter__iexact=chapter, verse__iexact=verse)
  else:
    logging.debug("chapter: " + chapter)
    logging.debug("verse  : " + verse)
    logging.debug("verse2 : " + verse2)

    #verse2 can't come before verse1
    if verse2 < verse:
      raise Http404

    #filter for a range
    verses = Verse.objects.filter(version__iexact=version,
book__iexact=book, chapter__iexact=chapter,
verse__in=range(int(verse),int(verse2)+1))

  if verses.count() == 0:
    logging.debug("No verses found!")
    raise Http404


  return list_detail.object_list(

    request,

    queryset = verses,

    template_name = 'verse.html',

    template_object_name = 'verses',
    extra_context =
{'book':book,'chapter':chapter,'verse':verse,'verse2':verse2}

  )

Now, is this the standard way of doing this kind of thing?  Or should
I break the method up into different methods and have several
different url patterns?  Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to