From 8a9f41759e0e7e369e9e0d72a2c735eba8d53c50 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 31 Oct 2017 13:46:52 +1100 Subject: [PATCH] Add a field site.domain, so that profiles can be labeled as username@domain, WebFinger style --- entries/templates/entries/h-entry.html | 2 +- users/admin.py | 2 +- users/migrations/0006_auto_20171031_1336.py | 26 +++++++++++++++++++++ users/migrations/0007_auto_20171031_1347.py | 20 ++++++++++++++++ users/models.py | 16 ++++++++++--- 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 users/migrations/0006_auto_20171031_1336.py create mode 100644 users/migrations/0007_auto_20171031_1347.py diff --git a/entries/templates/entries/h-entry.html b/entries/templates/entries/h-entry.html index bf3b2b0..6a8f6f3 100644 --- a/entries/templates/entries/h-entry.html +++ b/entries/templates/entries/h-entry.html @@ -28,7 +28,7 @@ {% for s in entry.syndications.all %} - {{ s.profile.name }} + {{ s.profile }} {% endfor %} diff --git a/users/admin.py b/users/admin.py index 04c7ed2..7efd9c8 100644 --- a/users/admin.py +++ b/users/admin.py @@ -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): diff --git a/users/migrations/0006_auto_20171031_1336.py b/users/migrations/0006_auto_20171031_1336.py new file mode 100644 index 0000000..1cf8516 --- /dev/null +++ b/users/migrations/0006_auto_20171031_1336.py @@ -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, + ), + ] diff --git a/users/migrations/0007_auto_20171031_1347.py b/users/migrations/0007_auto_20171031_1347.py new file mode 100644 index 0000000..a28bb94 --- /dev/null +++ b/users/migrations/0007_auto_20171031_1347.py @@ -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), + ), + ] diff --git a/users/models.py b/users/models.py index 732d5f0..d372359 100644 --- a/users/models.py +++ b/users/models.py @@ -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')