Keys: Update use of DetailForm
Fix absolute URL keyword argument. Move detail generation to the model. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.utils.html import escape
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.common.forms import DetailForm
|
||||
@@ -10,34 +9,20 @@ from .models import Key
|
||||
|
||||
|
||||
class KeyDetailForm(DetailForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
instance = kwargs['instance']
|
||||
|
||||
extra_fields = (
|
||||
{'label': _('Key ID'), 'field': 'key_id'},
|
||||
{
|
||||
'label': _('User ID'),
|
||||
'field': lambda x: escape(instance.user_id),
|
||||
},
|
||||
{
|
||||
'label': _('Creation date'), 'field': 'creation_date',
|
||||
'widget': forms.widgets.DateInput
|
||||
},
|
||||
{
|
||||
'label': _('Expiration date'),
|
||||
'field': lambda x: instance.expiration_date or _('None'),
|
||||
'widget': forms.widgets.DateInput
|
||||
},
|
||||
{'label': _('Fingerprint'), 'field': 'fingerprint'},
|
||||
{'label': _('Length'), 'field': 'length'},
|
||||
{'label': _('Algorithm'), 'field': 'algorithm'},
|
||||
{'label': _('Type'), 'field': lambda x: instance.get_key_type_display()},
|
||||
)
|
||||
|
||||
kwargs['extra_fields'] = extra_fields
|
||||
super(KeyDetailForm, self).__init__(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
extra_fields = (
|
||||
{'field': 'key_id'},
|
||||
{'field': 'get_escaped_user_id'},
|
||||
{'field': 'creation_date', 'widget': forms.widgets.DateInput},
|
||||
{
|
||||
'field': 'get_expiration_date_display',
|
||||
'widget': forms.widgets.DateInput
|
||||
},
|
||||
{'field': 'fingerprint'},
|
||||
{'field': 'length'},
|
||||
{'field': 'algorithm'},
|
||||
{'label': _('Type'), 'field': 'get_key_type_display'},
|
||||
)
|
||||
fields = ()
|
||||
model = Key
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.html import escape
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .exceptions import NeedPassphrase, PassphraseError
|
||||
@@ -78,9 +79,17 @@ class Key(models.Model):
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
viewname='django_gpg:key_detail', kwargs={'key_pk': self.pk}
|
||||
viewname='django_gpg:key_detail', kwargs={'key_id': self.pk}
|
||||
)
|
||||
|
||||
def get_expiration_date_display(self):
|
||||
return self.expiration_date or _('None')
|
||||
get_expiration_date_display.short_description = _('Expiration date')
|
||||
|
||||
def get_escaped_user_id(self):
|
||||
return escape(self.user_id)
|
||||
get_escaped_user_id.short_description = _('User ID')
|
||||
|
||||
@property
|
||||
def key_id(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user