Skip to content

Commit

Permalink
Display additional infos about public files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed May 29, 2024
1 parent b74e9a6 commit 23f520b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
10 changes: 8 additions & 2 deletions openatlas/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ class FileDisplay(BaseDisplay):

def add_data(self) -> None:
super().add_data()
self.data[_('public sharing allowed')] = str(_('yes')) \
if self.entity.public else str(_('no'))
self.data[_('public sharing allowed')] = str(_('no'))
if self.entity.public:
self.data[_('public sharing allowed')] = str(_('yes'))
if not self.entity.standard_type:
self.data[_('public sharing allowed')] = str(_('yes')) + (
' <span class="error">' + _('but license is missing ') +
'</span>')

self.data[_('creator')] = self.entity.creator
self.data[_('license_holder')] = self.entity.license_holder
self.data[_('size')] = self.entity.get_file_size()
Expand Down
1 change: 1 addition & 0 deletions openatlas/display/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
self.paging = paging
self.order = order or ''
self.defs = defs or []
self.additional_information = None

def display(self, name: str = 'default') -> str:
if not self.rows:
Expand Down
3 changes: 3 additions & 0 deletions openatlas/templates/entity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<div class="row">
<div class="{{ 'col-lg-6' if gis_data else 'col' }}">
{{ buttons|button_bar|safe }}
{% if table.additional_information %}
<p>{{table.additional_information}}</p>
{% endif %}
{{ table.display()|safe }}
</div>
{% if gis_data %}
Expand Down
25 changes: 21 additions & 4 deletions openatlas/views/entity_index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import g, render_template, url_for
from flask_babel import lazy_gettext as _
from flask_babel import format_number, lazy_gettext as _
from werkzeug.wrappers import Response

from openatlas import app
Expand All @@ -9,7 +9,7 @@
button, check_iiif_file_exist, get_base_table_data, get_file_path, link,
required_group)
from openatlas.display.util2 import (
format_date, is_authorized, manual, show_table_icons)
format_date, is_authorized, manual, show_table_icons, uc_first)
from openatlas.models.entity import Entity
from openatlas.models.gis import Gis

Expand All @@ -25,25 +25,34 @@ def index(view: str) -> str | Response:
g.classes[name].label,
url_for('insert', class_=name),
tooltip_text=g.classes[name].get_tooltip()))
crumbs = [_(view).replace('_', ' ')]
if view == 'file':
crumbs = [[_('file'), url_for('file_index')], _('files')]
return render_template(
'entity/index.html',
class_=view,
table=get_table(view),
buttons=buttons,
gis_data=Gis.get_all() if view == 'place' else None,
title=_(view.replace('_', ' ')),
crumbs=[[_('file'), url_for('file_index')], _('files')]
if view == 'file' else [_(view).replace('_', ' ')])
crumbs=crumbs)


def get_table(view: str) -> Table:
table = Table(g.table_headers[view])
if view == 'file':
stats = {'public': 0, 'without_license': 0, 'without_creator': 0}
table.order = [[0, 'desc']]
table.header = ['date'] + table.header
if show_table_icons():
table.header.insert(1, _('icon'))
for entity in Entity.get_by_class('file', types=True):
if entity.public:
stats['public'] += 1
if not entity.standard_type:
stats['without_license'] += 1
elif not entity.creator:
stats['without_creator'] += 1
data = [
format_date(entity.created),
link(entity),
Expand All @@ -57,6 +66,14 @@ def get_table(view: str) -> Table:
if show_table_icons():
data.insert(1, file_preview(entity.id))
table.rows.append(data)
table.additional_information = (
uc_first(_('files')) + ': ' +
f"{format_number(stats['public'])} " + _('public') +
f", {format_number(stats['without_license'])} " +
_('public without license') +
f", {format_number(stats['without_creator'])} " +
_('public with license but without creator'))

elif view == 'reference_system':
for system in g.reference_systems.values():
table.rows.append([
Expand Down
19 changes: 17 additions & 2 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,43 @@
class FileTest(TestBaseCase):

def test_file(self) -> None:

with app.app_context():
with app.test_request_context():
app.preprocess_request()
place = insert('place', 'File keeper')
reference = insert('edition', 'Ancient Books')
license_type = get_hierarchy('License')

logo = Path(
app.root_path) / 'static' / 'images' / 'layout' / 'logo.png'

with open(logo, 'rb') as img_1, open(logo, 'rb') as img_2:
rv: Any = self.app.post(
url_for('insert', class_='file', origin_id=place.id),
data={'name': 'OpenAtlas logo', 'file': [img_1, img_2]},
data={
'name': 'OpenAtlas logo',
'public': True,
'file': [img_1, img_2]},
follow_redirects=True)
assert b'An entry has been created' in rv.data

with app.test_request_context():
app.preprocess_request()
files = Entity.get_by_class('file')
file_without_creator_id = files[0].id

rv = self.app.get(url_for('view', id_=file_without_creator_id))
assert b'but license is missing ' in rv.data

with open(logo, 'rb') as img:
rv = self.app.post(
url_for('insert', class_='file', origin_id=reference.id),
data={
'name': 'OpenAtlas logo',
'file': img},
'file': img,
'public': True,
str(license_type.id): license_type.subs[0]},
follow_redirects=True)
assert b'An entry has been created' in rv.data

Expand Down

0 comments on commit 23f520b

Please sign in to comment.