Add a field site.domain, so that profiles can be labeled as username@domain, WebFinger style

This commit is contained in:
Danielle McLean 2017-10-31 13:46:52 +11:00
parent 76305543fa
commit 8a9f41759e
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
5 changed files with 61 additions and 5 deletions

View file

@ -28,7 +28,7 @@
{% for s in entry.syndications.all %} {% for s in entry.syndications.all %}
<a class="u-syndication" href="{{ s.url }}"> <a class="u-syndication" href="{{ s.url }}">
<i class="{{ s.profile.site.icon }}"></i> <i class="{{ s.profile.site.icon }}"></i>
{{ s.profile.name }} {{ s.profile }}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>

View file

@ -4,7 +4,7 @@ from .models import Key, Profile, Site, User
class SiteAdmin(admin.ModelAdmin): class SiteAdmin(admin.ModelAdmin):
list_display = ('name', 'icon', 'url') list_display = ('name', 'icon', 'domain', 'url_template')
class KeyInline(admin.TabularInline): class KeyInline(admin.TabularInline):

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-31 02:36
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0005_auto_20171023_0158'),
]
operations = [
migrations.RenameField(
model_name='site',
old_name='url',
new_name='url_template',
),
migrations.AddField(
model_name='site',
name='domain',
field=models.CharField(default='', max_length=100),
preserve_default=False,
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-31 02:47
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0006_auto_20171031_1336'),
]
operations = [
migrations.AlterField(
model_name='site',
name='domain',
field=models.CharField(blank=True, max_length=100),
),
]

View file

@ -11,7 +11,15 @@ def avatar_path(instance, name):
class Site(models.Model): class Site(models.Model):
name = models.CharField(max_length=100, unique=True) name = models.CharField(max_length=100, unique=True)
icon = models.CharField(max_length=100) icon = models.CharField(max_length=100)
url = models.CharField(max_length=100) domain = models.CharField(max_length=100, blank=True)
url_template = models.CharField(max_length=100)
def format(self, username=''):
return self.url_template.format(domain=self.domain, username=username)
@property
def url(self):
return self.format()
def __str__(self): def __str__(self):
return self.name return self.name
@ -73,7 +81,9 @@ class Profile(models.Model):
display_name = models.CharField(max_length=100, blank=True) display_name = models.CharField(max_length=100, blank=True)
def __str__(self): def __str__(self):
return self.url if self.site.domain:
return self.name + '@' + self.site.domain
return self.name
@property @property
def name(self): def name(self):
@ -81,7 +91,7 @@ class Profile(models.Model):
@property @property
def url(self): def url(self):
return self.site.url.format(username=self.username) return self.site.format(username=self.username)
class Meta: class Meta:
ordering = ('site', 'username') ordering = ('site', 'username')