Пример #1
0
    def save(self, *args, **kwargs):
        if not self.uuid:
            self.uuid = uuid4()
        if not self.pk and self.is_local:
            if not self.guid:
                self.guid = str(self.uuid)
            if not self.fid:
                self.fid = self.url

        if not self.fid and not self.handle:
            raise ValueError("Profile must have either a fid or a handle")

        if self.handle:
            # Ensure handle is *always* lowercase
            self.handle = self.handle.lower()
            if not validate_handle(self.handle):
                raise ValueError("Not a valid handle")

        # Set default pony images if image urls are empty
        if not self.image_url_small or not self.image_url_medium or not self.image_url_large:
            ponies = get_pony_urls()
            for idx, attr in enumerate(["image_url_large", "image_url_medium", "image_url_small"]):
                if not getattr(self, attr, None):
                    setattr(self, attr, ponies[idx])

        # Ensure keys are converted to str before saving
        self.rsa_private_key = decode_if_bytes(self.rsa_private_key)
        self.rsa_public_key = decode_if_bytes(self.rsa_public_key)

        super().save(*args, **kwargs)
Пример #2
0
    def save(self, *args, **kwargs):
        if not self.uuid:
            self.uuid = uuid4()
        if not self.pk and self.is_local:
            if not self.guid:
                self.guid = str(self.uuid)
            if not self.fid:
                self.fid = self.url

        if not self.fid and not self.handle:
            raise ValueError("Profile must have either a fid or a handle")

        if self.handle:
            # Ensure handle is *always* lowercase
            self.handle = self.handle.lower()
            if not validate_handle(self.handle):
                raise ValueError("Not a valid handle")

        # Set default pony images if image urls are empty
        if not self.image_url_small or not self.image_url_medium or not self.image_url_large:
            ponies = get_pony_urls()
            for idx, attr in enumerate(["image_url_large", "image_url_medium", "image_url_small"]):
                if not getattr(self, attr, None):
                    setattr(self, attr, ponies[idx])

        # Ensure keys are converted to str before saving
        self.rsa_private_key = decode_if_bytes(self.rsa_private_key)
        self.rsa_public_key = decode_if_bytes(self.rsa_public_key)

        super().save(*args, **kwargs)
Пример #3
0
 def save(self, *args, **kwargs):
     """Set default pony images if image urls are empty."""
     if not self.image_url_small or not self.image_url_medium or not self.image_url_large:
         ponies = get_pony_urls()
         for idx, attr in enumerate(
             ["image_url_large", "image_url_medium", "image_url_small"]):
             if not getattr(self, attr, None):
                 setattr(self, attr, ponies[idx])
     super().save(*args, **kwargs)
Пример #4
0
 def test_profile_image_urls_default_to_ponies(self):
     profile = ProfileFactory(image_url_small="",
                              image_url_medium="",
                              image_url_large="")
     ponies = get_pony_urls()
     urls = [
         profile.image_url_large, profile.image_url_medium,
         profile.image_url_small
     ]
     self.assertEqual(urls, ponies)
def forward(apps, schema_editor):
    """Fill empty profile images with ponies according to new save logic."""
    Profile = apps.get_model("users", "Profile")
    ponies = get_pony_urls()
    for profile in Profile.objects.filter(
        Q(image_url_small="") | Q(image_url_medium="") | Q(image_url_large="")
    ):
        for idx, attr in enumerate(["image_url_large", "image_url_medium", "image_url_small"]):
            if not getattr(profile, attr, None):
                setattr(profile, attr, ponies[idx])
        profile.save()
Пример #6
0
 def save(self, *args, **kwargs):
     # Protect against empty guids which the search indexing would crash on
     if not self.guid:
         raise ValueError("Profile must have a guid!")
     # Set default pony images if image urls are empty
     if not self.image_url_small or not self.image_url_medium or not self.image_url_large:
         ponies = get_pony_urls()
         for idx, attr in enumerate(
             ["image_url_large", "image_url_medium", "image_url_small"]):
             if not getattr(self, attr, None):
                 setattr(self, attr, ponies[idx])
     super().save(*args, **kwargs)
