def str_and_file( request, title: str = Form(...), description: str = Form(""), file: UploadedFile = File(...), ): return {"title": title, "data": file.read().decode()}
def test_multi_form_body( request, i: int = Form(...), s: str = Body("a-str"), data: TestData4 = Form(...), nested_data: TestData = Body(..., alias="nested-data"), ): return dict(s=s, i=i, data=data, nested_data=nested_data)
def register(request, username: str = Form(...), password1: str = Form(...), password2: str = Form(...)): if password1 == password2: user = User.objects.create_user(username=username, password=password1) return f'User {user.username} criado com sucesso' return f'As senhas nao coincidem'
def test_multi_body_form( request, i: int = Body(...), s: str = Form("a-str"), data: TestData4 = Body(..., **test_data4_extra), nested_data: TestData = Form(..., alias="nested-data"), ): return dict(s=s, i=i, data=data, nested_data=nested_data)
def test_multi_form_file( request, file: UploadedFile, i: int = Form(...), s: str = Form("a-str"), data: TestData4 = Form(..., **test_data4_extra), nested_data: TestData = Form(..., alias="nested-data"), ): return dict(s=s, i=i, data=data, nested_data=nested_data)
def test_multi_body_form_file( request, file: UploadedFile = File(...), i: int = Body(...), s: str = Form("a-str"), data: TestData4 = Body(...), nested_data: TestData = Form(..., alias="nested-data"), ): return dict(s=s, i=i, data=data, nested_data=nested_data)
def create_post(request, title: str = Form(...), content: str = Form(...), files: List[UploadedFile] = File(default=None)): post_create = Post.objects.create(owner=request.auth, title=title, content=content) if files: for f in files: images = PostImages.objects.create(post=post_create, image=f) return f'Post created' return 'Post Created'
def password_reset(request,email: str = Form(...)): user = models.User.objects.filter(email=email).first() try: mail_subject = 'Reset your password.' message = render_to_string('password_reset_form.html', { 'user':user, 'domain': request.get_host(), 'uid':urlsafe_base64_encode(force_bytes(user.pk)), 'token':account_activation_token.make_token(user), }) print(message) # email = EmailMessage( # mail_subject, message, to=[user.email] # ) # email.send() send_mail( mail_subject, message, settings.EMAIL_HOST_USER, [user.email], fail_silently=False, ) except: raise HttpError(422, "Введены неправильные данные(email)") return "Sent"
def post_moon_rental_new(request, rental: schema.NewMoonRental = Form(...)): if not request.user.has_perm("moons.add_moonrental"): return 403, "Permision Denied!" if models.MoonRental.objects.filter(moon_id=rental.moon_id, end_date__isnull=True).exists(): return 403, "Moon Already Rented!" try: char = EveCharacter.objects.get(character_id=rental.contact_id) except EveCharacter.DoesNotExist: return 403, "Character Unknown to Auth" try: corp = EveCorporationInfo.objects.get( corporation_id=rental.corporation_id) except EveCorporationInfo.DoesNotExist: return 403, "Corporation Unknown to Auth" new_rental = models.MoonRental.objects.create(moon_id=rental.moon_id, contact=char, corporation=corp, price=rental.price, start_date=timezone.now()) return 200, { "moon": { "id": new_rental.moon.moon_id, "name": new_rental.moon.name }, "system": { "id": new_rental.moon.system.system_id, "name": new_rental.moon.system.name }, "contact": new_rental.contact, "corporation": new_rental.corporation, "price": new_rental.price, "start_date": new_rental.start_date }
def listview1( request, query: List[int] = Query(...), form: List[int] = Form(...), ): return { "query": query, "form": form, }
def set_new_password(request, uidb64, token, password: str = Form(...), confirm_password: str = Form(...)): try: uid = force_text(urlsafe_base64_decode(uidb64)) user = User.objects.get(pk=uid) except(TypeError, ValueError, OverflowError, User.DoesNotExist): user = None if user is not None and account_activation_token.check_token(user, token): if(password==confirm_password): user.set_password(password) user.save(update_fields=['password']) else: return HttpResponse('Passwords are not same.') # return redirect('home') return HttpResponse('Your password has been set. Now you can login your account.') else: return HttpResponse('Link is invalid!')
def get_token(request, username: str = Form(...), password: str = Form(...)): if username == "admin" and password == "giraffethinnknslong": return {"token": "supersecret"}
def login(request, email: str = Form(...), password: str = Form(...)): user = get_object_or_404(User, email=email) if user.check_password(password): return (user.id,create_token(user.id))
def method_form_single(request, data: float = Form(...)): return dict(i=int(data), f=data)
def broken2(request, data: TestData = Form(...), p1: int = Form(...)): pass
def view4(request, form: OtherModel = Form(...)): assert isinstance(form, OtherModel) return form
def create_task2(request, start: int = Body(2), end: int = Form(1)): return [start, end]
def update(request, item_id: int, q: str, item: Item=Form(...)): return {"item_id": item_id, "item": item.dict(), "q": q}
def method_form_file(request, files: List[UploadedFile], data: Payload = Form(...)): return dict(i=data.i, f=data.f)
def method_form_body(request, i: int = Form(10), s: str = Body("10")): return dict(i=i, s=s)
def create(request, item: Item = Form(...)): return item
def form_operation(request, s: str = Form(...), i: int = Form(...)): return {"s": s, "i": i}
def login(request, username: str = Form(...), password: str = Form(...)): user = get_object_or_404(User, username=username) if check_password(password, user.password): return create_token(user.id)
def method_form(request, data: Payload = Form(...)): return dict(i=data.i, f=data.f)