admin: add oauth2 models, improve search (fixes #22950)
We also add default ordering on creation_date for most models.
This commit is contained in:
parent
a465f2c176
commit
aebddbb7bf
|
@ -8,10 +8,10 @@ from . import models
|
|||
|
||||
class UserDocumentAdmin(admin.ModelAdmin):
|
||||
list_display = ['user', 'filename', 'thumbnail', 'created', 'origin']
|
||||
fields = ['user', 'filename', 'thumbnail', 'created', 'origin']
|
||||
fields = ['id', 'user', 'filename', 'thumbnail', 'created', 'origin']
|
||||
readonly_fields = ['created', 'thumbnail']
|
||||
search_fields = ['user__first_name', 'user__last_name', 'user__email', 'filename',
|
||||
'origin__label']
|
||||
'origin__label', 'document__content_hash']
|
||||
|
||||
def thumbnail(self, instance):
|
||||
return instance.document.thumbnail_img_tag
|
||||
|
@ -22,6 +22,7 @@ class DocumentAdmin(admin.ModelAdmin):
|
|||
fields = ['content_hash', 'thumbnail', 'users']
|
||||
list_display = ['content_hash', 'thumbnail', 'users']
|
||||
readonly_fields = ['thumbnail', 'users']
|
||||
search_fields = ['content_hash', 'content']
|
||||
|
||||
def users(self, instance):
|
||||
User = get_user_model()
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.11 on 2018-03-31 13:32
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fargo', '0016_auto_20180330_2248'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='document',
|
||||
options={'ordering': ('creation_date',), 'verbose_name': 'document', 'verbose_name_plural': 'documents'},
|
||||
),
|
||||
]
|
|
@ -232,10 +232,13 @@ class Document(models.Model):
|
|||
return ''
|
||||
return {'src': self.thumbnail_data_url, 'width': thumbnail.width, 'height': thumbnail.height}
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('document')
|
||||
verbose_name_plural = _('documents')
|
||||
ordering = ('content_hash',)
|
||||
ordering = ('creation_date',)
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Document)
|
||||
|
|
|
@ -15,13 +15,47 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .models import OAuth2Client
|
||||
from .models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
|
||||
|
||||
|
||||
class OAuth2ClientAdmin(admin.ModelAdmin):
|
||||
fields = ('client_name', 'client_id', 'client_secret', 'redirect_uris')
|
||||
list_display = ['client_name', 'client_id', 'client_secret', 'redirect_uris']
|
||||
|
||||
class OAuth2AuthorizeAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'client_name', 'user_document', 'thumbnail',
|
||||
'access_token', 'code', 'creation_date']
|
||||
raw_id_fields = ['user_document']
|
||||
search_fields = ['client__client_name', 'user_document__user__email',
|
||||
'user_document__user__first_name',
|
||||
'user_document__user__last_name',
|
||||
'user_document__filename',
|
||||
'user_document__user__contenat_has']
|
||||
|
||||
def thumbnail(self, instance):
|
||||
return instance.user_document.document.thumbnail_img_tag
|
||||
thumbnail.short_description = _('thumbnail')
|
||||
|
||||
def client_name(self, instance):
|
||||
return instance.client.client_name
|
||||
|
||||
|
||||
class OAuth2TempFileAdmin(admin.ModelAdmin):
|
||||
list_display = ['uuid', 'client_name', 'filename', 'thumbnail', 'creation_date']
|
||||
raw_id_fields = ['document']
|
||||
search_fields = ['filename', 'uuid', 'client__client_name']
|
||||
|
||||
|
||||
def thumbnail(self, instance):
|
||||
return instance.document.thumbnail_img_tag
|
||||
thumbnail.short_description = _('thumbnail')
|
||||
|
||||
def client_name(self, instance):
|
||||
return instance.client.client_name
|
||||
|
||||
|
||||
admin.site.register(OAuth2Client, OAuth2ClientAdmin)
|
||||
admin.site.register(OAuth2Authorize, OAuth2AuthorizeAdmin)
|
||||
admin.site.register(OAuth2TempFile, OAuth2TempFileAdmin)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.11 on 2018-03-31 13:32
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('oauth2', '0004_auto_20180326_1330'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='oauth2authorize',
|
||||
options={'ordering': ('creation_date',), 'verbose_name': 'OAUTH2 authorization', 'verbose_name_plural': 'OAUTH2 authorizations'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='oauth2client',
|
||||
options={'ordering': ('client_name',), 'verbose_name': 'OAUTH2 client', 'verbose_name_plural': 'OAUTH2 clients'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='oauth2tempfile',
|
||||
options={'ordering': ('creation_date',), 'verbose_name': 'OAUTH2 temporary file', 'verbose_name_plural': 'OAUTH2 temporary files'},
|
||||
),
|
||||
]
|
|
@ -47,12 +47,12 @@ def validate_https_url(data):
|
|||
|
||||
|
||||
class OAuth2Client(models.Model):
|
||||
client_secret = models.CharField(max_length=255, default=generate_uuid)
|
||||
client_id = models.CharField(max_length=255, default=generate_uuid)
|
||||
client_name = models.CharField(max_length=255)
|
||||
redirect_uris = models.TextField(
|
||||
verbose_name=_('redirect URIs'),
|
||||
validators=[validate_https_url])
|
||||
client_id = models.CharField(max_length=255, default=generate_uuid)
|
||||
client_secret = models.CharField(max_length=255, default=generate_uuid)
|
||||
|
||||
def __repr__(self):
|
||||
return 'OAuth2Client name: %s with id: %s' % (self.client_name, self.client_id)
|
||||
|
@ -66,6 +66,11 @@ class OAuth2Client(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.client_name
|
||||
|
||||
class Meta:
|
||||
ordering = ('client_name',)
|
||||
verbose_name = _('OAUTH2 client')
|
||||
verbose_name_plural = _('OAUTH2 clients')
|
||||
|
||||
|
||||
class CleanupQuerySet(QuerySet):
|
||||
def cleanup(self, n=None):
|
||||
|
@ -83,6 +88,11 @@ class OAuth2Authorize(models.Model):
|
|||
|
||||
objects = CleanupQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
ordering = ('creation_date',)
|
||||
verbose_name = _('OAUTH2 authorization')
|
||||
verbose_name_plural = _('OAUTH2 authorizations')
|
||||
|
||||
@classmethod
|
||||
def get_lifetime(cls):
|
||||
return max(
|
||||
|
@ -105,3 +115,8 @@ class OAuth2TempFile(models.Model):
|
|||
@classmethod
|
||||
def get_lifetime(cls):
|
||||
return settings.FARGO_OAUTH2_TEMPFILE_LIFETIME
|
||||
|
||||
class Meta:
|
||||
ordering = ('creation_date',)
|
||||
verbose_name = _('OAUTH2 temporary file')
|
||||
verbose_name_plural = _('OAUTH2 temporary files')
|
||||
|
|
Loading…
Reference in New Issue