Commit 147e5d2b authored by Philippe Pepiot's avatar Philippe Pepiot
Browse files

Introduce a "display_in_user_request" on Daytype

This allow to modify Daytype titles without needing to adapt the code.
When display_in_user_request is set to True, User will see this choice when creating Timeperiod.

Ok ocy@
parent db4560548b6a
# coding: utf-8
add_attribute('Daytype', 'display_in_user_request')
rql('SET X display_in_user_request TRUE WHERE X is Daytype, (X title LIKE "%congés%" OR X title LIKE "%maladie%" OR X title LIKE "%paternité%" OR X title LIKE "%maternité%")')
commit()
......@@ -5,25 +5,26 @@ from cubicweb import _
from cubicweb_calendar import WORKING_AM, WORKING_PM, WORKING, NON_WORKING
## DAY TYPES
dt_definitions = {u'journée de congés': NON_WORKING,
u'matinée de congés': WORKING_PM,
u'après-midi de congés': WORKING_AM,
u'journée de mat-paternité': NON_WORKING,
u'malade la journée': NON_WORKING,
u'malade le matin': WORKING_PM,
u"malade l'après-midi": WORKING_AM,
u'journée de grève': NON_WORKING,
u'matinée de grève': WORKING_PM,
u'après-midi de grève': WORKING_AM,
u'journée de travail': WORKING,
u'matinée de travail': WORKING_AM,
u'après-midi de travail': WORKING_PM,
u'non travaillé': NON_WORKING,
dt_definitions = {u'journée de congés': (NON_WORKING, True),
u'matinée de congés': (WORKING_PM, True),
u'après-midi de congés': (WORKING_AM, True),
u'journée de mat-paternité': (NON_WORKING, True),
u'malade la journée': (NON_WORKING, True),
u'malade le matin': (WORKING_PM, True),
u"malade l'après-midi": (WORKING_AM, True),
u'journée de grève': (NON_WORKING, False),
u'matinée de grève': (WORKING_PM, False),
u'après-midi de grève': (WORKING_AM, False),
u'journée de travail': (WORKING, False),
u'matinée de travail': (WORKING_AM, False),
u'après-midi de travail': (WORKING_PM, False),
u'non travaillé': (NON_WORKING, True),
}
dt_store = {}
for dt_title, dt_type in dt_definitions.items():
dt_store[dt_title] = create_entity('Daytype', title=dt_title, type=dt_type)
for dt_title, (dt_type, display_in_user_request) in dt_definitions.items():
dt_store[dt_title] = create_entity('Daytype', title=dt_title, type=dt_type,
display_in_user_request=display_in_user_request)
weekdays = []
## WEEK DAYS
......
# cube's specific schema
from yams.buildobjs import EntityType, SubjectRelation, String, Datetime
from yams.buildobjs import EntityType, SubjectRelation, String, Datetime, Boolean
from yams.constraints import BoundaryConstraint, Attribute
from cubicweb.schema import WorkflowableEntityType
......@@ -28,6 +28,7 @@ class Daytype(EntityType):
title = String(required=True, maxsize=32, internationalizable=True)
type = String(vocabulary=(_('dt_working'), _('dt_nonworking'),
_('dt_working_am'), _('dt_working_pm')))
display_in_user_request = Boolean(required=True, default=False)
class Timeperiod(WorkflowableEntityType):
......
......@@ -34,13 +34,10 @@ _abaa.tag_object_of(('*', 'for_period', 'Timeperiod'), True)
def daytype_choices(form, field, limit=None):
req = form._cw
# FIXME: holidays should have their own type and we shuold not rely
# on application-defined vocabulary
rql = u'Any D,DT WHERE D is Daytype, D title DT'
if 'holidays' in req.form:
rset = req.execute(u'Any D,DT WHERE D is Daytype, D title DT, '
u'D title IN ("journée de congés", "matinée de congés", "après-midi de congés", "non travaillé", "journée de mat-paternité")') # noqa: E501
else:
rset = req.execute(u'Any D,DT WHERE D is Daytype, D title DT')
rql += ', D display_in_user_request TRUE'
rset = req.execute(rql)
return [(e.view('combobox'), six.text_type(e.eid)) for e in rset.entities()]
......
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