mirror of https://github.com/interlegis/sigi.git
Sesóstris Vieira
3 weeks ago
4 changed files with 25 additions and 0 deletions
@ -0,0 +1,15 @@ |
|||
import datetime |
|||
from django.forms import fields |
|||
from django.utils.translation import gettext_lazy as _ |
|||
from sigi.apps.utils.forms import widgets |
|||
|
|||
|
|||
class MonthField(fields.DateField): |
|||
widget = widgets.MonthInput |
|||
input_formats = ["%Y-%m", "%m-%Y"] |
|||
default_error_messages = { |
|||
"invalid": _("Enter a valid month."), |
|||
} |
|||
|
|||
def strptime(self, value, format): |
|||
return datetime.datetime.strptime(value, format).date() |
@ -0,0 +1,9 @@ |
|||
from django.forms import widgets |
|||
|
|||
|
|||
class MonthInput(widgets.DateTimeBaseInput): |
|||
template_name = "utils/forms/widgets/month.html" |
|||
|
|||
def __init__(self, attrs=None, format=None): |
|||
super().__init__(attrs) |
|||
self.format = format or "%Y-%m" |
@ -0,0 +1 @@ |
|||
<input type="month" name="{{ widget.name }}" {% if widget.value != None %} value="{{ widget.value|date:'Y-m' }}"{% endif %} {% include "django/forms/widgets/attrs.html" %} style="width: max-content;"> |
Loading…
Reference in new issue