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 AddCartItem(View): | |
"""Добавление товара в карзину""" | |
def check_cart(self, request): | |
if request.user.is_authenticated: | |
cart = Cart.objects.get(user=request.user, accepted=False) | |
else: | |
session_cart = request.session.get('cart') | |
if not session_cart: | |
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore |
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 CategoryProductVue(View): | |
"""Список товаров из категории для vue""" | |
def get(self, request): | |
return render(request, "shop/vue/list-product-vue.html") | |
def post(self, request): | |
slug = request.POST.get("slug") | |
node = Category.objects.get(slug=slug) | |
if Product.objects.filter(category__slug=slug).exists(): | |
products = Product.objects.filter(category__slug=slug) |
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 .models import Category | |
def list_categoryes(request): | |
"""Список категорий в меню""" | |
return {"menu_categoryes": Category.objects.all()} |
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
Создание пользователя | |
--------------------- | |
adduser username | |
usermod -aG sudo username | |
group username | |
su username | |
--------------------------------------- | |
Компиляции python 3.6 | |
---------------------- | |
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev |
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 User(UserBase): | |
id: int | |
is_active: bool | |
class Config: | |
orm_mode = True | |
async def create_user(user: schemas.UserCreate): | |
fake_hashed_password = user.password + "notreallyhashed" |
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
Авторизация\Регистрация | |
https://github.com/jazzband/django-oauth-toolkit | |
https://github.com/pennersr/django-allauth | |
https://github.com/sunscrapers/djoser | |
https://github.com/django-guardian/django-guardian | |
https://github.com/flavors/django-graphql-jwt | |
Защита входа | |
https://github.com/jazzband/django-axes | |
https://github.com/jazzband/django-defender |
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 Comment(object): | |
def __init__(self, email, content, created=None): | |
self.email = email | |
self.content = content | |
self.created = created or datetime.datetime.now() | |
comment = Comment(email='[email protected]', content='My content') |
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 rest_framework import serializers | |
class CommentSerializer(serializers.Serializer): | |
email = serializers.EmailField() | |
content = serializers.CharField(max_length=200) | |
created = serializers.DateTimeField() | |
def restore_object(self, attrs, instance=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
serializer = CommentSerializer(comment) | |
print(serializer.data) | |
# {'email': u'[email protected]', 'content': u'foo bar', 'created': datetime.datetime(2012, 8, 22, 16, 20, 9, 822774)} |
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 rest_framework.renderers import JSONRenderer | |
json = JSONRenderer().render(serializer.data) | |
print(json) | |
# '{"email": "[email protected]", "content": "foo bar", "created": "2012-08-22T16:20:09.822"}' |
OlderNewer