Now with pretty colours...
Posted 2009-01-27 23:14:50 by .

I've abstracted out the "Basic apps blog" and wrapped it in my own app called 'Musings'. Its not yet at a point where I might consider rolling my own. However I had to do this in order to gain more control over searching, the data returned and the templates in my site. I've also added unit tests to cover the functionality my 'Musings' app is providing.

I'm not a fan of the templates knowing too much about the database and the relationship that entries have to each other. This is something I've noticed in Django and the apps I've looked at so far. It seems to be accepted practice to use database entries directly. For example the basic blog provides a Post entry which can have an Author entry. To access the authors name you might do the following in a template:

1
<em>Author: {{post_object.author.first_name}} post_object.author.last_name</em>

I don't like this at all as it leads to tight coupling which is just bad. Any change to the database would require changes to the template. On a small project that might be ok, however on a large project particularly one without any unit/acceptance testing its a no-no. To allow me to use other blog backends in future I've wrapped what gets returned to hide these relationships and provide only what is needed.

1
<em>Author: {{post_object.author_name}}</em>

I've finally managed to get ReStructuredText markup working along with a custom "sourcecode" directive. This uses Pygments to highlight the source code and includes lines numbers. The code I've used to do this is shown below. Its being marked up by itself ;)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Provide a custom directive for the ReStructuredText I'm using in my blog.

Based on the 'django-rstify' http://code.google.com/p/django-rstify/ by
George Brandl, who released it under the BSD license. I've modified
it a lot to my needs. I've mainly made it less django-centric so I can
use it elsewhere. I'm releasing this code under the BSD License.

Pygments must also be installed for this to work http://pygments.org/

Oisin Mulvihill
2009-01-27

"""
from docutils import nodes
from docutils.core import publish_parts
from docutils.parsers.rst import directives
from docutils.parsers.rst import Directive

from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name, TextLexer


class SourceCode(Directive):
"""My custom sourcecode directive markup using pygments.

For example:

.. sourcecode:: python

import sys

def sayhello(msg):
print 'Hello %s' % msg

sayhello('Bob')
sys.exit(0)

This will result in highlighted code with line numbers,
with the css styles done inline.

"""
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {}
has_content = True

def run(self):
"""Generate sourcecode highlighting based on pygments.
"""
# noclasses=True use inline styles.
formatter = HtmlFormatter(noclasses=True, linenos=True)

try:
lexer = get_lexer_by_name(self.arguments[0])
except ValueError:
# no lexer found - use the text one instead of an exception
lexer = TextLexer()

parsed = highlight(u'\n'.join(self.content), lexer, formatter)

return [nodes.raw('', parsed, format='html')]


def rstify(data):
"""Convert the given restructured text into a html fragment
ready for insertion elsewhere.

data:
This must be text which is valid ReStructuredText.

Returned:
A string containing a html fragment representing the
convert restructured data. Errors in processing will
also be displayed in the string.

This function registers special directives which can be
used.

.. sourcecode:: <Language e.g. python>

code line 1 ...
code line 2 ...
:
etc

