Using Coconuts - a Pythonic Blog

Username:

Password:


Don't have an account? Get one!

Long, Long Rant About Blog Upgrades I Hope To Implement (And A Fittingly Long Title To Go With It)

My blog sucks. It is a hacked-together piece of junk. To even just operate it, you need knowledge of web development. The security for it is shaky, and it's got Python, HTML, Javascript, and SQL all intermingled in one huge file. It is also hard to install, insecure, and hard to expand on if you're not me. Even I can't exactly remember what some parts of it do.

http://blog.opensourcenerd.com/upload/fsm

My code threw a fit when I revealed to it that FSMism is a joke.

So, to avoid any Flying Python-Spaghetti Monsters, I'm rewriting my blog engine from square one, the Pythonic way. Read: no SQL or plain procedural programming.

The Database

I believe I've commented on this database software before: Durus. Durus is a Python persistent object database. Meaning? I just give it an object and it's automatically stored in the database. I can fetch it up later at my convenience. Meaning? This:

rootobj['foo'] = 'bar'

connection.commit()
connection.close()

Then, later, I can do this:

if rootobj['foo'] == 'bar':
    print 'Yay! I win!'
else:
    print 'Aww... :('

connection.close()

Actually I'm probably going to have a Durus server running and accepting connections from the localhost just so that the database doesn't get locked and prevent two users from loading pages at the same time on my site. Plus, I can store collections of stuff using the PersistentList and PersistentDict special classes, which sense when they've been changed and report it to the server to update them. And, I can make my own custom classes that subclass the general Persistent class, and they will know when their attributes have been changed, too! Speaking of classes:

Object-Oriented Programming

It doesn't just mean refusing to use antique, abstracted SQL to store data. It means my data actually is objects. Like this:

class Entry(Persistent):
    def __init__(self, title, data, author, date, datatype='RST'):
        self.title = cgi.escape(title)
        self.data = data
        self.author = author
        if type(self.author) is str:
           self.author = cgi.escape(self.author)
        self.date = date
        self.datatype = datatype
        self.comments = PersistentList([])

    @property
    def htmldata(self):
        if datatype == 'RST':
            return RSTtoHTML(self.data)
        elif datatype == 'HTML':
            from warnings import warn
            warn('HTML is deprecated and unsafe. Don\'t use it.')
            return self.data
        raise NotImplementedError('Only RST is implemented for now!')

class Comment(Persistent):
    def __init__(self, data, author, date, datatype='RST'):
        self.data = data
        self.author = author
        if type(self.author) is str:
           self.author = cgi.escape(self.author)
        self.date = date
        self.datatype = datatype

    @property
    def htmldata(self):
        if datatype == 'RST':
            return RSTtoHTML(self.data)
        elif datatype == 'HTML':
            from warnings import warn
            warn('HTML is deprecated and unsafe. Don\'t use it.')
            return self.data
        raise NotImplementedError('Only RST is implemented for now!')

An instance of the Entry object can now just be thrown into Durus, instead of a weird dict of data or something similar. I can also have variable types of data; the author, for example, can be either a simple string, or an instance of the future User object. All this doesn't mean much for a class that's merely a storage container, but as you can see, the Entry and Comment classes can dynamically serve their respective data in multiple...

Formats!

It has been brought to my attention that my way of doing comments is ugly. Yes, it is. I don't allow much formatting, and even for that, the behind-the-scenes code to keep the comments secure is pure disgusting. So, in the future, I'm going to offer ReST (aka RST) and BBCode. Both of these have separate, well-established Python modules for their processing, so I don't need to write any weird interpreter/parser/validator for them. More on that later.

Images

http://blog.opensourcenerd.com/upload/bored-cat

Yeah, I know. I'm a boring guy. But if you haven't quit reading yet, I might yet have something worthy to say. Or maybe you just want to know that yes, I will have a way for you to upload images into comments. Not like my images are managed now (manual FTP upload into my /resources/ directory), but rather inside the database.

It will probably be only for thosee who log on, though, and logon will be solely given with my permission for account creation. If someone finds it funny to make my site a mirror for goatse, they will pay, and I would like to know who they are so I can make them pay in person.

One last thing before I stop boring you:

Code Readability

For those of you that are interested in reading, using, or modifying my code, my current codebase is insane even for my eyes... much less others'. I promise, I'll try to avoid doing that this time around. Open source software is no fun if it's closed source by obscurity (or FSM).

With that said, thank you for sticking with me through my insane rant that somewhat organized what I want to do by vomiting text onto this page.


In other news, my Emacs editor decided to suddenly turn into an e-mail client while I was writing this blog post. I don't even know what shortcut I mistyped... or that Emacs can do emails! (along with being a text editor, calculator, web browser, tetris game, and psychiatrist)

New Comment
You're not logged in! Log in to be awesome!
Format: BBCode ReStructured Text

Author (max. 20 characters):