Skip to content

Commit

Permalink
fix: print greenhouse, type layout
Browse files Browse the repository at this point in the history
  • Loading branch information
moogoo78 committed Oct 29, 2024
1 parent 95349e9 commit 08fc7b9
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 67 deletions.
38 changes: 3 additions & 35 deletions app/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
Site,
)
from app.utils import find_date
from app.jinja_func import *

#from scripts import load_data

Expand All @@ -55,6 +56,7 @@
}
})
'''

def apply_blueprints(app):
from app.blueprints.base import base as base_bp
from app.blueprints.frontpage import frontpage as frontpage_bp
Expand All @@ -66,41 +68,8 @@ def apply_blueprints(app):
app.register_blueprint(admin_bp, url_prefix='/admin')
app.register_blueprint(api_bp, url_prefix='/api/v1')

def get_locale():
#print(request.cookies.get('language'), flush=True)
locale = 'zh'
if request.path[0:3] == '/en':
locale = 'en'
#elif request.path[0:3] == '/zh':
# locale = 'zh'
#else:
# locale = request.accept_languages.best_match(['zh', 'en'])

#print('get_locale', locale, flush=True)
return getattr(g, 'LOCALE', locale)

def get_lang_path(lang):
#locale = get_locale()
by = None
#if m = re.match(r'/(en|zh)/', request.path):
# print(m.group(''))
if request.path[0:3] == '/en':
by = 'prefix'
elif request.path[0:3] == '/zh':
by = 'prefix'
else:
locale = request.accept_languages.best_match(['zh', 'en'])
by = 'accept-languages'
#print('get_lang_path', locale, flush=True)
#print(by, lang, flush=True)
if by == 'prefix':
return f'/{lang}{request.path[3:]}'
elif by == 'accept-languages':
return f'/{lang}{request.path}'

#session = init_db(flask_app.config)


def create_app():
#app = Flask(__name__, subdomain_matching=True, static_folder=None)
app = Flask(__name__)
Expand All @@ -123,7 +92,6 @@ def create_app():
# subdomain='static',
# view_func=app.send_static_file)


app.url_map.strict_slashes = False
#print(app.config, flush=True)
return app
Expand All @@ -136,6 +104,7 @@ def create_app():
babel = Babel(flask_app, locale_selector=get_locale)
flask_app.jinja_env.globals['get_locale'] = get_locale
flask_app.jinja_env.globals['get_lang_path'] = get_lang_path
flask_app.jinja_env.globals['str_to_date'] = str_to_date
login_manager = LoginManager()
login_manager.init_app(flask_app)
jwt = JWTManager(flask_app)
Expand All @@ -144,7 +113,6 @@ def create_app():
def load_user(id):
return User.query.get(id)


@flask_app.route('/')
def cover():
host = request.headers.get('Host', '')
Expand Down
40 changes: 40 additions & 0 deletions app/jinja_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from datetime import datetime
from flask import (
request,
g,
)

def str_to_date(string, format='%Y-%m-%d'):
return datetime.strptime(string, format)

def get_locale():
#print(request.cookies.get('language'), flush=True)
locale = 'zh'
if request.path[0:3] == '/en':
locale = 'en'
#elif request.path[0:3] == '/zh':
# locale = 'zh'
#else:
# locale = request.accept_languages.best_match(['zh', 'en'])

#print('get_locale', locale, flush=True)
return getattr(g, 'LOCALE', locale)

def get_lang_path(lang):
#locale = get_locale()
by = None
#if m = re.match(r'/(en|zh)/', request.path):
# print(m.group(''))
if request.path[0:3] == '/en':
by = 'prefix'
elif request.path[0:3] == '/zh':
by = 'prefix'
else:
locale = request.accept_languages.best_match(['zh', 'en'])
by = 'accept-languages'
#print('get_lang_path', locale, flush=True)
#print(by, lang, flush=True)
if by == 'prefix':
return f'/{lang}{request.path[3:]}'
elif by == 'accept-languages':
return f'/{lang}{request.path}'
22 changes: 0 additions & 22 deletions app/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,28 +1004,6 @@ def get_image(self, thumbnail='s'):
# return media.file_url
return ''

# def get_assertions(self):
# result = {}
# for a in self.assertions:
# result[a.assertion_type.name] = {
# 'type_id': a.assertion_type_id,
# 'type_name': a.assertion_type.name,
# 'type_label': a.assertion_type.label,
# 'value': a.value
# }
# return result

# def get_annotations(self):
# result = {}
# for a in self.annotations:
# result[a.annotation_type.name] = {
# 'type_id': a.annotation_type_id,
# 'type_name': a.annotation_type.name,
# 'type_label': a.annotation_type.label,
# 'value': a.value
# }
# return result

def get_annotation_map(self, type_name=''):
result = {}
for x in self.annotations:
Expand Down
28 changes: 23 additions & 5 deletions app/templates/admin/inc_record-form2.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,22 @@ $( document ).ready(function() {
itemElement = document.createElement('input');
itemElement.classList.add('uk-input');
itemElement.id = itemId;
itemElement.value = (values[item.name]) ? values[item.name].value : '';
itemElement.value = val;
itemElement.oninput = (e, key=item.name) => {
if (values[key]?.value === e.target.value) {
if (val === e.target.value) {
e.target.classList.remove('uk-form-success');
} else {
e.target.classList.add('uk-form-success');
}
};
} else if (item.input_type === 'input-date') {
itemElement = document.createElement('input');
itemElement.classList.add('uk-input');
itemElement.setAttribute('type', 'date');
itemElement.id = itemId;
itemElement.value = (values[item.name]) ? values[item.name].value : '';
itemElement.onchange = (e) => {
if (val === e.target.value) {
e.target.classList.remove('uk-form-success');
} else {
e.target.classList.add('uk-form-success');
Expand All @@ -315,8 +328,8 @@ $( document ).ready(function() {
itemElement.classList.add('uk-textarea');
itemElement.id = itemId;
itemElement.textContent = (values[item.name]) ? values[item.name].value : '';
itemElement.oninput = (e, key=item.name) => {
if (values[key]?.value === e.target.value) {
itemElement.oninput = (e) => {
if (val === e.target.value) {
e.target.classList.remove('uk-form-success');
} else {
e.target.classList.add('uk-form-success');
Expand All @@ -339,7 +352,7 @@ $( document ).ready(function() {
} else {
itemElement.value = 'on';
}
}
};
}
assertion.querySelector('.uk-form-controls').appendChild(itemElement);
container.appendChild(assertion);
Expand Down Expand Up @@ -589,6 +602,11 @@ $( document ).ready(function() {
}
};

let printBtn = unitCard.querySelector('#card-print-button');
printBtn.id = `unit-${index}-card-print-button`;
printBtn.dataset.index = index;
printBtn.setAttribute('href', `/admin/print-label?entities=u${unit.id}`);

let detailToggle = unitCard.querySelector('#card-detail-toggle');
detailToggle.id = `unit-${index}-card-detail-toggle`;
detailToggle.setAttribute('href', `#unit-${index}-modal`);
Expand Down
3 changes: 2 additions & 1 deletion app/templates/admin/inc_record_template-modal.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h6 class="uk-text-bold">{{ _('館號') }}: <span id="card-catalog-number"></spa
<div class="uk-card-footer">
<div class="uk-grid uk-grid-small uk-grid-divider uk-flex uk-flex-middle" data-uk-grid>
<div class="uk-width-expand uk-text-small">

</div>
<div class="uk-width-auto uk-text-right">
{#
Expand All @@ -83,6 +83,7 @@ <h6 class="uk-text-bold">{{ _('館號') }}: <span id="card-catalog-number"></spa
<a id="card-delete-button" data-uk-tooltip="title: {{ _('刪除') }}" href="#" class="uk-icon-link drag-icon" data-uk-icon="icon:trash; ratio: 1"></a>
</div>
<div class="uk-width-auto uk-text-right">
<a id="card-print-button" href="#" data-uk-tooltip="title: {{ _('標籤') }}" class="uk-icon-link" data-uk-icon="icon:print; ratio: 1" target="_blank"></a>
<a id="card-detail-toggle" href="#" data-uk-tooltip="title: {{ _('編輯') }}" class="uk-icon-link" data-uk-icon="icon:pencil; ratio: 1" uk-toggle></a>
</div>
</div>
Expand Down
11 changes: 7 additions & 4 deletions app/templates/admin/print-label.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 class="page-title">page 1</h1>
</div>

<div class="annotation-container">
{% if item.type == 'unit' and item.unit.get_annotations('add-char') %}{{ item.unit.get_annotations('add-char').value }}{% endif %}
{% if item.type == 'unit' and item.unit.get_annotation('add-char') %}{{ item.unit.get_annotation('add-char').value }}{% endif %}
{% for i in item.assertion_display_list %}
<div class="annotations">{{ i }}</div>
{% endfor %}
Expand All @@ -89,6 +89,7 @@ <h1 class="page-title">page 1</h1>
{% if field_note_list %}<div class="annotations">{{ field_note_list|reject('none')|join(', ') }}{{ annotation_list|rejectattr('text', 'none')|map(attribute='text')|join(', ') }}</div>{% endif %}
#}
</div>
{% if item.unit.type_status %}{{ item.unit.type_status|capitalize }} of {{ item.unit.typified_name }}{% endif %}
<div class="collect">
<span class="collect-num">{% if item.record.collector_id %}{{ item.record.collector.display_name }}{% endif %} {{ item.record.field_number }}</span>
<span class="collect-date">{% if item.record.collect_date %}{{ item.record.collect_date.strftime('%b. %d, %Y') }}{% endif %}</span>
Expand All @@ -98,10 +99,12 @@ <h1 class="page-title">page 1</h1>
<!-- LAYOUT1 div class="footer">HERBARIUM, ACADEMIA SINICA, TAIPEI (HAST)</div-->
<div class="institution"><span class="institution-name">中央研究院植物標本館</span><span class="institution-code">Herbarium, Academia Sinica, Taipei (HAST)</span></div>
<div class="annotations">
{% if item.type == 'unit' and item.unit.get_annotation('greenhouse') %}<span class="box">Plants of this collection were brought back for cultivation.</span>{% endif %}
{% if item.unit and item.unit.preparation_date %}<span class="box">This specimen was pressed on {{ item.unit.preparation_date.strftime('%b. %d, %Y') }}</span>{% endif %}
{% if item.type == 'unit' and item.unit.get_annotation('greenhouse').value %}<span class="box">Plants of this collection were brought back for cultivation.</span>{% endif %}
{% if item.unit and item.unit.get_annotation('greenhouse_pressed_date') %}
{% set p_date = item.unit.get_annotation('greenhouse_pressed_date').value %}
<span class="box">This specimen was pressed on {{ str_to_date(p_date).strftime('%b. %d, %Y') }}</span>
{% endif %}
</div>

</div>
{% endfor %}
</div><!-- end page-item-column -->
Expand Down

0 comments on commit 08fc7b9

Please sign in to comment.