Skip to content

Commit

Permalink
Kroshkadoc (#49)
Browse files Browse the repository at this point in the history
* removed unnecessary lib

* add platform

* create fakerscript for db, small fix makedoc views, del platform from githubactions

* del platform from githubactions

* small fix scripts

* Added new library(pymorphy3), removed unnecessary file(makedoc/constants), improved readability by moving functions from views to services, fix urls

* add ru locale

* update docker file

* del all locale, fix error, added new library(Babel)

* added new library(Babel) to requirements

* Deleted unnecessary script file
  • Loading branch information
dev-lymar committed Apr 21, 2024
1 parent a9a8fd7 commit c637b0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
6 changes: 0 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ ENV PYTHONUNBUFFERED 1

COPY requirements.txt /app/

# Устанавливаем локаль
RUN apt update && apt install -y --no-install-recommends locales; rm -rf /var/lib/apt/lists/*; sed -i '/^#.* ru_RU.UTF-8 /s/^#//' /etc/locale.gen; locale-gen

RUN locale -a


RUN pip install --upgrade pip \
&& pip install -r requirements.txt

Expand Down
29 changes: 16 additions & 13 deletions makedoc/services.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import babel.dates
import openpyxl
import locale
import pymorphy3
import os
import pymorphy3


from datetime import date, timedelta
from clients.models import Client
Expand All @@ -28,7 +29,6 @@ def get_logistics(request):
pass


locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8")
morph = pymorphy3.MorphAnalyzer()


Expand All @@ -39,9 +39,9 @@ def get_current_date():


def get_formatted_date_agreement():
formatted_date_agreement = (
f'«{get_current_date().day}» '
f'{get_current_date().strftime("%B")} {get_current_date().year} г.'
# Форматируем дату согласно русской локали
formatted_date_agreement = babel.dates.format_date(
get_current_date(), "«d» MMMM y г.", locale="ru_RU"
)
return formatted_date_agreement

Expand All @@ -50,15 +50,18 @@ def get_formatted_date_shipment():
current_date = get_current_date()
next_month_date = current_date + timedelta(days=30)
if next_month_date.month == current_date.month:
formatted_date_shipment = (
f"{morph.parse(current_date.strftime('%B'))[0].inflect({'nomn'}).word} "
f"{current_date.year} г."
)
month_name = babel.dates.format_date(current_date, "MMMM", locale="ru_RU")
# Склоняем имя месяца
month_name = morph.parse(month_name)[0].inflect({"nomn"}).word
formatted_date_shipment = f"{month_name} {current_date.year} г."
else:
current_month_name = babel.dates.format_date(current_date, "MMMM", locale="ru_RU")
next_month_name = babel.dates.format_date(next_month_date, "MMMM", locale="ru_RU")
# Склоняем имена месяцев
current_month_name = morph.parse(current_month_name)[0].inflect({"nomn"}).word
next_month_name = morph.parse(next_month_name)[0].inflect({"nomn"}).word
formatted_date_shipment = (
f"{morph.parse(current_date.strftime('%B'))[0].inflect({'nomn'}).word}-"
f"{morph.parse(next_month_date.strftime('%B'))[0].inflect({'nomn'}).word} "
f"{current_date.year} г."
f"{current_month_name}-" f"{next_month_name} " f"{current_date.year} г."
)
return formatted_date_shipment

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
asgiref==3.7.2
attrs==23.2.0
Babel==2.14.0
certifi==2024.2.2
cfgv==3.4.0
charset-normalizer==3.3.2
Expand Down

0 comments on commit c637b0b

Please sign in to comment.