Пример #7
0
def forward(apps, schema_editor):
    """Fill empty profile images with ponies according to new save logic."""
    Profile = apps.get_model("users", "Profile")
    ponies = get_pony_urls()
    for profile in Profile.objects.filter(
            Q(image_url_small="") | Q(image_url_medium="")
            | Q(image_url_large="")):
        for idx, attr in enumerate(
            ["image_url_large", "image_url_medium", "image_url_small"]):
            if not getattr(profile, attr, None):
                setattr(profile, attr, ponies[idx])
        profile.save()
Пример #8
0
    def save(self, *args, **kwargs):
        if not self.uuid:
            self.uuid = uuid4()
        if not self.pk and self.is_local:
            if not self.guid:
                self.guid = str(self.uuid)
            if not self.fid:
                self.fid = self.user.url
            # Default protocol for all new profiles
            self.protocol = "activitypub"

        if not self.fid and not self.handle:
            raise ValueError("Profile must have either a fid or a handle")

        if self.handle:
            # Ensure handle is *always* lowercase
            self.handle = self.handle.lower()
            if not validate_handle(self.handle):
                raise ValueError("Not a valid handle")
        else:
            self.handle = None

        if self.guid == "":
            self.guid = None

        # Set default pony images if image urls are empty
        if not self.image_url_small or not self.image_url_medium or not self.image_url_large:
            ponies = get_pony_urls()
            for idx, attr in enumerate(
                ["image_url_large", "image_url_medium", "image_url_small"]):
                if not getattr(self, attr, None):
                    setattr(self, attr, ponies[idx])

        # Ensure keys are converted to str before saving
        self.rsa_private_key = decode_if_bytes(self.rsa_private_key)
        self.rsa_public_key = decode_if_bytes(self.rsa_public_key)

        # Set default federation endpoints for local users
        if self.is_local:
            if not self.inbox_private:
                self.inbox_private = f"{self.fid}inbox/"
            if not self.inbox_public:
                self.inbox_public = f"{settings.SOCIALHOME_URL}{reverse('federate:receive-public')}"

        super().save(*args, **kwargs)
Пример #9
0
 def save(self, *args, **kwargs):
     # Protect against empty guids which the search indexing would crash on
     if not self.guid:
         raise ValueError("Profile must have a guid!")
     if not validate_handle(self.handle):
         raise ValueError("Not a valid handle")
     # Set default pony images if image urls are empty
     if not self.image_url_small or not self.image_url_medium or not self.image_url_large:
         ponies = get_pony_urls()
         for idx, attr in enumerate(["image_url_large", "image_url_medium", "image_url_small"]):
             if not getattr(self, attr, None):
                 setattr(self, attr, ponies[idx])
     # Ensure handle is *always* lowercase
     self.handle = self.handle.lower()
     # Ensure keys are converted to str before saving
     self.rsa_private_key = decode_if_bytes(self.rsa_private_key)
     self.rsa_public_key = decode_if_bytes(self.rsa_public_key)
     super().save(*args, **kwargs)
Пример #10
0
 def test_get_image_urls_returns_ponies(self):
     profile = ProfileFactory(guid="1234")
     ponies = get_pony_urls()
     urls = profile.get_image_urls()
     assert urls == ponies
Пример #11
0
 def get_image_urls(self):
     """Get profile image urls or ponies, if none."""
     if self.image_url_large and self.image_url_medium and self.image_url_small:
         return self.image_url_large, self.image_url_medium, self.image_url_small
     # Ponies are nice
     return get_pony_urls()
Пример #12
0
 def test_profile_image_urls_default_to_ponies(self):
     profile = ProfileFactory(image_url_small="", image_url_medium="", image_url_large="")
     ponies = get_pony_urls()
     urls = [profile.image_url_large, profile.image_url_medium, profile.image_url_small]
     self.assertEqual(urls, ponies)