Advanced library and API design
I am developing a library that uses CMIS compatible storage as back-end (in my case Alfresco). I would very much li开发者_StackOverflow中文版ke to create a "sexy" API similar to that of Flask-SQLAlchemy and Django. The problem is that I am new to such advanced programming in Python. Here is the imagined way of using this library:
# Here is the connector that does the actual request to the CMIS server
c = CMISConnector('url', 'username', 'password')
# Here I declare the model with the desired property fields. A model
# can be either a folder or a document in Alfresco
class SomeModel(c.Model):
name = c.Property('cmis:name')
# Some query and create examples...
foo = SomeModel.query.first(name='John Doe')
print foo.name
bar = SomeModel(name='Jane Doe')
bar.save()
Since there will be one back-end for the entire object model I want every class that inherits from Model to use the same connection without having to explicitly register it.
Any help would be much appreciated :)
Have you taken a look at cmislib? It's a client-side API for CMIS written in Python. It allows you to work with objects in Alfresco (or any other CMIS-compliant repository).
The API gives you objects like "Document" and "Folder". I think you'd have to write some Django middleware to do the model stuff you are trying to do, but at least cmislib will save you from coding the interaction with Alfresco.
Hope that helps,
Jeff
精彩评论