Package couchdbkit :: Package ext :: Package django :: Module schema
[hide private]
[frames] | no frames]

Source Code for Module couchdbkit.ext.django.schema

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (c) 2008-2009 Benoit Chesneau <benoitc@e-engura.com>  
 4  # 
 5  # Permission to use, copy, modify, and distribute this software for any 
 6  # purpose with or without fee is hereby granted, provided that the above 
 7  # copyright notice and this permission notice appear in all copies. 
 8  # 
 9  # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 
10  # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
11  # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
12  # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
13  # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
14  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
15  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
16   
17  """ Wrapper of couchdbkit Document and Properties for django. It also  
18  add possibility to a document to register itself in CouchdbkitHandler 
19  """ 
20   
21  import sys 
22   
23  from couchdbkit import schema 
24  from couchdbkit.ext.django.loading import get_schema, register_schema 
25   
26  __all__ = ['Property', 'StringProperty', 'IntegerProperty',  
27              'DecimalProperty', 'BooleanProperty', 'FloatProperty',  
28              'DateTimeProperty', 'DateProperty', 'TimeProperty',  
29              'dict_to_json', 'list_to_json', 'value_to_json',  
30              'value_to_python', 'dict_to_python', 'list_to_python',  
31              'convert_property', 'DocumentSchema', 'Document',  
32              'SchemaProperty', 'ListProperty',  
33              'DictProperty', 'StringListProperty'] 
34   
35 -class DocumentMeta(schema.SchemaProperties):
36 - def __new__(cls, name, bases, attrs):
37 super_new = super(DocumentMeta, cls).__new__ 38 parents = [b for b in bases if isinstance(b, DocumentMeta)] 39 if not parents: 40 return super_new(cls, name, bases, attrs) 41 42 new_class = super_new(cls, name, bases, attrs) 43 document_module = sys.modules[new_class.__module__] 44 app_label = document_module.__name__.split('.')[-2] 45 register_schema(app_label, new_class) 46 47 return get_schema(app_label, name)
48
49 -class Document(schema.Document):
50 """ Document object for django extension """ 51 __metaclass__ = DocumentMeta 52 53 get_id = property(lambda self: self['_id']) 54 get_rev = property(lambda self: self['_rev'])
55 56 57 DocumentSchema = schema.DocumentSchema 58 59 # properties 60 Property = schema.Property 61 StringProperty = schema.StringProperty 62 IntegerProperty = schema.IntegerProperty 63 DecimalProperty = schema.DecimalProperty 64 BooleanProperty = schema.BooleanProperty 65 FloatProperty = schema.FloatProperty 66 DateTimeProperty = schema.DateTimeProperty 67 DateProperty = schema.DateProperty 68 TimeProperty = schema.TimeProperty 69 SchemaProperty = schema.SchemaProperty 70 ListProperty = schema.ListProperty 71 DictProperty = schema.DictProperty 72 StringListProperty = schema.StringListProperty 73 74 75 # some utilities 76 dict_to_json = schema.dict_to_json 77 list_to_json = schema.list_to_json 78 value_to_json = schema.value_to_json 79 value_to_python = schema.value_to_python 80 dict_to_python = schema.dict_to_python 81 list_to_python = schema.list_to_python 82 convert_property = schema.convert_property 83