mirror of https://github.com/snachodog/mybuddy.git
Code review comments
This commit is contained in:
parent
c665ebb181
commit
a35df92fe2
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
|
||||||
import time
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Iterable, Optional
|
from typing import Iterable, Optional
|
||||||
|
|
||||||
|
@ -12,7 +10,6 @@ from django.utils.text import slugify
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.text import format_lazy
|
from django.utils.text import format_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.timezone import now
|
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
@ -20,7 +17,7 @@ import random
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
from taggit.models import TagBase, GenericTaggedItemBase, TaggedItemBase
|
from taggit.models import TagBase, GenericTaggedItemBase, TaggedItemBase
|
||||||
|
|
||||||
random.seed(time.time())
|
random.seed()
|
||||||
|
|
||||||
|
|
||||||
def validate_date(date, field_name):
|
def validate_date(date, field_name):
|
||||||
|
@ -120,7 +117,7 @@ class BabyBuddyTag(TagBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
last_used = models.DateTimeField(
|
last_used = models.DateTimeField(
|
||||||
default=now,
|
default=timezone.now,
|
||||||
blank=False,
|
blank=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -133,7 +130,7 @@ class BabyBuddyTagged(GenericTaggedItemBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def save_base(self, *args, **kwargs):
|
def save_base(self, *args, **kwargs):
|
||||||
self.tag.last_used = now()
|
self.tag.last_used = timezone.now()
|
||||||
self.tag.save()
|
self.tag.save()
|
||||||
return super().save_base(*args, **kwargs)
|
return super().save_base(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.forms import Media
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
from django.forms import Widget
|
from django.forms import Widget
|
||||||
|
|
||||||
|
from . import models
|
||||||
|
|
||||||
class TagsEditor(Widget):
|
class TagsEditor(Widget):
|
||||||
class Media:
|
class Media:
|
||||||
|
@ -27,8 +28,6 @@ class TagsEditor(Widget):
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def get_context(self, name: str, value: Any, attrs) -> Dict[str, Any]:
|
def get_context(self, name: str, value: Any, attrs) -> Dict[str, Any]:
|
||||||
from . import models
|
|
||||||
|
|
||||||
most_tags = models.BabyBuddyTag.objects.order_by("-last_used").all()[:256]
|
most_tags = models.BabyBuddyTag.objects.order_by("-last_used").all()[:256]
|
||||||
|
|
||||||
result = super().get_context(name, value, attrs)
|
result = super().get_context(name, value, attrs)
|
||||||
|
|
Loading…
Reference in New Issue