Giter Club home page Giter Club logo

humongolus's Introduction

Persistence and Widget Framework for Python and MongoDB

Google Group: http://groups.google.com/group/humongolus

Features

  • Type Validation
  • Lazy Relationships
  • Full MongoDB Index Support
  • Dirty Updating (only send changes to db)
  • Full Test Suite (97% code coverage)
  • Documentation
  • Exposes default MongoDB cursors
  • Robust Widget System
  • Default HTML Widgets
    • Text
    • Password
    • Checkbox
    • Select
    • MultiSelect
    • TextArea
    • FieldSet
    • Form
  • List validation (len and multiple types)
  • Attribute aliases
  • Dynamic Field Validation
  • Large Collection of Default Field Types
    • Char
    • Integer
    • Float
    • Date
    • TimeStamp
    • DocumentID (pseudo DBRef)
    • AutoIncrement
    • DynamicDocument (pseudo DBRef)
    • Boolean
    • Regex
    • Geo
    • Email
    • Phone
    • Choice Fields (Model, Collection and List)
    • File
  • Endless EmbeddedDocuments
  • Default Created/Modified attributes
  • Easily integrates with Backbone.js or other client side frameworks
  • TODO
    • Tutorials
    • Plugins

Usage also see test.py and tests/test_field.py for more usage examples.

from pymongo.mongo_client import MongoClient
import logging
import humongolus as orm
import datetime
import humongolus.field as field

conn = MongoClient()
FORMAT = '%(asctime)-15s %(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger("humongolus")

orm.settings(logger=logger, db_connection=conn)

class Location(orm.EmbeddedDocument):
  city = field.Char(required=True)
  state = field.Char()

class Job(orm.EmbeddedDocument):
  employer = field.Char()
  title = field.Char(required=True)
  locations = orm.List(type=Location)

class Human(orm.Document):
  _db = "test"
  _collection = "humans"
  human_id = field.AutoIncrement(collection="human")
  name = field.Char(required=True, min=2, max=25)
  age = field.Integer(min=0, max=3000)
  height = field.Float(min=1, max=100000)
  weight = field.Float(min=1, max=30000)
  jobs = orm.List(type=Job)
  genitalia = field.Char()

class Female(Human):
  genitalia = field.Char(default='inny')

class Male(Human):
  genitalia = field.Char(default='outy')

class Car(orm.Document):
  _db = "test"
  _collection = "cars"
  owner = field.DynamicDocument()
  make = field.Char()
  model = field.Char()
  year = field.Date()
  silly_date = field.TimeStamp()    

Human.cars = orm.Lazy(type=Car, key='owner._id')

chris = Male()
chris.name = "Chris"
chris.age = 31
chris.height = 100
chris.weight = 180

job = Job()
job.employer = "Entropealabs"
job.title = "President"

loc = Location()
loc.city = "Chicago"
loc.state = "IL"

job.locations.append(loc)
chris.jobs.append(job)

print chris._json()
  {'jobs': [
      {
          'employer': u'Entropealabs', 
          'locations': [
              {'city': u'Chicago', 'state': u'IL'}
          ], 
          'title': u'President'}
      ], 
      'name': u'Chris', 
      'weight': 180.0, 
      'age': 31, 
      'height': 100.0, 
      'genitalia': u'outy', 
      'human_id': 1328
  }

_id = chris.save()

print _id

  4f36dd48eac0742b92000000

for person in Human.find().sort({"name":-1}):
  print person.name
  print person.created
  print person.modifed
  for job in person.jobs:
      print job.title
      for loc in job.locations:
          print loc.city

car = Car()
car.owner = chris
car.make = "Isuzu"
car.model = "Rodeo"
car.year = datetime.datetime(1998, 1, 1)

print car
  <__main__.Car object at 0x7fe3c9375650>

c_id = car.save()

print car._get("owner")().name
  Chris

humongolus's People

Contributors

198d avatar aaiyer avatar elpargo avatar emidln avatar entone avatar orisano avatar uniphil avatar warchiefx avatar xkmato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

humongolus's Issues

Class attributes are not accessible

On calling orm.Document.attribute
263
264 def get(self, instance, owner):
--> 265 me = instance.dict.get(self._name)
266 if me:
267 if callable(me): return me()

AttributeError: 'NoneType' object has no attribute 'dict'

Alternate loading strategy of DocumentId & friends

It would be extremely handy to offer alternative options to eagerly loading DocumentId fields and throwing exceptions when the document doesn't exist. Potential variations:

Eagerly load but return None (or empty dict) when the document doesn't exist
Lazily load and return None (or empty dict) when the document doesn't exist

Unable to save object when using pymongo 3.0+

Running pymongo 3.7.1 and found that I'm unable to save an object since the safe parameter has been removed from .insert(). Also insert() is deprecated.

Error occurs here - https://github.com/entone/Humongolus/blob/master/humongolus/__init__.py#L800

MongoDB Collection docs
http://api.mongodb.com/python/current/api/pymongo/collection.html

insert(doc_or_docs, manipulate=True, check_keys=True, continue_on_error=False, **kwargs)ΒΆ
Insert a document(s) into this collection.

DEPRECATED - Use insert_one() or insert_many() instead.

Changed in version 3.0: Removed the safe parameter. Pass w=0 for unacknowledged write operations.

Improve documentation

Documentation for the DynamicDocument and DocumentId is weak to non-existent. Please provide more detailed examples for these and information on when each should be used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.