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
| class SellProductAlphaForm(forms.ModelForm): | |
| category = TreeNodeChoiceField( | |
| queryset=SellCategory.objects.all(), | |
| widget=widgets.Select(attrs={ | |
| 'class': 'form-control' | |
| }) | |
| ) | |
| class Meta: | |
| model = SellProduct |
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 urllib.parse import parse_qs, urlparse | |
| def get_hash_from_url(url: str) -> str: | |
| parsed = urlparse(url) | |
| if parsed.query: | |
| _hashes = parse_qs(parsed.query).get('v') | |
| _hash = _hashes[0] | |
| else: | |
| _hash = parsed.path | |
| _hash = _hash.lstrip('/') |
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
| {% load locale_tag %} | |
| .... | |
| {% get_available_languages as languages %} | |
| <div class="header-lang-switch"> | |
| <ul class="nav navbar-nav"> | |
| {% for lang_code, lang_name in languages %} | |
| <li class="nav-item"> |
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
| file_storage = FileSystemStorage( | |
| location=settings.PRIVATE_UPLOAD_ROOT, | |
| ) | |
| def document_upload_to(instance, filename): | |
| return upload_path('project/document', instance, filename) | |
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
| @admin.register(Brief) | |
| class BriefAdmin(BaseAdmin, NestedModelAdmin): | |
| def answers(self, request, queryset=None, pk=None): | |
| brief = get_object_or_404(Brief, pk=pk) | |
| return render(request, 'brief/admin/brief-answers.html', { | |
| 'brief': brief | |
| }) |
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
| class JobAPIView(ListAPIView): | |
| def list(self, request: Request, *args: Any, **kwargs: Any) -> Response: | |
| if request.user: | |
| return self._list_authorized(request, *args, **kwargs) | |
| else: | |
| return self._list_unauthorized(request, *args, **kwargs) | |
| def _list_authorized(self, request: Request, *args: Any, **kwargs: Any): |
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
| class CategoryView(ListView): | |
| template_name = 'catalog/category.html' | |
| queryset = Product.objects.filter(archived=False) | |
| def dispatch(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: | |
| slug = kwargs.get('slug') | |
| self.category = Category.objects.get(slug=slug) | |
| return super().dispatch(request, *args, **kwargs) | |
| def get_queryset(self) -> QuerySet: |
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 rest_framework import serializers | |
| class BaseModelsSerializer(serializers.ModelSerializer): | |
| _fields = None | |
| def __init__(self, fields=None, *args, **kwargs): | |
| self._fields = fields | |
| super().__init__(*args, **kwargs) |
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', | |
| 'django.templatetags.static', | |
| ], |
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.contrib import admin | |
| from django.utils.safestring import mark_safe | |
| from catalog.models import Photo | |
| @admin.register(Photo) | |
| class PhotoAdmin(admin.ModelAdmin): | |
| list_display = ['show_image', 'post'] | |
| list_filter = ['post'] |