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
// File: openzeppelin-solidity/contracts/token/ERC20/IERC20.sol | |
pragma solidity ^0.5.2; | |
/** | |
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include | |
* the optional functions; to access them see `ERC20Detailed`. | |
*/ | |
interface IERC20 { |
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
#!/usr/bin/env python3.7 | |
from abc import ABC, abstractmethod | |
from decimal import Decimal | |
from typing import NamedTuple, List, Tuple | |
# STUBS | |
def _(val): |
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
def make_readonly_field_for_instance( | |
parent_obj, obj, template_path: str = "", extra_context: dict = None | |
) -> callable: | |
""" | |
Dynamically creating new read-only fields for ModelAdmin classes | |
:param parent_obj: Models instance from admin class | |
:param obj: The object for which we are creating the field | |
:param template_path: Template for rendering | |
:param extra_context: dynamic context | |
:return: callable |
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
order = ( | |
Order.objects | |
.select_related("patient", "client") | |
.prefetch_related( | |
"orderstep_order__orderstepmisc_orderstep__misc", | |
"orderstep_order__orderstepjob_orderstep" | |
) | |
.annotate(orderstep_order__row_number=number_subquery) | |
.filter(pk=pk) |
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
# models.py | |
class ProductionOrder(models.Model): | |
step = models.OneToOneField( | |
"order.OrderStep", | |
on_delete=models.DO_NOTHING, | |
verbose_name=_("Step"), | |
related_name="po_productionorder", | |
) |
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
def get_jobs_queryset(self) -> QuerySet: | |
""" | |
Get QuerySet from production.Job (for subquery in ProductionOrderJob queryset) | |
:return: QuerySet | |
""" | |
return apps.get_model("production.Job").objects.filter( | |
( | |
Q(version_end_date__gt=OuterRef("production_order__created_at")) | |
| Q(version_end_date__isnull=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
def when_conditions(when_year, when_month, then_val: Any = 1): | |
return When( | |
Q( | |
created_at__month=when_month, | |
created_at__year=when_year, | |
finish_at__isnull=True, | |
) | |
| Q( | |
finish_at__month=when_month, | |
finish_at__year=when_year, |
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
# Запрос: | |
company_subquery = ( | |
Order.objects_clear.annotate( | |
company_pk=F("client__company_id"), | |
company=Coalesce( | |
F("client__company__alias"), F("client__company__name") | |
), | |
) | |
) | |
company_name_subquery = company_subquery.values("company")[:1] |
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
when__critical_status = When( | |
Q(orderstep_order__deadline__isnull=False) | |
& Q(orderstep_order__deadline__gte=timezone.now()) | |
& Q(orderstep_order__deadline__lte=timezone.now() + timedelta(hours=4)), | |
then=Val("critical") | |
) | |
when__need_attention_status = When( | |
Q(orderstep_order__deadline__isnull=False) | |
& Q(orderstep_order__deadline__gte=timezone.now() + timedelta(hours=4)) |
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
# forms.py | |
class UserForm(forms.ModelForm): | |
"""A form for users. Includes password field.""" | |
password = forms.CharField( | |
label="Password", widget=forms.PasswordInput(), required=False | |
) | |
email = MultiEmailField( | |
widget=MultiEmailWidget(), required=False, help_text=help_text_for_email | |
) |
OlderNewer