This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
global: admin interface improvements
Signed-off-by: Lars Holm Nielsen <[email protected]>
- Loading branch information
Showing
6 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
invenio/modules/accounts/templates/accounts/admin/details.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends 'admin/model/details.html' %} | ||
{% import 'admin/lib.html' as lib with context %} | ||
|
||
{% block navlinks %} | ||
{{super()}} | ||
{%- set user_id = get_value(model, 'id') %} | ||
{%- set user_email = get_value(model, 'email') %} | ||
<ul class="nav nav-pills nav-justified"> | ||
<li><a href="{{url_for('userext.index_view', flt3_16=user_email )}}">View identities</a></li> | ||
<li><a href="{{url_for('search.search', p='8560_w:%s' % user_id)}}">View records</a></li> | ||
<li><a href="{{url_for('bibworkflowobject.index_view', flt3_2=user_email)}}">View deposits</a></li> | ||
<li><a href="{{url_for('resourceusage.index_view', flt0_2='User', flt3_9=user_id)}}">View metrics</a></li> | ||
<li><a href="{{url_for('Communities.index_view', flt2_9=user_email)}}">View communities</a></li> | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2015 CERN. | ||
# | ||
# Invenio is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Invenio; if not, write to the Free Software Foundation, Inc., | ||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
"""Flask-Admin page to configure users and accounts.""" | ||
|
||
from __future__ import absolute_import | ||
from markupsafe import Markup | ||
|
||
from flask import flash, render_template | ||
from flask_admin.actions import action | ||
from flask_admin.form.fields import DateTimeField | ||
from flask_admin.model.form import InlineFormAdmin | ||
|
||
from invenio.ext.admin.views import ModelView | ||
from invenio.ext.sqlalchemy import db | ||
|
||
from invenio.ext.login import login_user, logout_user | ||
|
||
from invenio.modules.workflows.models import BibWorkflowObject, Workflow, ObjectVersion | ||
from invenio.modules.workflows.engine import WorkflowStatus | ||
|
||
|
||
from .models import Deposition | ||
|
||
class AccMixin(object): | ||
|
||
"""Configure access rights.""" | ||
|
||
_can_create = False | ||
_can_edit = False | ||
_can_delete = False | ||
|
||
acc_view_action = 'cfgwebaccess' | ||
acc_edit_action = 'cfgwebaccess' | ||
acc_delete_action = 'cfgwebaccess' | ||
|
||
|
||
def name_from_workflowstatus(s): | ||
if s == WorkflowStatus.NEW: | ||
return "NEW" | ||
elif s == WorkflowStatus.RUNNING: | ||
return "RUNNING" | ||
elif s == WorkflowStatus.HALTED: | ||
return "HALTED" | ||
elif s == WorkflowStatus.ERROR: | ||
return "ERROR" | ||
elif s == WorkflowStatus.COMPLETED: | ||
return "COMPLETED" | ||
|
||
|
||
def format_deposition(v, c, m, n): | ||
"""Format data for a deposition.""" | ||
return Markup(render_template( | ||
"deposit/admin/deposition_data.html", obj=Deposition(m))) | ||
|
||
|
||
class DepositAdmin(ModelView, AccMixin): | ||
|
||
"""Flask-Admin view to manage users.""" | ||
|
||
can_view_details = True | ||
|
||
column_list = ( | ||
'id', 'user', 'id_workflow', 'version', 'workflow.status', 'created', | ||
'modified', | ||
) | ||
|
||
column_details_list = ( | ||
'id', | ||
'user', | ||
'version', | ||
'workflow.status', | ||
'created', | ||
'modified', | ||
'_data', | ||
'child_logs', | ||
) | ||
|
||
column_names = { | ||
'_data': 'Data', | ||
} | ||
|
||
column_filters = ( | ||
'user.email', | ||
'user.nickname', | ||
'created', | ||
'modified', | ||
) | ||
|
||
column_formatters = { | ||
'version': lambda v, c, m, n: ObjectVersion.name_from_version( | ||
getattr(m, n)), | ||
'workflow.status': lambda v, c, m, n: name_from_workflowstatus( | ||
m.workflow.status), | ||
'_data': format_deposition | ||
} | ||
|
||
def get_query(self): | ||
params = [ | ||
Workflow.module_name == 'webdeposit', | ||
BibWorkflowObject.id_user != 0 | ||
] | ||
|
||
return BibWorkflowObject.query.join("workflow").options( | ||
db.contains_eager('workflow')).filter(*params) | ||
|
||
|
||
def register_admin(app, admin): | ||
"""Call on app initialization to register administration interface.""" | ||
category = "Deposits" | ||
admin.add_view(DepositAdmin( | ||
BibWorkflowObject, db.session, name="Deposits", category=category | ||
)) |
32 changes: 32 additions & 0 deletions
32
invenio/modules/deposit/templates/deposit/admin/deposition_data.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<p> | ||
<strong>{{obj.title}}</strong> | ||
{% if obj.get_latest_sip() %} | ||
{% set sip = obj.get_latest_sip() %} | ||
<a href="{{ url_for('record.metadata', recid=sip.metadata['recid'])}}">View record</a>{% endif %} | ||
</p> | ||
<p> | ||
<strong>Draft:</strong><br/> | ||
{% for v in obj.drafts.values() %} | ||
<pre>{{v.values}}</pre> | ||
{% endfor %} | ||
</p> | ||
<p> | ||
<strong>Submission Information Packages:</strong><br/> | ||
{% for s in obj.sips %} | ||
|
||
<i>{{s.uuid}} ({{s.timestamp}}):</i><br> | ||
<small class="text-muted">Agents: {% for a in s.agents %}{{a.user_id}} <{{a.email_address}}> ({{a.ip_address}}),{% endfor%}</small> | ||
<pre>{% for k in s.metadata.keys()|sort if not k.startswith('_') %}{{k}}: {{s.metadata[k]}} | ||
{% endfor %} | ||
</pre> | ||
<pre>{{s.package}}</pre> | ||
|
||
{% endfor %} | ||
</p> | ||
<p> | ||
<strong>Files:</strong><br/> | ||
{% for f in obj.files %} | ||
{{f.name}} ({{f.size|filesizeformat}}) <small class="text-muted">Checksum: {{f.checksum}}, Path: {{f.path}}</small><br/> | ||
{% endfor %} | ||
|
||
<p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters