Projet

Général

Profil

0001-admin-add-oauth2-models-improve-search-fixes-22950.patch

Benjamin Dauvergne, 03 avril 2018 10:58

Télécharger (10,4 ko)

Voir les différences:

Subject: [PATCH] admin: add oauth2 models, improve search (fixes #22950)

We also add default ordering on creation_date for most models.
 fargo/fargo/admin.py                               |  5 +--
 fargo/fargo/migrations/0017_auto_20180331_1532.py  | 19 ++++++++++++
 fargo/fargo/models.py                              |  5 ++-
 fargo/locale/fr/LC_MESSAGES/django.po              | 35 ++++++++++++++++++---
 fargo/oauth2/admin.py                              | 36 +++++++++++++++++++++-
 fargo/oauth2/migrations/0005_auto_20180331_1532.py | 27 ++++++++++++++++
 fargo/oauth2/models.py                             | 19 ++++++++++--
 7 files changed, 135 insertions(+), 11 deletions(-)
 create mode 100644 fargo/fargo/migrations/0017_auto_20180331_1532.py
 create mode 100644 fargo/oauth2/migrations/0005_auto_20180331_1532.py
fargo/fargo/admin.py
8 8

  
9 9
class UserDocumentAdmin(admin.ModelAdmin):
10 10
    list_display = ['user', 'filename', 'thumbnail', 'created', 'origin']
11
    fields = ['user', 'filename', 'thumbnail', 'created', 'origin']
11
    fields = ['id', 'user', 'filename', 'thumbnail', 'created', 'origin']
12 12
    readonly_fields = ['created', 'thumbnail']
13 13
    search_fields = ['user__first_name', 'user__last_name', 'user__email', 'filename',
14
                     'origin__label']
14
                     'origin__label', 'document__content_hash']
15 15

  
16 16
    def thumbnail(self, instance):
17 17
        return instance.document.thumbnail_img_tag
......
22 22
    fields = ['content_hash', 'thumbnail', 'users']
23 23
    list_display = ['content_hash', 'thumbnail', 'users']
24 24
    readonly_fields = ['thumbnail', 'users']
25
    search_fields = ['content_hash', 'content']
25 26

  
26 27
    def users(self, instance):
27 28
        User = get_user_model()
fargo/fargo/migrations/0017_auto_20180331_1532.py
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.11 on 2018-03-31 13:32
3
from __future__ import unicode_literals
4

  
5
from django.db import migrations
6

  
7

  
8
class Migration(migrations.Migration):
9

  
10
    dependencies = [
11
        ('fargo', '0016_auto_20180330_2248'),
12
    ]
13

  
14
    operations = [
15
        migrations.AlterModelOptions(
16
            name='document',
17
            options={'ordering': ('creation_date',), 'verbose_name': 'document', 'verbose_name_plural': 'documents'},
18
        ),
19
    ]
fargo/fargo/models.py
212 212
                           thumbnail.height,
213 213
                           data_url)
214 214

  
215
    def __unicode__(self):
216
        return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
217

  
215 218
    class Meta:
216 219
        verbose_name = _('document')
217 220
        verbose_name_plural = _('documents')
218
        ordering = ('content_hash',)
221
        ordering = ('creation_date',)
219 222

  
220 223

  
221 224
@receiver(post_delete, sender=Document)
fargo/locale/fr/LC_MESSAGES/django.po
7 7
msgstr ""
8 8
"Project-Id-Version: fargo 0\n"
9 9
"Report-Msgid-Bugs-To: \n"
10
"POT-Creation-Date: 2018-03-31 15:53+0200\n"
10
"POT-Creation-Date: 2018-03-31 15:54+0200\n"
11 11
"PO-Revision-Date: 2018-03-17 17:31+0100\n"
12 12
"Last-Translator: Frederic Peters <fpeters@entrouvert.com>\n"
13 13
"Language: French\n"
......
16 16
"Content-Transfer-Encoding: 8bit\n"
17 17
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
18 18

  
19
#: fargo/fargo/admin.py:18 fargo/fargo/admin.py:33
19
#: fargo/fargo/admin.py:18 fargo/fargo/admin.py:34 fargo/oauth2/admin.py:39
20
#: fargo/oauth2/admin.py:53
20 21
msgid "thumbnail"
21 22
msgstr "vignette"
22 23

  
......
80 81
msgid "user"
81 82
msgstr "utilisateur"
82 83

  
83
#: fargo/fargo/models.py:49 fargo/fargo/models.py:216
84
#: fargo/fargo/models.py:49 fargo/fargo/models.py:219
84 85
msgid "document"
85 86
msgstr "document"
86 87

  
......
149 150
msgid "%(label)s: %(value)s"
150 151
msgstr "%(label)s : %(value)s"
151 152

  
152
#: fargo/fargo/models.py:217
153
#: fargo/fargo/models.py:220
153 154
msgid "documents"
154 155
msgstr "documents"
155 156

  
......
178 179
msgid "Document"
179 180
msgstr "Document"
180 181

  
181
#: fargo/oauth2/models.py:54
182
#: fargo/oauth2/models.py:52
182 183
msgid "redirect URIs"
183 184
msgstr "URIs de redirection"
184 185

  
186
#: fargo/oauth2/models.py:71
187
msgid "OAUTH2 client"
188
msgstr ""
189

  
190
#: fargo/oauth2/models.py:72
191
msgid "OAUTH2 clients"
192
msgstr ""
193

  
194
#: fargo/oauth2/models.py:93
195
msgid "OAUTH2 authorization"
196
msgstr ""
197

  
198
#: fargo/oauth2/models.py:94
199
msgid "OAUTH2 authorizations"
200
msgstr ""
201

  
202
#: fargo/oauth2/models.py:121
203
msgid "OAUTH2 temporary file"
204
msgstr ""
205

  
206
#: fargo/oauth2/models.py:122
207
msgid "OAUTH2 temporary files"
208
msgstr ""
209

  
185 210
#: fargo/oauth2/views.py:231
186 211
msgid "This document is already in your portfolio"
187 212
msgstr "Ce document est déjà enregistré."
fargo/oauth2/admin.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.contrib import admin
18
from django.utils.translation import ugettext_lazy as _
18 19

  
19
from .models import OAuth2Client
20
from .models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
20 21

  
21 22

  
22 23
class OAuth2ClientAdmin(admin.ModelAdmin):
23 24
    fields = ('client_name', 'client_id', 'client_secret', 'redirect_uris')
