On 2014-11-24 10:06, martin f krafft wrote:
> It could come from Git! After all, Git is really a database by
> itself, just like the filesystem could be viewed as a database.
[snip]
> Furthermore, I'd actually like to post-process the data. The Git
> repo would contain reStructuredText files and I'd like to render
> them before filling the result into template slots.
You'd still have to sort out how to know which blob you want to
return/render. If you have the hash-id of it, you can do a direct
lookup. Throwing together some pseudo-code, your urls.py might look
something like
urlpatterns = patterns('',
url(r'^blob/([0-9a-f]{40})/$', 'myapp.views.render_blob', ...),
)
and then in myapp/views.py you'd have something like
from django.shortcuts import render
import some_git_lib
import your_markdown_lib
def render_blob(request, sha):
try:
blob = some_git_lib.fetch_blob(sha)
except some_git_lib.SomeException:
raise # do some actual error handling/reporting here
else:
rendered_markdown = your_markdown_lib.htmlize(blob)
return render(request, "my_template.html", {"data": blob})
Only you know how the sha1 of the blob is determined, but the rest
should give you a pretty straight-forward implementation. In theory,
you could also set the cache control headers in the response so that
they're ludicrously far in the future (assuming you don't plan to
change your my_template.html) because the blob shouldn't ever change
without having a different SHA1.
-tkc
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20141124041927.20723b62%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment