def __init__(self, json): """ takes in a json string Creates a new object """ Document.__init__(self) self.from_json(json) self.validate()
def save(self, uuid=False, validate=None, safe=True, *args, **kwargs): # before save if not self['key']: self['key'] = self.generate_key() # save Document.save(self, uuid, validate, safe, *args, **kwargs)
def save(self, uuid=False, validate=None, safe=True, *args, **kwargs): Document.save(self, uuid, validate, safe, *args, **kwargs) owner_id = self['owner'] if self['group']: group = connection.Group.find_one({'_id': owner_id}) group['grades'].add(self['_id']) group.save() student_ids = group['members'] for _id in student_ids: self.add_grade_to_student(_id) else: self.add_grade_to_student(owner_id)
def __getitem__(self, key): try: return Document.__getitem__(self, key) except KeyError: ans = self.default_values[key] if callable(ans): ans = ans() self[key] = ans self.save() return ans
def __init__(self, *args, **kwargs): # Document needs a lot of parameters Document.__init__(self, *args, **kwargs) self.authenticated = False
def __init__(self, *args, **kwargs): # Document needs a lot of parameters Document.__init__(self, *args, **kwargs) # store the elo per player (before, after) self.elos_per_player = {}
def __setattr__(self, field, value): if field in self.keys(): if isinstance(value, basestring): value = unicode(value) self[field] = value Document.__setattr__(self, field, value)
def __getattr__(self, field): if field in self.keys(): return self[field] return Document.__getattr__(self, field)
def save(self, uuid=False, validate=None, safe=True, *args, **kwargs): self.before_save() Document.save(self, uuid, validate, safe, *args, **kwargs)
def __init__(self, *args, **kwargs): # Document needs a lot of parameters Document.__init__(self, *args, **kwargs)