Example inputs:
Variable | Value |
---|---|
key | the shared secret key here |
message | the message to hash here |
Reference outputs for example inputs above:
| Type | Hash |
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) |
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 |
""" | |
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 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) |
from django.http import HttpResponse | |
from django.http import HttpResponseForbidden | |
from apps.order.models import Certificate, Order | |
__all__ = ( | |
'files_access', | |
) | |
from collections import defaultdict | |
import weakref | |
__refs__ = defaultdict(weakref.WeakSet) | |
def clear_refs(cls): | |
__refs__[cls].clear() |
Example inputs:
Variable | Value |
---|---|
key | the shared secret key here |
message | the message to hash here |
Reference outputs for example inputs above:
| Type | Hash |
# https://gist.github.com/1035190 | |
# See also: Snippets 85, 240, 880 at http://www.djangosnippets.org/ | |
# | |
# Minimally, the following settings are required: | |
# | |
# SSL_ENABLED = True | |
# SSL_URLS = ( | |
# r'^/some/pattern/', | |
# ) |
from django import forms | |
from django.db.models import FilteredRelation, Q | |
from django.urls import path | |
from django.contrib import admin | |
from django.contrib.auth import get_user_model | |
from django.http import HttpResponseRedirect | |
from django.template.response import TemplateResponse | |
from django.urls import reverse | |
from django.utils.http import urlencode | |
from django.utils.translation import ugettext_lazy as _ |
#!/usr/bin/env python | |
# coding: utf-8 | |
class AttrDict(object): | |
def __init__(self, init=None): | |
if init is not None: | |
self.__dict__.update(init) | |
def __getitem__(self, key): | |
return self.__dict__[key] |