24 25
    list_display = ['client_name', 'client_id', 'client_secret', 'redirect_uris']
25 26

  
27
class OAuth2AuthorizeAdmin(admin.ModelAdmin):
28
    list_display = ['id', 'client_name', 'user_document', 'thumbnail',
29
                    'access_token', 'code', 'creation_date']
30
    raw_id_fields = ['user_document']
31
    search_fields = ['client__client_name', 'user_document__user__email',
32
                     'user_document__user__first_name',
33
                     'user_document__user__last_name',
34
                     'user_document__filename',
35
                     'user_document__user__contenat_has']
36

  
37
    def thumbnail(self, instance):
38
        return instance.user_document.document.thumbnail_img_tag
39
    thumbnail.short_description = _('thumbnail')
40

  
41
    def client_name(self, instance):
42
        return instance.client.client_name
43

  
44

  
45
class OAuth2TempFileAdmin(admin.ModelAdmin):
46
    list_display = ['uuid', 'client_name', 'filename', 'thumbnail', 'creation_date']
47
    raw_id_fields = ['document']
48
    search_fields = ['filename', 'uuid', 'client__client_name']
49

  
50

  
51
    def thumbnail(self, instance):
52
        return instance.document.thumbnail_img_tag
53
    thumbnail.short_description = _('thumbnail')
54

  
55
    def client_name(self, instance):
56
        return instance.client.client_name
57

  
26 58

  
27 59
admin.site.register(OAuth2Client, OAuth2ClientAdmin)
60
admin.site.register(OAuth2Authorize, OAuth2AuthorizeAdmin)
61
admin.site.register(OAuth2TempFile, OAuth2TempFileAdmin)
fargo/oauth2/migrations/0005_auto_20180331_1532.py
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.11 on 2018-03-31 13:32
3
from __future__ import unicode_literals
4

  
5
from django.db import migrations
6

  
7

  
8
class Migration(migrations.Migration):
9

  
10
    dependencies = [
11
        ('oauth2', '0004_auto_20180326_1330'),
12
    ]
13

  
14
    operations = [
15
        migrations.AlterModelOptions(
16
            name='oauth2authorize',
17
            options={'ordering': ('creation_date',), 'verbose_name': 'OAUTH2 authorization', 'verbose_name_plural': 'OAUTH2 authorizations'},
18
        ),
19
        migrations.AlterModelOptions(
20
            name='oauth2client',
21
            options={'ordering': ('client_name',), 'verbose_name': 'OAUTH2 client', 'verbose_name_plural': 'OAUTH2 clients'},
22
        ),
23
        migrations.AlterModelOptions(
24
            name='oauth2tempfile',
25
            options={'ordering': ('creation_date',), 'verbose_name': 'OAUTH2 temporary file', 'verbose_name_plural': 'OAUTH2 temporary files'},
26
        ),
27
    ]
fargo/oauth2/models.py
47 47

  
48 48

  
49 49
class OAuth2Client(models.Model):
50
    client_secret = models.CharField(max_length=255, default=generate_uuid)
51
    client_id = models.CharField(max_length=255, default=generate_uuid)
52 50
    client_name = models.CharField(max_length=255)
53 51
    redirect_uris = models.TextField(
54 52
        verbose_name=_('redirect URIs'),
55 53
        validators=[validate_https_url])
54
    client_id = models.CharField(max_length=255, default=generate_uuid)
55
    client_secret = models.CharField(max_length=255, default=generate_uuid)
56 56

  
57 57
    def __repr__(self):
58 58
        return 'OAuth2Client name: %s with id: %s' % (self.client_name, self.client_id)
......
66 66
    def __unicode__(self):
67 67
        return self.client_name
68 68

  
69
    class Meta:
70
        ordering = ('client_name',)
71
        verbose_name = _('OAUTH2 client')
72
        verbose_name_plural = _('OAUTH2 clients')
73

  
69 74

  
70 75
class CleanupQuerySet(QuerySet):
71 76
    def cleanup(self, n=None):
......
83 88

  
84 89
    objects = CleanupQuerySet.as_manager()
85 90

  
91
    class Meta:
92
        ordering = ('creation_date',)
93
        verbose_name = _('OAUTH2 authorization')
94
        verbose_name_plural = _('OAUTH2 authorizations')
95

  
86 96
    @classmethod
87 97
    def get_lifetime(cls):
88 98
        return max(
......
105 115
    @classmethod
106 116
    def get_lifetime(cls):
107 117
        return settings.FARGO_OAUTH2_TEMPFILE_LIFETIME
118

  
119
    class Meta:
120
        ordering = ('creation_date',)
121
        verbose_name = _('OAUTH2 temporary file')
122
        verbose_name_plural = _('OAUTH2 temporary files')
108
-