Projet

Général

Profil

0001-role_forms-add-a-details-field-9503.patch

Benjamin Dauvergne, 06 janvier 2016 13:52

Télécharger (2,59 ko)

Voir les différences:

Subject: [PATCH 1/5] role_forms: add a details field (#9503)

 hobo/agent/authentic2/migrations/0001_initial.py | 29 ++++++++++++++++++++++++
 hobo/agent/authentic2/migrations/__init__.py     |  0
 hobo/agent/authentic2/models.py                  |  0
 hobo/agent/authentic2/role_forms.py              |  2 ++
 4 files changed, 31 insertions(+)
 create mode 100644 hobo/agent/authentic2/migrations/0001_initial.py
 create mode 100644 hobo/agent/authentic2/migrations/__init__.py
 create mode 100644 hobo/agent/authentic2/models.py
hobo/agent/authentic2/migrations/0001_initial.py
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3
import json
4

  
5
from django.db import models, migrations
6

  
7
def copy_description_to_details(apps, schema_editor):
8
    Role = apps.get_model('a2_rbac', 'Role')
9
    for role in Role.objects.all():
10
        value = json.dumps(role.description)
11
        ra, created = role.attributes.get_or_create(
12
            name='details', kind='json', defaults={
13
                'value': value})
14
        if not created:
15
            ra.value = value
16
            ra.save()
17

  
18
def noop(apps, schema_editor):
19
    pass
20

  
21
class Migration(migrations.Migration):
22

  
23
    dependencies = [
24
        ('a2_rbac', '0009_partial_unique_index_on_permission'),
25
    ]
26

  
27
    operations = [
28
        migrations.RunPython(copy_description_to_details, noop),
29
    ]
hobo/agent/authentic2/role_forms.py
77 77

  
78 78

  
79 79
class RoleForm(RoleEditForm):
80
    details = forms.CharField(label=_('Role details'), widget=forms.Textarea, initial='',
81
                              required=False)
80 82
    emails = CommaSeparatedCharField(label=_('Emails'),
81 83
                                     item_validators=[EmailValidator()],
82 84
                                     required=False)
83
-