Skip to content

Commit

Permalink
Merge pull request #27 from Gray-Advantage/sergey
Browse files Browse the repository at this point in the history
fix: update min date in form ever users request
  • Loading branch information
Gray-Advantage authored Jun 12, 2024
2 parents 556d660 + 7d8d3bd commit bd386ce
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ DJANGO_USE_SIMPLE_DATABASE=True
DJANGO_DATABASE_NAME=database
DJANGO_DATABASE_USER=webmaster
DJANGO_DATABASE_PASSWORD=this_very_secret_password_for_database

DJANGO_LOG_FILE_PATH=/path/to/log/file
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,26 @@ DJANGO_MAIL_PORT=2525
DJANGO_MAIL_USER=webmaster@localhost
DJANGO_MAIL_PASSWORD=this_very_secret_password_for_smtp_mail
DEFAULT_USER_IS_ACTIVE=False
DJANGO_USE_SIMPLE_DATABASE=True
DJANGO_LOG_FILE_PATH=/path/to/log/file
```
`DJANGO_SECRET_KEY`, `DJANGO_ALLOWED_HOSTS` замените на свои значения.
`DJANGO_MAIL_HOST`, `DJANGO_MAIL_PORT`, `DJANGO_MAIL_USER`,
`DJANGO_MAIL_PASSWORD` - настройки почтового сервиса, используйте свои.
`DJANGO_LOG_FILE_PATH` - путь, по которому приложение будет записывать все логи
(уровень логирования WARNING и выше)
`DJANGO_USE_SIMPLE_DATABASE` - Если `True`, то приложение будет использовать в
качестве базы данных простой файл.
Если установлено значение `False`, то необходимо указать настройки для сложной
СУБД ([postgresql](https://www.postgresql.org/)):
`DJANGO_DATABASE_NAME` - название вашей БД, `DJANGO_DATABASE_USER` - имя
пользователя БД, `DJANGO_DATABASE_PASSWORD` - пароль пользователя БД.
Предполагается, что БД находиться там же, где и приложения и работает на порту
5432
Настройка `DEFAULT_USER_IS_ACTIVE=False` - означает, что перед использованием
сервиса обязательно требуется подтверждённая почта, установите `True`, если
этого не нужно
Expand Down
31 changes: 29 additions & 2 deletions datanar/datanar/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pathlib import Path
import sys

from decouple import config, strtobool
from django.conf import settings
from django.utils.translation import gettext_lazy as _

BASE_DIR = Path(__file__).resolve().parent.parent

VERSION = "1.5.9"
VERSION = "1.6.0"

SECRET_KEY = config(
"DJANGO_SECRET_KEY",
Expand All @@ -16,6 +17,32 @@

DEBUG = bool(strtobool(config("DJANGO_DEBUG", "False")))

NOT_TESTING = "test" not in sys.argv

if "None" != config("DJANGO_LOG_FILE_PATH", default="None", cast=str):
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "{levelname}\n{asctime}\n>>> {message}\n",
"style": "{",
},
},
"handlers": {
"file": {
"level": "WARNING",
"class": "logging.FileHandler",
"filename": config("DJANGO_LOG_FILE_PATH", cast=str),
"formatter": "verbose",
},
},
"root": {
"handlers": ["file"],
"level": "WARNING",
},
}

ALLOWED_HOSTS = config(
"DJANGO_ALLOWED_HOSTS",
default="*",
Expand Down Expand Up @@ -58,7 +85,7 @@
"tz_detect.middleware.TimezoneMiddleware",
]

if settings.DEBUG:
if settings.DEBUG and NOT_TESTING:
INSTALLED_APPS.append("debug_toolbar")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
INTERNAL_IPS = ["127.0.0.1"]
Expand Down
2 changes: 1 addition & 1 deletion datanar/datanar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
path("", include("redirects.urls")),
]

if settings.DEBUG:
if settings.DEBUG and settings.NOT_TESTING:
import debug_toolbar

urlpatterns.append(path("__debug__/", include(debug_toolbar.urls)))
Expand Down
7 changes: 6 additions & 1 deletion datanar/redirects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
sqids = Sqids()


def _now_date():
return timezone.now().date()


class CustomDateField(forms.DateInput):
input_type = "date"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.attrs["min"] = timezone.now().date()
self.attrs["min"] = _now_date()


class RedirectForm(BootstrapFormMixin, forms.ModelForm):
Expand Down Expand Up @@ -124,6 +128,7 @@ def __init__(self, *args, **kwargs):

self.fields["links_file"].widget.attrs["class"] = "d-none"
self.fields["links_file"].widget.attrs["accept"] = ".txt, .xlsx"
self.fields["date_validity_field"].widget.attrs["min"] = _now_date()

def clean(self):
if self.cleaned_data["date_validity_field"] is None:
Expand Down

0 comments on commit bd386ce

Please sign in to comment.