def save(self, *args, **kwargs): try: if not self.created_by: self.created_by = current_user.get_id() self.modified_by = current_user.get_id() except: pass self.modified = datetime.now() Document.save(self, **kwargs)
def transform(cls, data: OrderedDict, model: Model) -> OrderedDict: id = query_dict("metadata.identification", data=data) existing = model.objects(_id=str(id)).first() or model() if not hasattr(existing, "hashes"): existing.hashes = {} data = super().transform(data, model) data = cls.copy_header_to_root(data) data = cls.copy_content_to_root(data) data = cls.copy_operator_to_root(data) data = cls.add_survey_hash(data) data = cls.add_location_hash(data) data = cls.create_geometries(data, existing) return data
def pre_save(cls, sender: Type, document: Document, **kwargs: Dict) -> Document: """ A signal handler which will put a new member into a default group if any hasn't been assigned yet. :param sender: Type of signal emitter. :type sender: Type :param document: New instance of User model. :type document: User :param kwargs: Additional parameters :type kwargs: Dict :return: Modified User instance. :rtype: User """ if all(map(lambda x: x.id != 'default', document.groups)): try: document.groups = [Group.objects.get(id='default')] except Group.DoesNotExist: raise Group.DoesNotExist('Please run \'manage.py init ...\'') return document
def dropall(): "Drops all database tables" if prompt_bool("Are you sure ? You will lose all your data !"): db.connection.drop_database(Document._get_db())
def update(self, *args, **kwargs): self.modified = datetime.now() self.modified_by = current_user.get_id() return Document.update(self, *args, **kwargs)
def delete(self, *args, **kwargs): # we can custom the delete # example: set the status to 0 instead of physical delete return Document.delete(self, *args, **kwargs)