Models.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional
  4. class BaseModel:
  5. def __init__(self, **kwargs):
  6. self.__dict__.update(kwargs)
  7. ## OAuth OAuth2Settings data template.
  8. class OAuth2Settings(BaseModel):
  9. CALLBACK_PORT = None # type: Optional[int]
  10. OAUTH_SERVER_URL = None # type: Optional[str]
  11. CLIENT_ID = None # type: Optional[str]
  12. CLIENT_SCOPES = None # type: Optional[str]
  13. CALLBACK_URL = None # type: Optional[str]
  14. AUTH_DATA_PREFERENCE_KEY = "" # type: str
  15. AUTH_SUCCESS_REDIRECT = "https://ultimaker.com" # type: str
  16. AUTH_FAILED_REDIRECT = "https://ultimaker.com" # type: str
  17. ## User profile data template.
  18. class UserProfile(BaseModel):
  19. user_id = None # type: Optional[str]
  20. username = None # type: Optional[str]
  21. profile_image_url = None # type: Optional[str]
  22. ## Authentication data template.
  23. class AuthenticationResponse(BaseModel):
  24. """Data comes from the token response with success flag and error message added."""
  25. success = True # type: bool
  26. token_type = None # type: Optional[str]
  27. access_token = None # type: Optional[str]
  28. refresh_token = None # type: Optional[str]
  29. expires_in = None # type: Optional[str]
  30. scope = None # type: Optional[str]
  31. err_message = None # type: Optional[str]
  32. received_at = None # type: Optional[str]
  33. ## Response status template.
  34. class ResponseStatus(BaseModel):
  35. code = 200 # type: int
  36. message = "" # type: str
  37. ## Response data template.
  38. class ResponseData(BaseModel):
  39. status = None # type: ResponseStatus
  40. data_stream = None # type: Optional[bytes]
  41. redirect_uri = None # type: Optional[str]
  42. content_type = "text/html" # type: str
  43. ## Possible HTTP responses.
  44. HTTP_STATUS = {
  45. "OK": ResponseStatus(code = 200, message = "OK"),
  46. "NOT_FOUND": ResponseStatus(code = 404, message = "NOT FOUND"),
  47. "REDIRECT": ResponseStatus(code = 302, message = "REDIRECT")
  48. }