Commit 2e794e94 authored by Artem Serga's avatar Artem Serga

#6 - Make font is bold for required form fields and add template helpers support

parent 68b681cf
...@@ -2,10 +2,8 @@ from functools import wraps ...@@ -2,10 +2,8 @@ from functools import wraps
from re import sub from re import sub
from flask import Blueprint, render_template, url_for, abort, g from flask import Blueprint, render_template, url_for, abort, g
from flask.ext.admin import babel from flask.ext.admin import babel
from flask.ext.admin import helpers as h
from .helpers import set_current_view
def expose(url='/', methods=('GET',)): def expose(url='/', methods=('GET',)):
...@@ -45,13 +43,12 @@ def _wrap_view(f): ...@@ -45,13 +43,12 @@ def _wrap_view(f):
@wraps(f) @wraps(f)
def inner(self, **kwargs): def inner(self, **kwargs):
# Store current admin view # Store current admin view
set_current_view(self) h.set_current_view(self)
# Check if administrative piece is accessible # Check if administrative piece is accessible
h = self._handle_view(f.__name__, **kwargs) abort = self._handle_view(f.__name__, **kwargs)
if abort is not None:
if h is not None: return abort
return h
return f(self, **kwargs) return f(self, **kwargs)
...@@ -224,6 +221,7 @@ class BaseView(object): ...@@ -224,6 +221,7 @@ class BaseView(object):
# or enabled. # or enabled.
kwargs['_gettext'] = babel.gettext kwargs['_gettext'] = babel.gettext
kwargs['_ngettext'] = babel.ngettext kwargs['_ngettext'] = babel.ngettext
kwargs['h'] = h
# Contribute extra arguments # Contribute extra arguments
kwargs.update(self._template_args) kwargs.update(self._template_args)
......
from flask import g from flask import g
from wtforms.validators import Required
def set_current_view(view): def set_current_view(view):
...@@ -7,3 +8,10 @@ def set_current_view(view): ...@@ -7,3 +8,10 @@ def set_current_view(view):
def get_current_view(): def get_current_view():
return getattr(g, '_admin_view', None) return getattr(g, '_admin_view', None)
def is_required_form_field(field):
for validator in field.validators:
if isinstance(validator, Required):
return True
return False
...@@ -78,7 +78,13 @@ ...@@ -78,7 +78,13 @@
{% for f in form if f.type != 'HiddenField' and f.type != 'CSRFTokenField' %} {% for f in form if f.type != 'HiddenField' and f.type != 'CSRFTokenField' %}
<div class="control-group{% if f.errors %} error{% endif %}"> <div class="control-group{% if f.errors %} error{% endif %}">
{{ f.label(class='control-label') }} <div class="control-label">
{% if h.is_required_form_field(f) %}
<strong>{{ f.label.text }}</strong>
{% else %}
{{ f.label.text }}
{% endif %}
</div>
<div class="controls"> <div class="controls">
<div> <div>
{% if not focus_set %} {% if not focus_set %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment