This file contains hidden or 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/python | |
| # -*- coding: utf-8 -*- | |
| # habraproxy.py — это простейший http-прокси-сервер, запускаемый локально | |
| # (порт на ваше усмотрение), который показывает содержимое страниц Хабра. | |
| # С одним исключением: после каждого слова из шести букв должен стоять | |
| # значок «™». | |
| # Примерно так: | |
| # | |
| # http://habrahabr.ru/company/yandex/blog/258673/ |
This file contains hidden or 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.translation import ugettext_lazy as _ | |
| # models.py | |
| class Car(models.Model): | |
| CATEGORY_A = 'A' | |
| CATEGORY_B = 'B' | |
| CATEGORY_C = 'C' | |
| CATEGORY_D = 'D' | |
| CATEGORIES = ( |
This file contains hidden or 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
| TEMPLATES = [ | |
| { | |
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
| 'DIRS': [], | |
| 'APP_DIRS': True, | |
| 'OPTIONS': { | |
| 'builtins': [ | |
| 'django.templatetags.i18n' | |
| ], | |
| 'context_processors': [ |
This file contains hidden or 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 import template | |
| from django.conf import settings | |
| register = template.Library() | |
| @register.filter | |
| def chlocale(path, code): | |
| keys = [] | |
| for l in settings.LANGUAGES: | |
| keys.append(l[0]) |
This file contains hidden or 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 imagekit.models import ImageSpecField | |
| from imagekit.processors import SmartResize, ResizeToFit, Adjust | |
| class Store(models.Model): | |
| user = models.ForeignKey( | |
| User, | |
| on_delete=models.CASCADE | |
| ) | |
| title = models.CharField(max_length=250) |
This file contains hidden or 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 home(request): | |
| data = {} | |
| # variant 1 | |
| featured = SellProduct.objects.filter(is_featured=True, status=SellProduct.STATUS_ACTIVE).order_by('?')[:4] | |
| popular = SellProduct.objects.filter(status=SellProduct.STATUS_ACTIVE).exclude(pk__in=featured.values_list('pk', flat=True)).order_by('-views_count')[:4] | |
| # variant 2 | |
| featured = SellProduct.objects.filter(is_featured=True, status=SellProduct.STATUS_ACTIVE).order_by('?')[:4] | |
| popular = SellProduct.objects.filter(status=SellProduct.STATUS_ACTIVE).exclude(pk__in=list(featured.values_list('pk', flat=True))).order_by('-views_count')[:4] |
This file contains hidden or 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_extra_dict(self): | |
| request = self.context['request'] | |
| fields = {} | |
| if request.user.is_staff(): | |
| fields['hr_unread'] = serializers.SerializerMethodField() | |
| fields['last_service_comment'] = serializers.SerializerMethodField() | |
| fields['achievement'] = serializers.SerializerMethodField() | |
| fields['grade_progress'] = serializers.SerializerMethodField() |
This file contains hidden or 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
| {% extends 'catalog/store/_store.html' %} | |
| {% load paginator %} | |
| {% block content %} | |
| <div class="row mb-3"> | |
| <div class="col"> | |
| <div class="card"> | |
| <div class="card-body"> | |
| <div class="row"> |
This file contains hidden or 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
| # --------------------------------------------- | |
| # Logging settings | |
| # --------------------------------------------- | |
| LOGGING = { | |
| 'version': 1, | |
| 'disable_existing_loggers': False, | |
| 'formatters': { | |
| 'console': { | |
| 'format': '\n%(name)s: %(levelname)s %(asctime)s [%(module)s:%(lineno)s] --> \n%(message)s\n' | |
| }, |
This file contains hidden or 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
| # utils.py | |
| import uuid | |
| def upload_path(prefix, instance, filename): | |
| ext = filename.split('.')[-1] | |
| filename = "%s.%s" % (uuid.uuid4().hex[:16], ext.lower()) | |
| return '{prefix}/{super_short}/{short}/{long}/{filename}'.format( | |
| prefix=prefix, | |
| super_short=filename[:2], | |
| short=filename[:4], |
OlderNewer