From 4a5804460fe38037c41a00b6ffa8d24e0efb1199 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Fri, 16 Aug 2019 09:49:27 +0200 Subject: [PATCH] Add admin functions to api. Add to_jsonifyable method to Job and Corpus and use it in API. --- app/models.py | 21 +++++ app/templates/main/dashboard.html.j2 | 129 ++++++++++++++++++++------- 2 files changed, 120 insertions(+), 30 deletions(-) diff --git a/app/models.py b/app/models.py index c3a09668..d5284554 100644 --- a/app/models.py +++ b/app/models.py @@ -247,6 +247,21 @@ class Job(db.Model): """ return '' % self.title + def to_jsonifyable(self): + return {'id': self.id, + 'creation_date': self.creation_date.timestamp(), + 'description': self.description, + 'end_date': (self.end_date.timestamp() if self.end_date else + None), + 'mem_mb': self.mem_mb, + 'n_cores': self.n_cores, + 'service': self.service, + 'service_args': self.service_args, + 'service_version': self.service_version, + 'status': self.status, + 'title': self.title, + 'user_id': self.user_id} + class Corpus(db.Model): """ @@ -269,6 +284,12 @@ class Corpus(db.Model): """ return '' % self.title + def to_jsonifyable(self): + return {'id': self.id, + 'creation_date': self.creation_date, + 'description': self.description, + 'title': self.title, + 'user_id': self.user_id} ''' ' Flask-Login is told to use the application’s custom anonymous user by setting diff --git a/app/templates/main/dashboard.html.j2 b/app/templates/main/dashboard.html.j2 index c8a02c07..ac063dae 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -76,45 +76,114 @@ -
- {% for job in current_user.jobs.all() %} - {% if job.service == 'nlp' %} - {% set service_color = 'blue' %} - {% set service_icon = 'format_textdirection_l_to_r' %} - {% elif job.service =='ocr' %} - {% set service_color = 'green' %} - {% set service_icon = 'find_in_page' %} - {% else %} - {% set service_color = 'red' %} - {% set service_icon = 'help' %} - {% endif %} - {% if job.status == 'pending' %} - {% set badge_color = 'amber' %} - {% elif job.status =='running' %} - {% set badge_color = 'indigo' %} - {% elif job.status =='complete' %} - {% set badge_color = 'teal' %} - {% else %} - {% set badge_color = 'red' %} - {% endif %} - - {{ service_icon }} - {{ job.status }} - {{ job.title }} -

{{ job.description }}

-
- {% endfor %} -
+
+ +