Browse Source

Add simple support for PGP keys

pull/1/head
Danielle McLean 5 years ago
parent
commit
75f2575c30
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
  1. 8
      home/templates/home/index.html
  2. 10
      users/admin.py
  3. 26
      users/migrations/0003_key.py
  4. 13
      users/models.py

8
home/templates/home/index.html

@ -7,6 +7,14 @@
<h4 class="card-title p-name">
<span class="p-given-name">{{ user.first_name }}</span> <span class="p-family-name">{{ user.last_name }}</span>
</h4>
{% for key in user.keys.all %}
<h6 class="card-subtitle">
<a class="u-key" href="{{ key.file.url }}">
<i class="fa fa-key"></i>
{{ key.pretty_print }}
</a>
</h6>
{% endfor %}
{% if user.note %}<p class="card-text p-note">{{ user.note }}</p>{% endif %}
</div>

10
users/admin.py

@ -1,12 +1,20 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import User
from .models import Key, User
class KeyInline(admin.TabularInline):
model = Key
extra = 1
class UserAdmin(BaseUserAdmin):
fieldsets = BaseUserAdmin.fieldsets + (
('Profile', {'fields': ('avatar', 'note')}),
)
inlines = (
KeyInline,
)
admin.site.register(User, UserAdmin)

26
users/migrations/0003_key.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-23 01:25
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0002_auto_20171023_0109'),
]
operations = [
migrations.CreateModel(
name='Key',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('fingerprint', models.CharField(max_length=40)),
('file', models.FileField(upload_to='keys')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='keys', to=settings.AUTH_USER_MODEL)),
],
),
]

13
users/models.py

@ -9,3 +9,16 @@ def avatar_path(instance, name):
class User(AbstractUser):
avatar = models.ImageField(upload_to=avatar_path)
note = models.TextField(blank=True)
class Key(models.Model):
user = models.ForeignKey(
User,
related_name='keys',
on_delete=models.CASCADE
)
fingerprint = models.CharField(max_length=40)
file = models.FileField(upload_to='keys')
def pretty_print(self):
return " ".join(self.fingerprint[i:i+4] for i in range(0, 40, 4))

Loading…
Cancel
Save