Files
mayan-edms/mayan/apps/checkouts/widgets.py
Roberto Rosario 8e69178e07 Project: Switch to full app paths
Instead of inserting the path of the apps into the Python app,
the apps are now referenced by their full import path.

This app name claves with external or native Python libraries.
Example: Mayan statistics app vs. Python new statistics library.

Every app reference is now prepended with 'mayan.apps'.

Existing config.yml files need to be updated manually.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-12-05 02:04:20 -04:00

46 lines
1.2 KiB
Python

from __future__ import unicode_literals
import datetime
from django import forms
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from mayan.apps.common.literals import TIME_DELTA_UNIT_CHOICES
class SplitTimeDeltaWidget(forms.widgets.MultiWidget):
"""
A Widget that splits a timedelta input into three <input type="text">
boxes.
"""
def __init__(self, attrs=None):
widgets = (
forms.widgets.NumberInput(
attrs={
'maxlength': 4, 'style': 'width: 8em;',
'placeholder': _('Period')
}
),
forms.widgets.Select(
attrs={'style': 'width: 8em;'}, choices=TIME_DELTA_UNIT_CHOICES
),
)
super(SplitTimeDeltaWidget, self).__init__(widgets, attrs)
def decompress(self, value):
return (None, None)
def value_from_datadict(self, querydict, files, name):
unit = querydict.get('{}_1'.format(name))
period = querydict.get('{}_0'.format(name))
if not unit or not period:
return now()
period = int(period)
timedelta = datetime.timedelta(**{unit: period})
return now() + timedelta