0001-role_forms-add-a-details-field-9503.patch
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 |
] |
|
25 | ||
26 |
operations = [ |
|
27 |
migrations.RunPython(copy_description_to_details, noop), |
|
28 |
] |
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, help_text=_('This text will be shown to users when ' |
|
82 |
'they are concerned by this role.')) |
|
80 | 83 |
emails = CommaSeparatedCharField(label=_('Emails'), |
81 | 84 |
item_validators=[EmailValidator()], |
82 | 85 |
required=False) |
83 |
- |