models.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from django.db import models
  2. from abid_utils.models import ABIDModel, ABIDField, AutoDateTimeField, ModelWithHealthStats
  3. from django.conf import settings
  4. # class Persona(ABIDModel, ModelWithHealthStats):
  5. # """Aka a "SessionType", its a template for a crawler browsing session containing some config."""
  6. # abid_prefix = 'prs_'
  7. # abid_ts_src = 'self.created_at'
  8. # abid_uri_src = 'self.name'
  9. # abid_subtype_src = 'self.created_by'
  10. # abid_rand_src = 'self.id'
  11. # id = models.UUIDField(primary_key=True, default=None, null=False, editable=False, unique=True, verbose_name='ID')
  12. # abid = ABIDField(prefix=abid_prefix)
  13. # created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None, null=False)
  14. # created_at = AutoDateTimeField(default=None, null=False, db_index=True)
  15. # modified_at = models.DateTimeField(auto_now=True)
  16. # name = models.CharField(max_length=100, blank=False, null=False, editable=False)
  17. # persona_dir = models.FilePathField(path=settings.PERSONAS_DIR, allow_files=False, allow_folders=True, blank=True, null=False, editable=False)
  18. # config = models.JSONField(default=dict)
  19. # # e.g. {
  20. # # USER_AGENT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
  21. # # COOKIES_TXT_FILE: '/path/to/cookies.txt',
  22. # # CHROME_USER_DATA_DIR: '/path/to/chrome/user/data/dir',
  23. # # CHECK_SSL_VALIDITY: False,
  24. # # SAVE_ARCHIVE_DOT_ORG: True,
  25. # # CHROME_BINARY: 'chromium'
  26. # # ...
  27. # # }
  28. # # domain_allowlist = models.CharField(max_length=1024, blank=True, null=False, default='')
  29. # # domain_denylist = models.CharField(max_length=1024, blank=True, null=False, default='')
  30. # class Meta:
  31. # verbose_name = 'Session Type'
  32. # verbose_name_plural = 'Session Types'
  33. # unique_together = (('created_by', 'name'),)
  34. # def clean(self):
  35. # self.persona_dir = settings.PERSONAS_DIR / self.name
  36. # assert self.persona_dir == settings.PERSONAS_DIR / self.name, f'Persona dir {self.persona_dir} must match settings.PERSONAS_DIR / self.name'
  37. # # make sure config keys all exist in FLAT_CONFIG
  38. # # make sure config values all match expected types
  39. # pass
  40. # def save(self, *args, **kwargs):
  41. # self.full_clean()
  42. # # make sure basic file structure is present in persona_dir:
  43. # # - PERSONAS_DIR / self.name /
  44. # # - chrome_profile/
  45. # # - chrome_downloads/
  46. # # - chrome_extensions/
  47. # # - cookies.txt
  48. # # - auth.json
  49. # # - config.json # json dump of the model
  50. # super().save(*args, **kwargs)