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 api.managers import BasicManager | |
| from api.utils import soft_delete_related_objects | |
| from django.contrib.admin.utils import NestedObjects | |
| from django.contrib.auth.models import AbstractUser | |
| from django.core.validators import RegexValidator | |
| from django.db import DEFAULT_DB_ALIAS, models | |
| from django.db.models.fields import DateField | |
| from django.urls import reverse | |
| from django.utils import timezone | |
| from django.utils.translation import gettext_lazy as _ |
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
| import re | |
| from rest_framework import serializers | |
| class DzPhoneFormatValidator(object): | |
| def __call__(self, phone): | |
| PHONE_REGEXP = re.compile("(0|\+213|00213){1}([1-9]){1}([0-9]{8})") | |
| if not PHONE_REGEXP.match(phone): | |
| message = "Invalid phone format" |
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
| requirements_file = 'base.pip' | |
| requirements = open(requirements_file, 'r') | |
| content = requirements.read().splitlines() | |
| content = list(set(content)) | |
| content.sort(key=lambda y: y.lower()) | |
| content = '\n'.join(content) | |
| file = open(requirements_file, 'w') | |
| file.write(content) |
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
| CRON_REGEX = r"((((\d+,)+\d+|((\d+|\*)(\/|-)\d+)|\d+|\*) ?){5,7})" |
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 update(self, instance, validated_data): | |
| for key, value in validated_data.items(): | |
| setattr(instance, key, value) | |
| instance.save() | |
| return instance |
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.core.validators import RegexValidator | |
| from django.db import models | |
| from django.utils.crypto import get_random_string | |
| def get_random_phone(): | |
| return '07'+ get_random_string(length=8, allowed_chars='123456789') | |
| phone_pattern_validator = RegexValidator('(0|\+213|00213){1}([1-9]){1}([0-9]{8})', message='Invalid phone format') |
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
| phone_regex = r'(0|\+213|00213){1}([1-9]){1}([0-9]{8})' |
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 refresh(instance): | |
| """Select and return instance from database. | |
| Usage: ``instance = refresh(instance)`` | |
| """ | |
| return instance.__class__.objects.get(pk=instance.pk) | |
| def update(instance, **data): |
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
| python -c 'import random;import string; print("".join(random.SystemRandom().choice(string.digits + string.ascii_letters + string.punctuation) for _ in range(50)))' |
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 BookCover(generics.RetrieveAPIView, generics.CreateAPIView): | |
| lookup_url_kwarg = 'book_id' | |
| def get_object(self): | |
| try: | |
| book = Book.objects.get(pk=self.kwargs.get('book_id')) | |
| except Book.DoesNotExist: | |
| raise exceptions.NotFound | |
| return book |
NewerOlder