Just a test of syntaxhighlighter in blogger

Friday, February 27, 2009

This is just a test of syntaxhighlighter.


from couchdb.schema import Document, View, IntegerField, TextField
from couchdb import Database

map_fun = """
function(doc){
emit(doc.name, doc.age);
}
"""
class Person(Document):
name = TextField()
age = IntegerField()
by_name = View('people', map_fun)

db = Database("http://127.0.0.1:5984/borrame")

# to make a view permanent do this
from couchdb.design import ViewDefinition
ViewDefinition.sync_many(db, [Person.by_name])

Person(name = "batok", age = 48).store(db)
Person(name = "rgalvan", age = 47).store(db)
Person(name = "robert", age = 30).store(db)

for person in Person.by_name( db, limit = 3):
print person.name, person.age

Introducing blogcdb

Monday, December 22, 2008

I have created a new project at github.

It's blogcdb ( a blog engine that uses couchdb ).

The blog engine is made with turbogears 2, a very good python web framework.

Also uses dojo javascript framework for some fancy stuff. Dojo version 1.2.3 is included.

To store blog posts, comments and attachments , the erlang based couchdb document database engine is used.

Requirements:

couchdb-python module by Christopher Lenz and Jan Lenhardt.
python 2.6
turbogears 2 : trunk version which also needs a lot of modules.
dojo 1.2.3 ( included ).
couchdb ( svn truk version ) available from apache software foundation.
erlang/otp
mozilla's spidermonkey.

Get blogcdb at http://www.github.com/batok/blogcdb

A wxpython GUI interface to a blog.

Wednesday, December 10, 2008



I have created a github project with the name couchdb-wxpython.


The project is a python script that uses:

wxpython ( a python module for GUI which is cross-platform. It is a wrapper for wxwidgets ).

couchdb , a document oriented database to store blogposts , comments and attachments.


The program can also take screenshots and store them as attachments into couchdb.

New attachment handling in couchdb-python module

Tuesday, September 09, 2008

I've been trying out the new methods for the Database class in couchdb-python, in the svn repository.

I tried put_attachment.

Guess you already have a couchdb database called blog. To get a reference to the db you have to...


from couchdb.schema import *


class Post(Document):
author = TextField()
subject = TextField()
content = TextField()
tags = ListField( TextField() )
comments = ListField( DictField(Schema.build(
comment_author = TextField(),
comment = TextField(),
comment_date = DateTimeField()
)))
date = DateTimeField()


from couchdb import Server
from datetime import datetime
import binascii
s = Server("http://127.0.0.1:5984/")
s.create("blog")
blog = s["blog"]
p = Post( author = "Me", subject = "Whatever for the subject ", content = "Any content",date = datetime.now(), tags = ["Python", "Couchdb", "Blog"])

p.store(blog)

f = open("apythonfile.py", "rb")
foo = binascii.b2a_base64(f.read()) # this convert the content of the file to a encode 64 string

#put_attachment only works right now with an encoded string as I see and with a dictionary object for the document ( first parameter ) and not for a Document instance as used here , so...


blog = s["blog"]
adoc = blog[p.id]

and finally call the method...

blog.put_attachment( adoc, "apythonfile.py", foo, "text/python")

#you can't do blog.put_attachment( p, "apythonfile.py", f, "text/python") which I taught by reading the doc inside the method.