Permalink
Browse files

setup.py adjusted

  • Loading branch information...
2 parents 9c36217 + de928df commit 2e4152eed13d8f3ec9a976ded8991a0aa6b60987 @rafaelnovello rafaelnovello committed Jun 3, 2011
View
@@ -5,3 +5,8 @@ dist/
*.egg-info/
.idea
.idea/*
+bin/
+build/
+examples/
+include/
+lib/
View
@@ -1,6 +1,12 @@
+0.2.0
+* Added CompositeTextProperty
+* Added MultiCompositeTextProperty
+* Added IsisCompositeTextProperty
+* Added MultiIsisCompositeTextProperty
+
0.1.1
---
* Added FileProperty datatype
* Added BooleanProperty datatype
* Embedded _rev and _id in automatic generated forms (couchdb api)
-* Fixed bug that changes the _id attr of a persistent document
+* Fixed bug that changes the _id attr of a persistent document
@@ -0,0 +1,66 @@
+from pyramid.config import Configurator
+from pyramid.response import Response
+from pyramid.view import view_config
+from pyramid.renderers import render_to_response
+
+from paste.httpserver import serve
+from models import Bibitex
+from forms import BibitexForm
+
+import deform
+import couchdbkit
+
+def new(request):
+ bibitex_form = BibitexForm.get_form()
+
+ if 'submit' in request.POST:
+ controls = request.POST.items()
+ try:
+ appstruct = bibitex_form.validate(controls)
+ except deform.ValidationFailure, e:
+ return render_to_response('bibitex:form.pt',
+ {'content': e.render()})
+
+ bibitex = Bibitex.from_python(appstruct)
+ bibitex.save(db)
+
+ return Response('Saved under id: %s' % bibitex._id)
+ else:
+
+ if 'id' in request.matchdict: #edit
+ bibitex = Bibitex.get(db, request.matchdict['id'])
+
+ return render_to_response('bibitex:form.pt',
+ {'content': bibitex_form.render(bibitex.to_python())})
+
+ return render_to_response('bibitex:form.pt',
+ {'content': bibitex_form.render()})
+
+
+def index(request):
+ records = db.view('_all_docs', include_docs=True)
+
+ return render_to_response('bibitex:index.pt',
+ {'records':records})
+
+
+if __name__ == '__main__':
+ config = Configurator()
+
+ """Configuring couchdb"""
+ server = couchdbkit.Server()
+ db = server.get_or_create_db('bibitex')
+
+ """Adding static views"""
+ config.add_static_view('deform_static', 'deform:static')
+
+ """Registering views and routes"""
+ config.add_view(view=index, route_name='index')
+ config.add_view(view=new, route_name='new')
+ config.add_view(view=new, route_name='edit')
+ config.add_route('index', '/')
+ config.add_route('new', '/new')
+ config.add_route('edit', '/edit/{id}')
+
+ app = config.make_wsgi_app()
+ serve(app, host='0.0.0.0:6543')
View
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" href="/deform_static/css/form.css" type="text/css"></link>
+ <link rel="stylesheet" href="/deform_static/css/theme.css" type="text/css"></link>
+ <script type="text/javascript" src="/deform_static/scripts/jquery-1.4.2.min.js"></script>
+ <script type="text/javascript" src="/deform_static/scripts/deform.js"></script>
+ <script type="text/javascript">
+ deform.load()
+ </script>
+ </head>
+ <body>
+ <div>
+ <h1><a href="http://github.com/bireme/isisdm">ISISDM Sample Application</a></h1>
+ <span tal:replace="structure content"></span>
+ </div>
+ </body>
+</html>
View
@@ -0,0 +1,12 @@
+from models import Bibitex
+
+import deform
+import colander
+
+class BibitexForm():
+
+ base_schema = Bibitex.get_schema()
+ base_schema['review'].widget = deform.widget.TextAreaWidget(cols=80, rows=15)
+ @classmethod
+ def get_form(cls):
+ return deform.Form(cls.base_schema, buttons=('submit',))
View
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" href="/deform_static/css/theme.css" type="text/css"></link>
+ </head>
+ <body>
+ <div>
+ <h1><a href="http://github.com/bireme/isisdm">ISISDM Sample Application</a></h1>
+ <p><a href="/new">add</a></p>
+ <table>
+ <tr>
+ <th>Entry type</th>
+ <th>Reference name</th>
+ <th>Title</th>
+ </tr>
+ <tr tal:repeat="record records">
+ <td tal:content="record.doc.entry_type"></td>
+ <td tal:content="record.doc.reference_name"></td>
+ <td tal:content="record.doc.title"></td>
+ <td><a href="/edit/${record.id}">edit</a></td>
+ </tr>
+ </table>
+ </div>
+ </body>
+</html>
View
@@ -0,0 +1,17 @@
+from isis import model
+import deform
+
+choices = ['article', 'book', 'booklet', 'conference', 'inbook', 'incollection', 'inproceedings',
+ 'manual', 'mastersthesis', 'misc', 'phdthesis', 'proceedings', 'techreport', 'unpublished', ]
+
+class Bibitex(model.CouchdbDocument):
+ entry_type = model.TextProperty(choices=[(entry,entry) for entry in choices],)
+ reference_name = model.TextProperty(required=True)
+ title = model.TextProperty(required=True)
+ authors = model.MultiCompositeTextProperty(required=True, subkeys=['name', 'lastname'])
+ publisher = model.TextProperty()
+ year = model.TextProperty()
+ address = model.TextProperty()
+ review = model.TextProperty()
+
+
View
@@ -1,6 +1,7 @@
# package
from .mapper import Document
from .mapper import TextProperty, MultiTextProperty
-from .mapper import CompositeTextProperty, MultiCompositeTextProperty
+from .mapper import CompositeTextProperty, IsisCompositeTextProperty
+from .mapper import MultiIsisCompositeTextProperty, MultiCompositeTextProperty
from .mapper import ReferenceProperty, FileProperty, BooleanProperty
from .couchdb import CouchdbDocument
View
@@ -19,7 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .ordered import OrderedProperty, OrderedModel
-from .subfield import CompositeString
+from .subfield import CompositeString, CompositeField
import json
import colander
import deform
@@ -169,16 +169,13 @@ class FileProperty(CheckedProperty):
def __set__(self, instance, value):
if not isinstance(value, dict):
raise TypeError('%r must be a dictionary' % self.name)
-
+
if 'filename' not in value:
try:
value['filename'] = value['fp'].name
except AttributeError:
raise TypeError('%r must be a file' % self.name)
-
- if 'fp' in value:
- value['md5'] = hashlib.md5(value['fp'].read()).hexdigest()
-
+
super(FileProperty, self).__set__(instance, value)
def _pystruct(self, instance, value):
@@ -187,8 +184,7 @@ def _pystruct(self, instance, value):
'''
if isinstance(value, dict):
serializable_value = {'uid':value['uid'],
- 'filename':value['filename'],
- 'md5':value['md5'],}
+ 'filename':value['filename'],}
return serializable_value
return value
@@ -230,18 +226,18 @@ def _colander_schema(self, instance, value):
return schema
-class CompositeTextProperty(CheckedProperty):
+class IsisCompositeTextProperty(CheckedProperty):
def __init__(self, subkeys=None, **kwargs):
- super(CompositeTextProperty, self).__init__(**kwargs)
+ super(IsisCompositeTextProperty, self).__init__(**kwargs)
self.subkeys = subkeys
def __set__(self, instance, value):
if not isinstance(value, basestring):
raise TypeError('%r value must be unicode or str instance' % self.name)
composite_text = CompositeString(value, self.subkeys)
- super(CompositeTextProperty, self).__set__(instance, composite_text)
+ super(IsisCompositeTextProperty, self).__set__(instance, composite_text)
def _pystruct(self, instance, value):
'''
@@ -258,18 +254,57 @@ def _colander_schema(self, instance, value):
subfield,
name=self.name)
-class MultiCompositeTextProperty(CheckedProperty):
+class CompositeTextProperty(CheckedProperty):
+
+ def __init__(self, subkeys, **kwargs):
+ super(CompositeTextProperty, self).__init__(**kwargs)
+ if not isinstance(subkeys,tuple) and not isinstance(subkeys, list):
+ raise TypeError('subkeys argument must be tuple or list')
+ self.subkeys = subkeys
+
+ def __set__(self, instance, value):
+ try:
+ value_as_dict = dict(value)
+ except ValueError:
+ raise TypeError('%r value must be a key-value structure' % self.name)
+
+ try:
+ value = CompositeField(value_as_dict, self.subkeys)
+ except TypeError:
+ raise TypeError('%r got an unexpected keyword' % self.name)
+
+ super(CompositeTextProperty, self).__set__(instance, value)
+
+ def _pystruct(self, instance, value):
+ '''
+ python representation for this property
+ '''
+ return value.items()
+
+ def _colander_schema(self, instance, value):
+ #option arg acts in each attribute
+ kwargs = {}
+ if not self.required:
+ kwargs.update({'missing':None})
+
+ subfield = colander.SchemaNode(colander.Mapping(), name=self.name)
+ for subkey in self.subkeys:
+ subfield.add(colander.SchemaNode(colander.String(), name=subkey, **kwargs))
+
+ return subfield
+
+class MultiIsisCompositeTextProperty(CheckedProperty):
def __init__(self, subkeys=None, **kwargs):
- super(MultiCompositeTextProperty, self).__init__(**kwargs)
+ super(MultiIsisCompositeTextProperty, self).__init__(**kwargs)
self.subkeys = subkeys
def __set__(self, instance, value):
if not isinstance(value, tuple):
- raise TypeError('MultiCompositeText value must be tuple')
+ raise TypeError('MultiIsisCompositeText value must be tuple')
composite_texts = tuple(CompositeString(raw_composite_text, self.subkeys) for raw_composite_text in value)
- super(MultiCompositeTextProperty, self).__set__(instance, composite_texts)
+ super(MultiIsisCompositeTextProperty, self).__set__(instance, composite_texts)
def _pystruct(self, instance, value):
'''
@@ -286,6 +321,46 @@ def _colander_schema(self, instance, value):
schema,
name=self.name)
+class MultiCompositeTextProperty(CheckedProperty):
+
+ def __init__(self, subkeys, **kwargs):
+ super(MultiCompositeTextProperty, self).__init__(**kwargs)
+ if not isinstance(subkeys,tuple) and not isinstance(subkeys, list):
+ raise TypeError('subkeys argument must be tuple or list')
+ self.subkeys = subkeys
+
+ def __set__(self, instance, value):
+ if not isinstance(value, tuple) and not isinstance(value, list):
+ raise TypeError('%r value must be tuple or list')
+
+ try:
+ composite_texts = tuple(CompositeField(dict(composite_text), self.subkeys) for composite_text in value)
+ except ValueError:
+ raise TypeError('%r value must be a list or tuple of key-value structures' % self.name)
+
+ super(MultiCompositeTextProperty, self).__set__(instance, composite_texts)
+
+ def _pystruct(self, instance, value):
+ '''
+ python representation for this property
+ '''
+ return tuple(composite_text.items() for composite_text in value)
+
+ def _colander_schema(self, instance, value):
+ schema = colander.SchemaNode(colander.Mapping(), name=self.name)
+
+ kwargs = {}
+ if not self.required:
+ kwargs.update({'missing':None})
+
+ for subkey in self.subkeys:
+ schema.add(colander.SchemaNode(colander.String(), name=subkey, **kwargs))
+
+ return colander.SchemaNode(colander.Sequence(),
+ schema,
+ name=self.name,
+ **kwargs)
+
class ReferenceProperty(CheckedProperty):
def __set__(self, instance, value):
Oops, something went wrong.

0 comments on commit 2e4152e

Please sign in to comment.