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
# coding: utf-8 | |
from django.contrib import auth | |
from django.conf import settings | |
from django.core.exceptions import PermissionDenied | |
from django.shortcuts import redirect | |
User = auth.get_user_model() |
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
# coding: utf-8 | |
from funcparserlib.lexer import make_tokenizer, Spec | |
from funcparserlib.parser import (maybe, many, eof, skip, oneplus, fwd, | |
name_parser_vars, memoize, SyntaxError) | |
from funcparserlib.util import pretty_tree | |
from funcparserlib.contrib.common import unarg, flatten, n, op, op_, sometoks | |
from funcparserlib.contrib.lexer import (make_comment, make_multiline_comment, | |
newline, space) |
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 Keeper(object): | |
_instances = list() | |
def __new__(cls): | |
obj = object.__new__(cls) | |
cls.__init__(obj) | |
cls._instances.append(obj) | |
@classmethod | |
def list_instances(self): |
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 dictify(a, b): | |
return dict(map(lambda k, v: (k, v), a, b)) |
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
#container{width:100%;height:20px;} | |
#left{width:300px;float:left;} | |
#main{margin:0 200px 0 300px;text-align:right;padding-right:20px;} | |
#right2{width:200px;float:right;} | |
<div id="container"> | |
<div id="left">Col1</div> | |
<div id="right2">Col3</div> | |
<div id="main">Rubber col2</div> | |
</div> |
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.template import Library, Node | |
register = Library() | |
@register.simple_tag | |
def number_human(value, separator=',', precision=2, delimeter_count=3, decimal_separator='.'): | |
""" Converts an integer or floating-point number or a string to a string | |
containing the delimiter character (default comma) | |
after every delimeter_count digits (by default 3 digits). |
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
# -*- coding: utf-8 -*- | |
__all__ = ( | |
'MyError', | |
'Parent', | |
'First', | |
'Second', | |
'A', | |
) |
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
_CONTENT_TYPES = { '.png': 'image/png', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.jpe': 'image/jpeg' } | |
def _encode_multipart(**kw): | |
''' | |
Build a multipart/form-data body with generated random boundary. | |
''' | |
boundary = '----------%s' % hex(int(time.time() * 1000)) | |
data = [] | |
for k, v in kw.iteritems(): | |
data.append('--%s' % boundary) |
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.urls import RegexURLResolver, RegexURLPattern, get_resolver | |
from django.utils.regex_helper import normalize | |
r = get_resolver() | |
r._up = '' | |
urlpatterns = [r] | |
urls = [] | |
while urlpatterns: | |
u = urlpatterns.pop(0) |
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 metaclass_resolver(*classes, **options): | |
"""Metaclass resolver | |
Example: | |
SomeClass(metaclass_resolver(ClassMixin, BaseClass, SomeActionClass, some_field1=True, some_field2=42)): | |
pass | |
:param classes: | |
:param options: | |
:return: |
OlderNewer