Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
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())
Esempio n. 6
0
 def update(self, *args, **kwargs):
     self.modified = datetime.now()
     self.modified_by = current_user.get_id()
     return Document.update(self, *args, **kwargs)
Esempio n. 7
0
 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)
Esempio n. 8
0
 def update(self, *args, **kwargs):
     self.modified = datetime.now()
     self.modified_by = current_user.get_id()
     return Document.update(self, *args, **kwargs)
Esempio n. 9
0
 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)