models.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from datetime import timedelta
  2. import pytz
  3. from django.contrib.auth import get_user_model
  4. from django.db import models
  5. from django_extensions.db.models import TimeStampedModel
  6. from encrypted_field import EncryptedField
  7. from profiles.constants import PRETTY_TIMEZONE_CHOICES
  8. User = get_user_model()
  9. BNULL = {"blank": True, "null": True}
  10. class UserProfile(TimeStampedModel):
  11. user = models.OneToOneField(
  12. User, on_delete=models.CASCADE, related_name="profile"
  13. )
  14. timezone = models.CharField(
  15. max_length=255, choices=PRETTY_TIMEZONE_CHOICES, default="UTC"
  16. )
  17. lastfm_username = models.CharField(max_length=255, **BNULL)
  18. lastfm_password = EncryptedField(**BNULL)
  19. lastfm_auto_import = models.BooleanField(default=False)
  20. retroarch_path = models.CharField(max_length=255, **BNULL)
  21. retroarch_auto_import = models.BooleanField(default=False)
  22. archivebox_username = models.CharField(max_length=255, **BNULL)
  23. archivebox_password = EncryptedField(**BNULL)
  24. archivebox_url = models.CharField(max_length=255, **BNULL)
  25. bgg_username = models.CharField(max_length=255, **BNULL)
  26. todoist_auth_key = EncryptedField(**BNULL)
  27. todoist_state = EncryptedField(**BNULL)
  28. todoist_user_id = models.CharField(max_length=100, **BNULL)
  29. redirect_to_webpage = models.BooleanField(default=True)
  30. def __str__(self):
  31. return f"User profile for {self.user}"
  32. @property
  33. def tzinfo(self):
  34. return pytz.timezone(self.timezone)