Skip to content

Instantly share code, notes, and snippets.

View DJWOMS's full-sized avatar

Омельченко Михаил | Omelchenko Mikhail DJWOMS

View GitHub Profile
@DJWOMS
DJWOMS / check_site.dart
Created September 25, 2024 20:39
1) Программа которая проверяет доступность веб-сайта по его URL-адресу. 2) Программа которая скачивает файл с указанного URL-адреса и сохраняет его на диск.
import 'dart:io';
import 'package:http/http.dart' as http;
void main() async {
checkSite('https://www.google.com');
checkSite('https://www.nonexistentsite.com');
}
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
DATABASE_NAME = 'track_db.sqlite'
engine = create_engine(f'sqlite:///{DATABASE_NAME}')
Session = sessionmaker(bind=engine)
Base = declarative_base()
serializer = CommentSerializer(data=data)
serializer.is_valid()
# True
serializer.validated_data
# {'content': 'My content', 'email': '[email protected]', 'created': datetime.datetime(2022, 09, 06, 16, 20, 09, 822243)}
import io
from rest_framework.parsers import JSONParser
stream = io.BytesIO(json)
data = JSONParser().parse(stream)
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"}'
serializer = CommentSerializer(comment)
print(serializer.data)
# {'email': u'[email protected]', 'content': u'foo bar', 'created': datetime.datetime(2012, 8, 22, 16, 20, 9, 822774)}
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):
"""
Учитывая словарь десериализованных значений поля, либо обновить существующий экземпляр модели или
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')
Авторизация\Регистрация
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
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"