forked from 00dani/lemoncurry
Add simple support for PGP keys
This commit is contained in:
parent
0e3ef423d2
commit
75f2575c30
4 changed files with 56 additions and 1 deletions
|
@ -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
Normal file
26
users/migrations/0003_key.py
Normal file
|
@ -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)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -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…
Add table
Add a link
Reference in a new issue