def save_version_manager(self): """Custom save. Returns: Saved Instance. """ try: return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError(str(e)) except Exception as ex: raise exceptions.ModelError(str(ex))
def save_object(self): """ Custom save. Returns: Saved Instance. """ try: return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError(e.message) except Exception as ex: raise exceptions.ModelError(ex.message)
def _create_perm(name, content_type, codename): """ Create permission. Args: name content_type codename Returns: """ try: perm, created = Permission.objects.get_or_create( name=name, content_type=content_type, codename=codename) except IntegrityError: raise exceptions.NotUniqueError("The permission already exists.") except Exception as ie: raise exceptions.ModelError("Problem while creating the permission.") if not created: raise exceptions.NotUniqueError("The permission already exists.") return perm
def save_object(self): """Custom save Returns: """ try: return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError( "The name is already used by an other exporter.") except Exception as ex: raise exceptions.ModelError(str(ex))
def save_object(self): """ Custom save. Returns: """ try: self.check_instance_name() return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError( "Unable to create the new repository: Not Unique") except Exception as ex: raise exceptions.ModelError(ex.message)
def save_object(self): """Custom save. Set the datetime fields and save. Returns: """ try: # initialize times now = datetime_now() # update change date every time the data is updated self.last_change_date = now if not self.id: # initialize when first created self.creation_date = now # initialize when first saved, then only updates when content is updated self.last_modification_date = now return self.save() except mongoengine_errors.NotUniqueError as e: raise exceptions.NotUniqueError(e) except Exception as ex: raise exceptions.ModelError(ex)
name content_type codename Returns: """ try: perm, created = Permission.objects.get_or_create(name=name, content_type=content_type, codename=codename) except IntegrityError: raise exceptions.NotUniqueError("The permission already exists.") except Exception, ie: raise exceptions.ModelError("Problem while creating the permission.") if not created: raise exceptions.NotUniqueError("The permission already exists.") return perm def add_permission_to_user(user, permission): """ Add permission to user. Args: user_id permission Returns: """ user.user_permissions.add(permission) user.save()