request.py 760 B

123456789101112131415161718192021222324252627282930313233343536
  1. from dataclasses import dataclass
  2. from dataclasses_json import dataclass_json
  3. from datetime import datetime
  4. from typing import List, Optional
  5. @dataclass_json
  6. @dataclass
  7. class User:
  8. name: str
  9. password: str
  10. @classmethod
  11. def from_form(cls, form):
  12. return cls(name=form["username"], password=form["password"],)
  13. @dataclass_json
  14. @dataclass
  15. class Link:
  16. url: str
  17. name: str
  18. description: str
  19. private: bool
  20. tags: List[str]
  21. created: Optional[datetime] = None
  22. @classmethod
  23. def from_form(cls, form):
  24. return cls(
  25. url=form["url"],
  26. name=form["name"],
  27. description=form["description"],
  28. private="private" in form,
  29. tags=form["tags"].split(),
  30. )