Revised the way to import from the datetime package, to avoid name conflict with the common "date" and "time" names.
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
"""The path converters for the journal entry management.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
import datetime as dt
|
||||
|
||||
from flask import abort
|
||||
from werkzeug.routing import BaseConverter
|
||||
@ -82,18 +82,18 @@ class DateConverter(BaseConverter):
|
||||
"""The date converter to convert the ISO date from and to the
|
||||
corresponding date in the routes."""
|
||||
|
||||
def to_python(self, value: str) -> date:
|
||||
def to_python(self, value: str) -> dt.date:
|
||||
"""Converts an ISO date to a date.
|
||||
|
||||
:param value: The ISO date.
|
||||
:return: The corresponding date.
|
||||
"""
|
||||
try:
|
||||
return date.fromisoformat(value)
|
||||
return dt.date.fromisoformat(value)
|
||||
except ValueError:
|
||||
abort(404)
|
||||
|
||||
def to_url(self, value: date) -> str:
|
||||
def to_url(self, value: dt.date) -> str:
|
||||
"""Converts a date to its ISO date.
|
||||
|
||||
:param value: The date.
|
||||
|
@ -17,7 +17,7 @@
|
||||
"""The line item sub-forms for the journal entry management.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
import datetime as dt
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
@ -307,7 +307,7 @@ class LineItemForm(FlaskForm):
|
||||
return getattr(self, "____original_line_item")
|
||||
|
||||
@property
|
||||
def original_line_item_date(self) -> date | None:
|
||||
def original_line_item_date(self) -> dt.date | None:
|
||||
"""Returns the text representation of the original line item.
|
||||
|
||||
:return: The text representation of the original line item.
|
||||
|
@ -17,7 +17,7 @@
|
||||
"""The reorder forms for the journal entry management.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
import datetime as dt
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import request
|
||||
@ -26,7 +26,7 @@ from accounting import db
|
||||
from accounting.models import JournalEntry
|
||||
|
||||
|
||||
def sort_journal_entries_in(journal_entry_date: date,
|
||||
def sort_journal_entries_in(journal_entry_date: dt.date,
|
||||
exclude: int | None = None) -> None:
|
||||
"""Sorts the journal entries under a date after changing the date or
|
||||
deleting a journal entry.
|
||||
@ -50,12 +50,12 @@ def sort_journal_entries_in(journal_entry_date: date,
|
||||
class JournalEntryReorderForm:
|
||||
"""The form to reorder the journal entries."""
|
||||
|
||||
def __init__(self, journal_entry_date: date):
|
||||
def __init__(self, journal_entry_date: dt.date):
|
||||
"""Constructs the form to reorder the journal entries in a day.
|
||||
|
||||
:param journal_entry_date: The date.
|
||||
"""
|
||||
self.date: date = journal_entry_date
|
||||
self.date: dt.date = journal_entry_date
|
||||
self.is_modified: bool = False
|
||||
|
||||
def save_order(self) -> None:
|
||||
|
@ -17,7 +17,7 @@
|
||||
"""The views for the journal entry management.
|
||||
|
||||
"""
|
||||
from datetime import date
|
||||
import datetime as dt
|
||||
from urllib.parse import parse_qsl, urlencode
|
||||
|
||||
import sqlalchemy as sa
|
||||
@ -30,9 +30,9 @@ from accounting.locale import lazy_gettext
|
||||
from accounting.models import JournalEntry
|
||||
from accounting.utils.cast import s
|
||||
from accounting.utils.flash_errors import flash_form_errors
|
||||
from accounting.utils.journal_entry_types import JournalEntryType
|
||||
from accounting.utils.next_uri import inherit_next, or_next
|
||||
from accounting.utils.permission import has_permission, can_view, can_edit
|
||||
from accounting.utils.journal_entry_types import JournalEntryType
|
||||
from accounting.utils.user import get_current_user_pk
|
||||
from .forms import sort_journal_entries_in, JournalEntryReorderForm
|
||||
from .template_filters import with_type, to_transfer, format_amount_input, \
|
||||
@ -67,7 +67,7 @@ def show_add_journal_entry_form(journal_entry_type: JournalEntryType) -> str:
|
||||
form.validate()
|
||||
else:
|
||||
form = journal_entry_op.form()
|
||||
form.date.data = date.today()
|
||||
form.date.data = dt.date.today()
|
||||
return journal_entry_op.render_create_template(form)
|
||||
|
||||
|
||||
@ -188,7 +188,7 @@ def delete_journal_entry(journal_entry: JournalEntry) -> redirect:
|
||||
|
||||
@bp.get("dates/<date:journal_entry_date>", endpoint="order")
|
||||
@has_permission(can_view)
|
||||
def show_journal_entry_order(journal_entry_date: date) -> str:
|
||||
def show_journal_entry_order(journal_entry_date: dt.date) -> str:
|
||||
"""Shows the order of the journal entries in a same date.
|
||||
|
||||
:param journal_entry_date: The date.
|
||||
@ -203,7 +203,7 @@ def show_journal_entry_order(journal_entry_date: date) -> str:
|
||||
|
||||
@bp.post("dates/<date:journal_entry_date>", endpoint="sort")
|
||||
@has_permission(can_edit)
|
||||
def sort_journal_entries(journal_entry_date: date) -> redirect:
|
||||
def sort_journal_entries(journal_entry_date: dt.date) -> redirect:
|
||||
"""Reorders the journal entries in a date.
|
||||
|
||||
:param journal_entry_date: The date.
|
||||
|
Reference in New Issue
Block a user