Skip to content

Commit

Permalink
cleaned up 'Profile' model
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasofthings committed Aug 12, 2024
1 parent 4c9d875 commit db741ee
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion webapp/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class ProfileAdmin(admin.ModelAdmin):
"user",
"consent",
"public",
"ap_id",
# "ap_id",
)


Expand Down
2 changes: 1 addition & 1 deletion webapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Meta:
"dob",
"img",
"gravatar",
"follows",
# "follows",
]


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.7 on 2024-08-12 08:15

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("webapp", "0044_remove_actor_flw_follow_actor_follows_delete_fllwng"),
]

operations = [
migrations.RemoveField(
model_name="profile",
name="ap_id",
),
migrations.RemoveField(
model_name="profile",
name="follows",
),
]
33 changes: 16 additions & 17 deletions webapp/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
slug = models.SlugField(null=True, help_text=_("Slug"))

follows = models.ManyToManyField(
"self", related_name="followed_by", symmetrical=False, blank=True
)

public = models.BooleanField(
default=False, help_text=_("Make Profile Profile public?")
Expand All @@ -63,13 +60,6 @@ class Profile(models.Model):
)
bio = models.TextField(blank=True, help_text=_("Short Bio"))

ap_id = models.CharField(
max_length=255,
blank=True,
help_text=_("ActivityPub ID"),
unique=True,
) # noqa: E501

public_key_pem = models.TextField(blank=True, help_text=_("Public Key"))
private_key_pem = models.TextField(blank=True, help_text=_("Private Key"))

Expand All @@ -86,6 +76,19 @@ class Profile(models.Model):
default="https://storage.cloud.google.com/media.pramari.de/user/default.png", # noqa: E501
)

## The following is deprecated and has been moved to the Actor model

# follows = models.ManyToManyField(
# "self", related_name="followed_by", symmetrical=False, blank=True
# )

# ap_id = models.CharField(
# max_length=255,
# blank=True,
# help_text=_("ActivityPub ID"),
# unique=True,
# ) # noqa: E501

@property
def imgurl(self):
"""
Expand All @@ -103,23 +106,21 @@ def imgurl(self):
"""
size = 80

# Set your variables here
if self.user.is_verified: # noqa: no-member
email = EmailAddress.objects.get(
user=self.user, verified=True, primary=True
)
else:
return "https://storage.cloud.google.com/media.pramari.de/user/default.png" # noqa: E501
return "user/default.png" # noqa: E501

# construct the url
if self.gravatar is False:
return staticfiles_storage.url(self.img)
else:
if self.gravatar is True
hashvalue = hashlib.md5(
str(email).lower().encode("utf-8")
).hexdigest() # noqa: E501
size = urllib.parse.urlencode({"d": email, "s": str(size)})
return f"https://www.gravatar.com/avatar/{hashvalue}?{size}"
return staticfiles_storage.url(self.img)

def __str__(self):
"""
Expand All @@ -138,8 +139,6 @@ def save(self, *args, **kwargs):
"""
if not self.slug:
self.slug = slugify(self.user.username) # pylint: disable=E1101
if not self.ap_id: # and self.user.is_verified:
self.ap_id = f"https://pramari.de/@{self.slug}"
return super().save(*args, **kwargs) # Call save()

@property
Expand Down

0 comments on commit db741ee

Please sign in to comment.