Use list comprehension instead of class methods.

This commit is contained in:
Patrick Jentsch 2019-11-12 12:03:46 +01:00
parent 5602ba950f
commit 19f1dea4fa
2 changed files with 4 additions and 16 deletions

View File

@ -73,16 +73,16 @@ def user_ressource_subscription_handler(app, user_id, session_id,
with app.app_context():
# Gather current values from database.
user = User.query.filter_by(id=user_id).first()
corpora = user.corpora_as_dict()
jobs = user.jobs_as_dict()
corpora = {corpus.id: corpus.to_dict() for corpus in user.corpora}
jobs = {job.id: job.to_dict() for job in user.jobs}
# Send initial values to the user.
socketio.emit(init_events['corpora'], json.dumps(corpora),
room=session_id)
socketio.emit(init_events['jobs'], json.dumps(jobs), room=session_id)
while session_id in connected_sessions:
# Get new values from the database
new_corpora = user.corpora_as_dict()
new_jobs = user.jobs_as_dict()
new_corpora = {corpus.id: corpus.to_dict() for corpus in user.corpora}
new_jobs = {job.id: job.to_dict() for job in user.jobs}
# Compute JSON patches.
corpora_patch = jsonpatch.JsonPatch.from_diff(corpora, new_corpora)
jobs_patch = jsonpatch.JsonPatch.from_diff(jobs, new_jobs)

View File

@ -208,18 +208,6 @@ class User(UserMixin, db.Model):
"""
return self.can(Permission.ADMIN)
def corpora_as_dict(self):
corpora = {}
for corpus in self.corpora:
corpora[str(corpus.id)] = corpus.to_dict()
return corpora
def jobs_as_dict(self):
jobs = {}
for job in self.jobs:
jobs[str(job.id)] = job.to_dict()
return jobs
def delete_user(self):
"""
Delete user from database. Also delete all associated jobs and corpora