"""
directives.register_directive('sourcecode', SourceCode)

parts = publish_parts(data, writer_name='html')

return parts['body']
 

Comments

On 2013-03-21 17:42:09 levitraTexideady (http://www.levitrasafetybuy.com/#rx) wrote:
erection unsteady or does not occur. http://www.levitrasafetybuy.com/#cheap this is a area. Altogether basic rule. http://www.levitrasafetybuy.com/#rx - levitra us oblige you healthier. you improve your life <a href=http://www.levitrasafetybuy.com/#safe>levitra price</a> look fitted discounts
On 2013-05-08 03:03:06 chan luu bracelet (http://www.chanluustore.net/) wrote:
http://www.marcjacobsbagsstore.com http://www.usitccoachpurses.net http://www.voguecoachoutlet.com http://www.marcjacobssale.co.uk http://www.chanluustore.net/
On 2013-10-28 07:00:58 Coach outlet (http://www.legacyoutletstore.com/) wrote:
Notre site vend abercrombie soldes avec la livraison gratuite économiser jusqu'à 70 pour you.buy sacs louis vuitton avec une qualité supérieure, une boutique avec l'expédition rapide libre! [b] Cheap Handbag [url=http://www.asosmacys.com]www.asosmacys.com[/url][/b] Shop At The Official Online Store. Spend Over $75 & Get Free Shipping![/pre] [b]Coach[/b] offers a wide selection of women's designer handbags, wallets, shoes and jewelry. Browse the newest styles from your favorite collections at [b]legacyoutletstore[/b].com. [[url=http://www.legacyoutletstore.com/category/coach-outlet/]Coach outlet[/url]] [[url=http://www.legacyoutletstore.com/latest-coach-outlet-coupon-2/]Coach outlet online[/url]][[url=http://www.legacyoutletstore.com/category/coach-outlet-store-online/]Coach outlet store online[/url]][[url=http://www.legacyoutletstore.com/category/coach-factory-outlet/]Coach factory outlet[/url]] [[url=http://www.legacyoutletstore.com/coach-factory-onlines-end-quality-sale/]Coach factory online[/url]][[url=http://www.legacyoutletstore.com/coach-store-online/]coach store online[/url]] About Marc by Marc Jacobs About Marc by Marc Jacobs Native New Yorker Marc Jacobs began his design career in 1981 when he attended Parsons School of Design. On the evening that Marc Jacobs was showing his senior collection and receiving some of the school's highest honors, a fashion executive in the audience took immediate notice. The conversation that followed led to the creation of a partnership based on two very simple concepts: a love for fashion and a commitment to quality. Two years later, [url=http://www.marcjacobsmarc.com/]Marc Jacobs[/url] ventured out and designed his first clothing collection bearing the [url=http://www.marcjacobsmarc.com/]Marc Jacobs[/url] label. In 1995, he launched his first full collection of men's ready-to-wear clothing. 2000 saw the launch of the first Marc Jacobs handbag collection. In 2001, Marc Jacobs and his business partner, Robert Duffy, introduced their secondary collection, Marc by Marc Jacobs. It was established on the basis of providing a collection of comparatively affordable, edgy, and retro-inspired mass-market pieces. Since then, the collection has continued to grow exponentially to include Marc by Marc Jacobs shoes, Marc by Marc Jacobs handbags, Marc by Marc Jacobs jewelry, Marc by Marc Jacobs eyewear, [url=http://www.marcjacobsmarc.com/]Marc by Marc Jacobs[/url] hair accessories, and [url=http://www.marcjacobsmarc.com/]Marc by Marc Jacobs[/url] watches. Each season, the Marc by Marc Jacobs collections are created with the aim of providing quality shoes, handbags, accessories, eyewear and watches with high fashion designs incorporating the signature quirkiness and unique sense of style that [url=http://www.marcjacobsmarc.com/]Marc by Marc Jacobs[/url] has come to be known for.
On 2013-11-22 01:14:44 prada bags outlet uk (http://pro-sim.com/) wrote:
All right, I'll give you the bad news first. <a href="http://www.coachhandbagsnew2013.com/">Coach handbags new 2013</a> found out that a hoodie from <a href="http://pro-sim.com/flyer/prada_uk.html">prada bags outlet uk</a>'s holiday collection for <a href="http://azscitechfest.asu.edu/prada-outlet-australia">prada outlet</a> will set you back 3K. Britney's annual <a href="https://sites.google.com/site/marcjacobsoutletshop/">Marc jacobs outlet</a> expenditures: $26,784 on coffee, $14,877 for flushing down the <a href="http://pro-sim.com/flyer/marc_by_marc_acobs.html">marc by marc jacobs</a>.Over the past six years, I've just rolled with the punches and have managed to eek out some sort of <a href="http://pro-sim.com/flyer/prada_uk.html">http://pro-sim.com/flyer/prada_uk.html</a> from what I've done with this blog.Get a head <a href="http://pro-sim.com/flyer/prada_uk.html">prada uk</a> start on your holiday shopping thanks to Urban Outfitters! South Asia researcher at the Business & bags Rights Resource <a href="http://www.marcby-marcjacobs.com/">Marc by marc jacobs outlet</a>; Sarah Labowitz, co-director of the New York University <a href="http://pro-sim.com/flyer/marc_by_marc_acobs.html">http://pro-sim.com/flyer/marc_by_marc_acobs.html</a> Center for Business and Marc jacobs Rights;A <a href="http://www.marcbymarcjacobsinc.com/">Marc by marc jacobs bags</a> cross stitching and a custom green leather label show Heineken's involvement with the Marc jacobs outlet bags.
On 2013-12-11 02:38:18 coach store online (http://www.coachstoreonline.com/) wrote:
http://www.coachstoreonline.com/ coach store online http://www.coachoutletstoreonline2014.com/ coach outlet store online http://www.coachfactoryoutlet2014.com/ coach factory outlet http://www.coachhandbagsnew2013.com/ coach handbags outlet http://www.coachfactoryhandbagsoutlet.com/ coach factory handbags outlet http://www.michaelkorsoutlet-store.com/ michael kors outlet http://www.louisvuittonblackfridaybags.com/ louis vuitton black friday http://www.louisvuittonhandbagsnew2013.com/ louis vuitton handbags new 2013 http://www.chan-luu-inc.com/ chan luu http://www.marcjacobsmarc.com/ marc jacobs handbags http://www.marcby-marcjacobs.com/ marc by marc jacobs http://www.marcjacobsoutletstore.com/ marc jacobs outlet http://www.marcjacobsbagsshops.com/ marc jacobs bags http://www.marcbymarcjacobsinc.com/ marc by marc jacobs http://www.marcjacobsinc.com/ marc by marc jacobs bags http://www.marcbymarcjacobs.org/ marc by marc jacobs http://www.michaelkorshandbagsnew2013.com/ michael kors handbags new 2013 http://www.sportfanatics.org/ cheap jerseys http://www.giuseppe-zanottifrance.com/ giuseppe zanotti http://www.sugarsit.com/ coach outlet http://goo.gl/8PkSUC coach factory outlet http://goo.gl/OY98HY michael kors handbags http://goo.gl/C3aqu1 louis vuitton outlet http://goo.gl/JaGdpL fitflops http://azscitechfest.asu.edu/prada-outlet-australia prada outlet https://sites.google.com/site/marcjacobsoutletshop/ marc jacobs outlet
On 2014-01-09 01:23:38 coach factory (http://www.coachfactoryoutlet2014.com/) wrote:
We think you'll create some ripples when you walk into the room wearing this [url=http://www.michaelkorsoutlet-store.com/]michael kors outlet[/url] Striped Flare Dress ($27), which features geometric rings expanding from the neckline.Dang, what if the reason the birds went on a super killing spree was because [url=http://www.michael-kors-outlet-store.com/]michael kors outlet store[/url] was holding ice cream and wouldn't share [url=http://www.coachfactoryoutlet2014.com/]coach factory[/url] ?It's an easy piece to wear both alone and with our other charm bracelets and studded [url=http://www.marcby-marcjacobs.com/]marc by marc jacobs[/url].To see some of the other color options, check them out at [url=http://www.michaelkorshandbagsnew2013.com/]michael kors[/url]. I think we were all a bit surprised when [url=http://www.coach-factory-outlet-online.com/]coach factory outlet online[/url] announced that she was pregnant, and it took a bit of [url=http://www.coachstoreonline.com/]Coach Outlet[/url] and error in regards to confirming if she was pregnant.The first month of 2014 welcomes a new style from [url=http://www.coachinc.nl.ae/]coach outlet[/url], the likes of which we've never seen from the house. Today, Converse launches its spring 2014 [url=http://www.marcjacobsinc.com/]marc by marc jacobs bags[/url] Chuck Taylor All Star v [url=http://www.coachhandbagsnew2014.com/]coach handbags[/url] collection-yes, that's right, [url=http://www.coachfactoryhandbagsoutlet.com/]coach handbags outlet[/url] is making five styles of sneakers this season inspired by heavy metal band [url=http://www.marcjacobsmarc.com/]marc jacobs handbags[/url].(A three-day weekend, perhaps [url=http://www.marcbymarcjacobs.org/]marc by marc jacobs[/url]?) But, while we're all for staying [url=http://www.coachoutletstoreonline2014.com/]coach outlet store online[/url] - bundled up in a plush duvet and our cozy [url=http://www.marcjacobsbagsshops.com/]marc jacobs bags[/url], sipping hot chocolate with lots of [url=http://www.fitflopflip-flop.com/]fitflop shoes[/url] - snow days don't really exist for adults. You'll be able to insert faster running into your training more often, but [url=http://www.louisvuittonhandbagsnew2013.com/]louis vuitton handbags[/url] recover faster after each session.[url=http://www.fitflopsflipflops.com/]fitflops[/url] Series 2014 to create a unique installation inspired by the energy of the dancers.I have everything I could ever possibly need for the next year shoved into my purse, and all the snacks, [url=http://www.coachfactoryoutlet-purses.com/]coach factory outlet[/url], and miscellaneous [url=http://www.marcbymarcjacobsinc.com/]marc by marc jacobs[/url] (that was usually put there by my husband) can sometimes leave a bit of a [url=http://www.marcjacobsoutletstore.com/]marc jacobs outlet[/url] innocent bystander items- like my sunglasses. Specifically, I prefer the [url=http://goo.gl/OY98HY]michael kors handbags[/url] Le Trop Shoulder Bag, which is thoroughly [url=http://goo.gl/8PkSUC]coach factory outlet[/url] but will set you back less than $400.While many of us eat up the joining of two T-shirt brands, 2013 certainly brought us a few [url=http://goo.gl/JaGdpL]fitflops[/url] projects that broke the mold more than others. Coming in [url=http://goo.gl/C3aqu1]louis vuitton outlet[/url], University Red and Light Base Grey, [url=http://www.coachfactoryoutlet2014.com/]www.coachfactory.com/store[/url] includes a mesh and suede upper in addition to a synthetic tongue with vented holes.
On 2014-02-17 02:03:13 coach outlet (http://coachofficialsite.blog.com/) wrote:
http://coachofficialsite.blog.com/ coach outlet http://www.outletsonlinemall.com/ coach outlet http://www.coachoutletstoreonlinebo.net/ coach outlet http://www.louisvuittonoutletbo.com/ louis vuitton http://www.louisvuittonpursesbag.net/ louis vuitton bags http://www.toryburchoutlet-shoes.com/ tory burch outlet http://www.oakleyvault-sunglasses.com/ cheap oakley http://www.truereligionjeansoutletbo.com/ true religion outlet http://www.truereligionoutletfactory.com/ true religion outlet http://www.burberryoutletstoresbo.com/ burberry outlet http://www.michaelkorsoutlethandbag.com/ michael kors outlet http://www.christianlouboutinstore2013.com/ louboutin outlet http://www.christianlouboutinoutletft.com/ christian louboutin outlet http://www.terrybuilt.com/ christian louboutin outlet http://www.scarpehoganoutlet.net/ hogan sito ufficiale http://www.ralphlauren-pascher-france.com/ polo ralph lauren http://www.saclongchampsoldespascher.com/ longchamp pas cher http://www.beatsbydrdre-headphones.com/ beats by dre http://www.hoganshoesoutletsale.co.uk/ hogan http://www.montblancpensoutlet.co.uk/ mont blanc pens http://www.louisvuittonborse-sitoufficiale.com/ louis vuitton http://www.canadagooseoutlet-jackets.com/ Canada Goose Outlet http://www.moncler-jacka.com/ moncler http://www.toryburchoutlet.cc/ tory burch outlet http://www.truereligionjean.cc/ true religion jeans http://www.coachoutlets.cc/ coach outlet http://www.timberlandfr.cc/ timberland pas cher http://www.longchampfr.cc/ longchamp pas cher http://www.hoganit.cc/ hogan outlet http://www.louboutinfr.cc/ louboutin http://www.ralphlaurenfr.cc/ Polo ralph lauren http://www.canadagoosefr.cc/ canada goose http://www.lancelfr.cc/ Lancel http://www.parajumpersjacketscoatsoutlet.com/ parajumpers outlet http://www.marcjacobshandbagsoutlet.net/ marc jacobs outlet http://www.mcmhandbags-backpack.com/ mcm bags http://www.pradaoutletonlineb.com/ prada outlet http://www.pradahandbags-shoes.com/ prada outlet http://www.guccihandbagshoes-outlet.com/ gucci outlet http://www.raymore.ca/aboutus.html Canada Goose Outlet http://www.canadagoose.cc/ Canada Goose Outlet
On 2014-04-08 07:37:04 Ralph Lauren Outlet (http://www.sralphlaurenpolo.com/) wrote:
http://www.burbagssale2013.com/ Burberry Outlet http://www.cheaphollistersale.co.uk/ Cheap Hollister Clothes http://www.coachblackfriday2014.com/ Coach Black Friday http://www.coach-storeoutletonline.com/ Coach Black Friday 2013 http://www.coachcoachoutlet.com/ Coach Cyber Monday http://www.coachxfactory.com/ Coach Factory http://www.coach-factoryoutletonline.net/ Coach Outlet Factory http://www.coach-outletusa.com/ Coach Outlet USA http://www.coach-pursesfactory.com/ Coach Purses Factory http://www.coachpurseusa.com/ Coach Purses USA http://www.coach-storeoutlet.com/ Coach Store Outlet http://www.coachxpursesonsale.com/ Coach Purses On Sale http://www.discountbeatsbydresale.com/ Monster Beats Outlet http://www.louis-vuittonblackfriday.com/ Louis Vuitton Outlet http://www.lv-guccishoesfactory.com/ Louis Vuitton Factory http://www.marcjacobsonsale.com/ Marc Jacobs On Sale http://www.mcmblackfriday.com/ MCM Outlet http://www.mcmoutlet-jp.com/ MCM 店铺 http://www.michaelkorsmas.com/ Michael Kors Outlet http://www.michaelkors.so/ Michael Kors Outlet http://www.michaelkorsfactory-store.com/ Michael Kors Factory http://www.michaelkorsoutletr.com/ Michael Kors Outlet http://www.michael-korsfactoryonline.com/ Michael Kors Factory Online http://www.newcoachfactory.com/ Coach Factory Outlet http://www.north-faceoutletonlines.net/ North Face Outlet Online http://www.polo-outletstore.com/ Polo Outlet Store http://www.ralphlaurenuker.com/ Ralph Lauren UK http://www.saclongchamppairs.com/ Sac Longchamp Pairs http://www.tcoachoutletonline.com/ Coach Outlet Online http://www.the-coachfactoryoutlet.com/ Coach Factory Oultet http://www.uggaustralia.cc/ Ugg Australia http://www.barbour-jacketsoutlet.com/ Barbour Jackets Outlet Online http://www.canada-gooser.com/ Canada Goose Outlet http://www.guccishoes-factorys.com/ Gucci Outlet Online http://www.michaelkors-states.com/ Michael Kors Outlet http://www.moncler-clearance.com/ Moncler Clearance http://www.moncler-jacketsoutletonline.com/ Moncler Jackets Outlet Online http://www.northsclearance.com/ North Clearace Outlet http://www.sralphlaurenpolo.com/ Polo Ralph Lauren Outlet Online http://www.woolrich-clearance.com/ Woolrich Clearance http://www.cvshopfactory.com/ shop.coachfactory.com http://www.mksfactoryoutlet.com/ Michael Kors Factory Outlet http://www.zxcoachoutlet.com/ Coach Outlet Online USA http://www.mischristmas.com/ Coach Factory Outlet Online http://www.misblackfriday.com/ Black Friday http://www.thebeatsbydre.com/ Beats by Dre http://www.newoutletonlinemall.com/ Coach Purses Outlet Online http://www.clickmichaelkors.com/ Michael Kors USA http://www.cmichaelkorsoutlet.com/ Michael Kors Outlet USA http://www.ralphlaurenepolo.com/ Ralph Lauren Polo

New Comment

Your email is never published nor shared.
Required fields are marked *
*
*