This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<br> | |
<h2>Thank you for your order {{ order.full_name }}</h2> | |
<h3>Your Order ID: {{ order.short_uuid }}</h3> | |
<h3>Shipping Details:</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="cart"> | |
{% with total_items=cart|length %} | |
{% if cart|length > 0 %} | |
Ваша корзина: | |
<a href="{% url "cart:CartDetail" %}"> | |
{{ total_items }} тов. {{ cart.get_total_price }} руб. | |
</a> | |
{% else %} | |
Корзина пустая | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for article in articles %} | |
{% include 'articles/partial/partial_article.html' %} | |
{% empty %} | |
<h1>Nothing to show</h1> | |
{% endfor %} | |
<!-- Pagination --> | |
{% if articles.has_other_pages %} | |
<div class="text-center"> | |
<ul class="pagination pagination-lg text-center"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Custom django checks. | |
H001: Field has no verbose name. | |
H002: Verbose name should use gettext. | |
H003: Words in verbose name must be all upper case or all lower case. | |
H004: Help text should use gettext. | |
H005: Model must define class Meta. | |
H006: Model has no verbose name. | |
H007: Model has no verbose name plural. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.functional import curry | |
class DetailsInline(admin.TabularInline): | |
model = Details | |
# formset = DetailsFormset | |
extra = 3 | |
def get_formset(self, request, obj=None, **kwargs): | |
initial = [] | |
if request.method == "GET": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductVariantAdminInline(admin.TabularInline): | |
extra = 0 | |
model = ProductVariant | |
def get_parent_object_from_request(self, request): | |
""" | |
Returns the parent object from the request or None. | |
Note that this only works for Inlines, because the `parent_model` | |
is not available in the regular admin.ModelAdmin as an attribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AfterFetchQuerySetMixin: | |
""" | |
QuerySet mixin to enable functions to run immediately | |
after records have been fetched from the DB. | |
""" | |
# This is most useful for registering 'prefetch_related' like operations | |
# or complex aggregations that need to be run after fetching, but while | |
# still allowing chaining of other QuerySet methods. | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
def number_str_to_float(amount_str:str) -> (any, bool): | |
""" | |
Take in an amount string to return float (if possible). | |
Valid string returns: | |
Float | |
Boolean -> True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a hack so that French translation falls back to English translation, | |
# not German translation (which is the default locale and the original | |
# strings). | |
from django.utils.translation import trans_real | |
class MyDjangoTranslation(trans_real.DjangoTranslation): | |
def _add_fallback(self, localedirs=None): | |
if self._DjangoTranslation__language[:2] in {'de', 'en'}: | |
return super()._add_fallback(localedirs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse | |
from django.http import HttpResponseForbidden | |
from apps.order.models import Certificate, Order | |
__all__ = ( | |
'files_access', | |
) | |
NewerOlder