mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-10-31 02:32:45 +00:00 
			
		
		
		
	cleanup in models file
This commit is contained in:
		| @@ -205,6 +205,8 @@ class Role(HashidMixin, db.Model): | |||||||
|                 if self.has_permission(x.value) |                 if self.has_permission(x.value) | ||||||
|             ] |             ] | ||||||
|         } |         } | ||||||
|  |         if backrefs: | ||||||
|  |             pass | ||||||
|         if relationships: |         if relationships: | ||||||
|             json_serializeable['users'] = { |             json_serializeable['users'] = { | ||||||
|                 x.hashid: x.to_json_serializeable(relationships=True) |                 x.hashid: x.to_json_serializeable(relationships=True) | ||||||
| @@ -256,6 +258,27 @@ class Token(db.Model): | |||||||
|         self.access_expiration = datetime.utcnow() |         self.access_expiration = datetime.utcnow() | ||||||
|         self.refresh_expiration = datetime.utcnow() |         self.refresh_expiration = datetime.utcnow() | ||||||
|  |  | ||||||
|  |     def to_json_serializeable(self, backrefs=False, relationships=False): | ||||||
|  |         json_serializeable = { | ||||||
|  |             'id': self.hashid, | ||||||
|  |             'access_token': self.access_token, | ||||||
|  |             'access_expiration': ( | ||||||
|  |                 None if self.access_expiration is None | ||||||
|  |                 else f'{self.access_expiration.isoformat()}Z' | ||||||
|  |             ), | ||||||
|  |             'refresh_token': self.refresh_token, | ||||||
|  |             'refresh_expiration': ( | ||||||
|  |                 None if self.refresh_expiration is None | ||||||
|  |                 else f'{self.refresh_expiration.isoformat()}Z' | ||||||
|  |             ) | ||||||
|  |         } | ||||||
|  |         if backrefs: | ||||||
|  |             json_serializeable['user'] = \ | ||||||
|  |                 self.user.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|  |         return json_serializeable | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def clean(): |     def clean(): | ||||||
|         """Remove any tokens that have been expired for more than a day.""" |         """Remove any tokens that have been expired for more than a day.""" | ||||||
| @@ -288,6 +311,11 @@ class Avatar(HashidMixin, FileMixin, db.Model): | |||||||
|             'id': self.hashid, |             'id': self.hashid, | ||||||
|             **self.file_mixin_to_json_serializeable() |             **self.file_mixin_to_json_serializeable() | ||||||
|         } |         } | ||||||
|  |         if backrefs: | ||||||
|  |             json_serializeable['user'] = \ | ||||||
|  |                 self.user.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -328,6 +356,13 @@ class CorpusFollowerAssociation(HashidMixin, db.Model): | |||||||
|             'corpus': self.corpus.to_json_serializeable(), |             'corpus': self.corpus.to_json_serializeable(), | ||||||
|             'follower': self.follower.to_json_serializeable() |             'follower': self.follower.to_json_serializeable() | ||||||
|         } |         } | ||||||
|  |         if backrefs: | ||||||
|  |             json_serializeable['corpus'] = \ | ||||||
|  |                 self.corpus.to_json_serializeable(backrefs=True) | ||||||
|  |             json_serializeable['follower'] = \ | ||||||
|  |                 self.follower.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -620,7 +655,6 @@ class User(HashidMixin, UserMixin, db.Model): | |||||||
|     def is_following_corpus(self, corpus): |     def is_following_corpus(self, corpus): | ||||||
|         return corpus in self.followed_corpora |         return corpus in self.followed_corpora | ||||||
|  |  | ||||||
|  |  | ||||||
|     def to_json_serializeable(self, backrefs=False, relationships=False, filter_by_privacy_settings=False): |     def to_json_serializeable(self, backrefs=False, relationships=False, filter_by_privacy_settings=False): | ||||||
|         json_serializeable = { |         json_serializeable = { | ||||||
|             'id': self.hashid, |             'id': self.hashid, | ||||||
| @@ -628,9 +662,9 @@ class User(HashidMixin, UserMixin, db.Model): | |||||||
|             'email': self.email, |             'email': self.email, | ||||||
|             'last_seen': ( |             'last_seen': ( | ||||||
|                 None if self.last_seen is None |                 None if self.last_seen is None | ||||||
|                 else self.last_seen.strftime('%Y-%m-%d %H:%M') |                 else f'{self.last_seen.isoformat()}Z' | ||||||
|             ), |             ), | ||||||
|             'member_since': self.member_since.strftime('%Y-%m-%d'), |             'member_since': f'{self.member_since.isoformat()}Z', | ||||||
|             'username': self.username, |             'username': self.username, | ||||||
|             'full_name': self.full_name, |             'full_name': self.full_name, | ||||||
|             'about_me': self.about_me, |             'about_me': self.about_me, | ||||||
| @@ -804,6 +838,8 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model): | |||||||
|         if backrefs: |         if backrefs: | ||||||
|             json_serializeable['user'] = \ |             json_serializeable['user'] = \ | ||||||
|                 self.user.to_json_serializeable(backrefs=True) |                 self.user.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -930,7 +966,10 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model): | |||||||
|             **self.file_mixin_to_json_serializeable() |             **self.file_mixin_to_json_serializeable() | ||||||
|         } |         } | ||||||
|         if backrefs: |         if backrefs: | ||||||
|             json_serializeable['user'] = self.user.to_json_serializeable(backrefs=True) |             json_serializeable['user'] = \ | ||||||
|  |                 self.user.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -989,6 +1028,8 @@ class JobInput(FileMixin, HashidMixin, db.Model): | |||||||
|         if backrefs: |         if backrefs: | ||||||
|             json_serializeable['job'] = \ |             json_serializeable['job'] = \ | ||||||
|                 self.job.to_json_serializeable(backrefs=True) |                 self.job.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -1053,6 +1094,8 @@ class JobResult(FileMixin, HashidMixin, db.Model): | |||||||
|         if backrefs: |         if backrefs: | ||||||
|             json_serializeable['job'] = \ |             json_serializeable['job'] = \ | ||||||
|                 self.job.to_json_serializeable(backrefs=True) |                 self.job.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -1132,7 +1175,6 @@ class Job(HashidMixin, db.Model): | |||||||
|             raise e |             raise e | ||||||
|         return job |         return job | ||||||
|  |  | ||||||
|  |  | ||||||
|     def delete(self): |     def delete(self): | ||||||
|         ''' Delete the job and its inputs and results from the database. ''' |         ''' Delete the job and its inputs and results from the database. ''' | ||||||
|         if self.status not in [JobStatus.COMPLETED, JobStatus.FAILED]:  # noqa |         if self.status not in [JobStatus.COMPLETED, JobStatus.FAILED]:  # noqa | ||||||
| @@ -1177,8 +1219,7 @@ class Job(HashidMixin, db.Model): | |||||||
|             'service_args': self.service_args, |             'service_args': self.service_args, | ||||||
|             'service_version': self.service_version, |             'service_version': self.service_version, | ||||||
|             'status': self.status.name, |             'status': self.status.name, | ||||||
|             'title': self.title, |             'title': self.title | ||||||
|             'url': self.url |  | ||||||
|         } |         } | ||||||
|         if backrefs: |         if backrefs: | ||||||
|             json_serializeable['user'] = \ |             json_serializeable['user'] = \ | ||||||
| @@ -1264,9 +1305,9 @@ class CorpusFile(FileMixin, HashidMixin, db.Model): | |||||||
|     def to_json_serializeable(self, backrefs=False, relationships=False): |     def to_json_serializeable(self, backrefs=False, relationships=False): | ||||||
|         json_serializeable = { |         json_serializeable = { | ||||||
|             'id': self.hashid, |             'id': self.hashid, | ||||||
|             'url': self.url, |  | ||||||
|             'address': self.address, |             'address': self.address, | ||||||
|             'author': self.author, |             'author': self.author, | ||||||
|  |             'description': self.description, | ||||||
|             'booktitle': self.booktitle, |             'booktitle': self.booktitle, | ||||||
|             'chapter': self.chapter, |             'chapter': self.chapter, | ||||||
|             'editor': self.editor, |             'editor': self.editor, | ||||||
| @@ -1285,6 +1326,8 @@ class CorpusFile(FileMixin, HashidMixin, db.Model): | |||||||
|         if backrefs: |         if backrefs: | ||||||
|             json_serializeable['corpus'] = \ |             json_serializeable['corpus'] = \ | ||||||
|                 self.corpus.to_json_serializeable(backrefs=True) |                 self.corpus.to_json_serializeable(backrefs=True) | ||||||
|  |         if relationships: | ||||||
|  |             pass | ||||||
|         return json_serializeable |         return json_serializeable | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user