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
# -- coding: utf-8 -- | |
import time | |
from celery.utils.log import get_task_logger | |
from constance import config | |
from django.conf import settings | |
from django.db import IntegrityError | |
from django.utils import timezone | |
from vk.exceptions import VkException |
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
""" | |
Task management forms | |
""" | |
from django import forms | |
from django.contrib.auth.models import User | |
from task_management.fields import MultiFileField | |
from task_management.helpers import send_message | |
from task_management.models import Task, TaskAttachment, TaskComment, \ |
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
""" | |
Using lxml for a web pages scrapping | |
""" | |
def process_goods_page(self, document, url): | |
""" Scrapping of goods on the html page """ | |
items = [] | |
if settings.DEBUG: | |
try: |
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
""" | |
Django signals example | |
""" | |
import logging | |
from django.dispatch import receiver | |
from django.dispatch import Signal | |
from django.db.models.signals import pre_save | |
from statistics.models import Client, Dealer |
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
# -*- coding: utf-8 -*- | |
""" | |
Selenium loading module | |
""" | |
import os | |
import time | |
import psutil | |
import logging | |
from django.conf import settings |
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 BulkViewSetMixin(object): | |
""" | |
Mixin for bulk create and update operations. | |
You need used Bulk routers for providing routing to bulk operations, | |
for example BulkNestedSimpleRouter. | |
""" | |
def create(self, request, *args, **kwargs): | |
bulk = isinstance(request.data, list) | |
if not bulk: |
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 ForeignKeySerializerMixin(object): | |
""" | |
Mixin for processing foreign key field serializers | |
""" | |
class Meta: | |
foreign_key_fields = () | |
def is_valid(self, raise_exception=False): | |
# TODO: костыль, после выхода 3.4.8 посмотреть решён ли баг | |
# DRF parent-level validation of nested serializer bug |
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 BaseTranslationMixin(object): | |
def __init__(self, instance=None, data=empty, **kwargs): | |
if not self.Meta.model_translation: | |
raise AttributeError( | |
'You must define Meta.model_translation attribute') | |
super().__init__(instance=instance, data=data, **kwargs) | |
@staticmethod | |
def get_translation_fields(languages, fields): |
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 M2MNestedSerializerMixin(object): | |
""" | |
Nested serializer mixin for M2M fields. | |
You need mix serializer mixin to you serializer and append M2M fields to | |
Meta.m2m_nested_fields. | |
""" | |
m2m_nested_objects = {} | |
class Meta: |
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
@deconstructible | |
class VersioningFileSystemStorage(FileSystemStorage): | |
""" The modified version of the original :class:`FileSystemStorage` will | |
append a hash to any file being saved regardless of whether the original | |
file name is already taken or not so any file saved will have it. | |
The backend is meant to be used with model versioning to provide simple | |
file versioning as well. | |
A security consideration of the approach is that though there is a hash, | |
which cannot be guessed manually, the ``MEDIA_ROOT`` directory is usually | |
world-readable. So potentially, an automatic guessing could reveal |
OlderNewer