mirror of https://github.com/snachodog/mybuddy.git
Linting
This commit is contained in:
parent
ae1dee1d7b
commit
3ac21ed67b
|
@ -7,6 +7,7 @@ from django.utils.translation import gettext as _
|
|||
from core import models
|
||||
from core.widgets import TagsEditor
|
||||
|
||||
|
||||
def set_initial_values(kwargs, form_type):
|
||||
"""
|
||||
Sets initial value for add forms based on provided kwargs.
|
||||
|
@ -170,7 +171,7 @@ class NoteForm(CoreModelForm):
|
|||
"data-target": "#datetimepicker_time",
|
||||
}
|
||||
),
|
||||
"tags": TagsEditor()
|
||||
"tags": TagsEditor(),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ from taggit.models import TagBase, GenericTaggedItemBase, TaggedItemBase
|
|||
|
||||
random.seed(time.time())
|
||||
|
||||
|
||||
def validate_date(date, field_name):
|
||||
"""
|
||||
Confirm that a date is not in the future.
|
||||
|
@ -81,15 +82,31 @@ def validate_time(time, field_name):
|
|||
{field_name: _("Date/time can not be in the future.")}, code="time_invalid"
|
||||
)
|
||||
|
||||
TAG_COLORS = [
|
||||
"#FF0000", "#00FF00", "#0000FF", "#FF00FF", "#FFFF00", "#00FFFF",
|
||||
"#FF7F7F", "#7FFF7F", "#7F7FFF", "#FF7FFF", "#FFFF7F", "#7FFFFF",
|
||||
"#7F0000", "#007F00", "#00007F", "#7F007F", "#7F7F00", "#007F7F",
|
||||
]
|
||||
|
||||
def random_color():
|
||||
TAG_COLORS = [
|
||||
"#FF0000",
|
||||
"#00FF00",
|
||||
"#0000FF",
|
||||
"#FF00FF",
|
||||
"#FFFF00",
|
||||
"#00FFFF",
|
||||
"#FF7F7F",
|
||||
"#7FFF7F",
|
||||
"#7F7FFF",
|
||||
"#FF7FFF",
|
||||
"#FFFF7F",
|
||||
"#7FFFFF",
|
||||
"#7F0000",
|
||||
"#007F00",
|
||||
"#00007F",
|
||||
"#7F007F",
|
||||
"#7F7F00",
|
||||
"#007F7F",
|
||||
]
|
||||
return TAG_COLORS[random.randrange(0, len(TAG_COLORS))]
|
||||
|
||||
|
||||
class BabyBuddyTag(TagBase):
|
||||
class Meta:
|
||||
verbose_name = _("Tag")
|
||||
|
@ -99,7 +116,7 @@ class BabyBuddyTag(TagBase):
|
|||
"Color",
|
||||
max_length=32,
|
||||
default=random_color,
|
||||
validators=[RegexValidator(r"^#[0-9A-F]{6}$")]
|
||||
validators=[RegexValidator(r"^#[0-9A-F]{6}$")],
|
||||
)
|
||||
|
||||
last_used = models.DateTimeField(
|
||||
|
@ -125,10 +142,12 @@ class BabyBuddyTaggableManager(TaggableManager):
|
|||
"""
|
||||
Remove default help_text - only reason for this to exist.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs["help_text"] = kwargs.get("help_text")
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class Child(models.Model):
|
||||
model_name = "child"
|
||||
first_name = models.CharField(max_length=255, verbose_name=_("First name"))
|
||||
|
@ -299,6 +318,7 @@ class Feeding(models.Model):
|
|||
validate_duration(self)
|
||||
validate_unique_period(Feeding.objects.filter(child=self.child), self)
|
||||
|
||||
|
||||
class Note(models.Model):
|
||||
model_name = "note"
|
||||
child = models.ForeignKey(
|
||||
|
|
|
@ -2,10 +2,12 @@ from django.forms import Media
|
|||
from typing import Any, Dict, Optional
|
||||
from django.forms import Widget
|
||||
|
||||
|
||||
class TagsEditor(Widget):
|
||||
class Media:
|
||||
js = ("babybuddy/js/tags_editor.js",)
|
||||
|
||||
|
||||
input_type = 'hidden'
|
||||
template_name = 'core/widget_tag_editor.html'
|
||||
|
||||
|
|
Loading…
Reference in New Issue