Skip to content

Commit

Permalink
Create a user website model, and express an intention about icons.
Browse files Browse the repository at this point in the history
  • Loading branch information
colons committed Nov 6, 2023
1 parent d574b70 commit e9802de
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions nkdsu/apps/vote/migrations/0022_userwebsite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.7 on 2023-11-06 10:33

from django.db import migrations, models
import django.db.models.deletion
import nkdsu.apps.vote.models


class Migration(migrations.Migration):
dependencies = [
('vote', '0021_track_archival'),
]

operations = [
migrations.CreateModel(
name='UserWebsite',
fields=[
(
'id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
('url', models.URLField()),
(
'profile',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='websites',
to='vote.profile',
),
),
],
bases=(nkdsu.apps.vote.models.CleanOnSaveMixin, models.Model),
),
]
38 changes: 38 additions & 0 deletions nkdsu/apps/vote/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,44 @@ def get_toggle_abuser_url(self) -> str:
return reverse('vote:admin:toggle_local_abuser', kwargs={'user_id': self.pk})


class UserWebsite(CleanOnSaveMixin, models.Model):
url = models.URLField()
profile = models.ForeignKey(Profile, related_name='websites', on_delete=models.CASCADE)

@property
def icon(self) -> str:
"""
Return an appropriate identify for for what kind of URL this is.
>>> UserWebsite(url='https://someone.tumblr.com').icon
'tumblr'
>>> UserWebsite(url='https://tumblr.com/someone').icon
'tumblr'
>>> UserWebsite(url='https://cohost.org/someone').icon
'cohost'
>>> UserWebsite(url='https://bsky.app/profile/someone').icon
'bsky'
>>> UserWebsite(url='https://bsky.app/profile/someone').icon
'bsky'
>>> UserWebsite(url='https://www.instagram.com/someone').icon
'instagram'
>>> UserWebsite(url='https://www.threads.net/@someone').icon
'threads'
>>> UserWebsite(url='https://linkedin.com/in/someone-jsioadj/').icon
'linkedin'
>>> UserWebsite(url='https://facebook.com/someone').icon
'facebook'
>>> UserWebsite(url='https://www.youtube.com/@someone').icon
'youtube'
>>> UserWebsite(url='https://www.youtube.com/channel/someone/').icon
'youtube'
>>> UserWebsite(url='https://www.twitch.tv/someone/').icon
'twitch'
>>> UserWebsite(url='https://website.tld').icon
'website'
"""


def art_path(i: Track, f: str) -> str:
return 'art/bg/%s.%s' % (i.pk, f.split('.')[-1])

Expand Down

0 comments on commit e9802de

Please sign in to comment.