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 MyForm(forms.Form): | |
... | |
def __init__(self, *args, **kwargs): | |
extra_fields = kwargs.pop('extra', 0) | |
super().__init__(*args, **kwargs) | |
if extra_fields and int(extra_fields) > 0: | |
for index in range(int(extra_fields)): | |
# generate extra fields in the number specified via extra_fields |
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
blank_choice = ((None, '---------'),) | |
STAR_CHOICES = blank_choice + tuple((float(i*0.5), str(float(i*0.5))) for i in range(1, 11)) |
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
@override_settings( | |
EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend', | |
CELERY_ALWAYS_EAGER=True) | |
def test_valid_create(self): | |
response = client.post( | |
self.create_view_name, | |
data=json.dumps(self.valid_payload), | |
content_type='application/json' | |
) | |
self.assertEqual(response.status_code, status.HTTP_200_OK) |
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
kwargs['count'] = { | |
v['status']: v['status__count'] | |
for v in | |
self.get_queryset().values('status').annotate(Count('status')).order_by('status') | |
} | |
# status = model choice field |
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
select.ordering__select(data-msg=trans('Заполните поле'), required) | |
+for('item in form.fields.field_name.queryset') | |
option(value=exp('item.pk'), data-price=exp('item.price')) | |
+exp item.title | |
.errors | |
+exp form.delivery_way.errors.as_text() |
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 PIL import Image | |
from PIL.ExifTags import TAGS, GPSTAGS | |
class ImageMetaData(object): | |
''' | |
Extract the exif data from any image. Data includes GPS coordinates, | |
Focal Length, Manufacture, and more. | |
''' | |
exif_data = None |
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
""" Function for applying watermarks to images. | |
Original found here: | |
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879 | |
""" | |
try: | |
import Image | |
import ImageEnhance | |
except ImportError: | |
try: |
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> | |
</head> | |
<body> |
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
a.header-top__login(href=exp("url('accounts:logout')")+"?next=" + exp("df.urlencode(request.path)")) |
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 __future__ import unicode_literals | |
import logging | |
from django.utils.translation import ugettext_lazy as _ | |
logger = logging.getLogger(__name__) | |
class TemplatesChoices: |