forked from 00dani/lemoncurry
Add a field site.domain, so that profiles can be labeled as username@domain, WebFinger style
This commit is contained in:
parent
76305543fa
commit
8a9f41759e
5 changed files with 61 additions and 5 deletions
|
@ -28,7 +28,7 @@
|
|||
{% for s in entry.syndications.all %}
|
||||
<a class="u-syndication" href="{{ s.url }}">
|
||||
<i class="{{ s.profile.site.icon }}"></i>
|
||||
{{ s.profile.name }}
|
||||
{{ s.profile }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@ from .models import Key, Profile, Site, User
|
|||
|
||||
|
||||
class SiteAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'icon', 'url')
|
||||
list_display = ('name', 'icon', 'domain', 'url_template')
|
||||
|
||||
|
||||
class KeyInline(admin.TabularInline):
|
||||
|
|
26
users/migrations/0006_auto_20171031_1336.py
Normal file
26
users/migrations/0006_auto_20171031_1336.py
Normal 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,
|
||||
),
|
||||
]
|
20
users/migrations/0007_auto_20171031_1347.py
Normal file
20
users/migrations/0007_auto_20171031_1347.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -11,7 +11,15 @@ def avatar_path(instance, name):
|
|||
class Site(models.Model):
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
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):
|
||||
return self.name
|
||||
|
@ -73,7 +81,9 @@ class Profile(models.Model):
|
|||
display_name = models.CharField(max_length=100, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.url
|
||||
if self.site.domain:
|
||||
return self.name + '@' + self.site.domain
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -81,7 +91,7 @@ class Profile(models.Model):
|
|||
|
||||
@property
|
||||
def url(self):
|
||||
return self.site.url.format(username=self.username)
|
||||
return self.site.format(username=self.username)
|
||||
|
||||
class Meta:
|
||||
ordering = ('site', 'username')
|
||||
|
|
Loading…
Reference in a new issue