-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add access zones for access cards (#3507)
Author: @lukaszkarykowski
- Loading branch information
1 parent
720c12c
commit cf4361e
Showing
8 changed files
with
186 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,50 @@ | ||
from ralph.access_cards.models import AccessCard | ||
from ralph.access_cards.models import AccessCard, AccessZone | ||
from ralph.accounts.api import RalphUserSimpleSerializer, RegionSerializer | ||
from ralph.api import RalphAPISerializer, RalphAPIViewSet, router | ||
|
||
|
||
class AccessZoneSimpleSerializer(RalphAPISerializer): | ||
class Meta: | ||
model = AccessZone | ||
depth = 0 | ||
fields = ['id', 'name', 'parent', 'description'] | ||
|
||
|
||
class AccessZoneSerializer(RalphAPISerializer): | ||
class Meta: | ||
model = AccessZone | ||
depth = 1 | ||
|
||
|
||
class AccessCardSerializer(RalphAPISerializer): | ||
user = RalphUserSimpleSerializer() | ||
owner = RalphUserSimpleSerializer() | ||
region = RegionSerializer() | ||
access_zones = AccessZoneSimpleSerializer(many=True) | ||
|
||
class Meta: | ||
model = AccessCard | ||
fields = ['id', 'status', 'user', 'owner', 'created', 'modified', | ||
'visual_number', 'system_number', 'issue_date', 'notes', | ||
'region'] | ||
'region', 'access_zones'] | ||
|
||
|
||
class AccessCardViewSet(RalphAPIViewSet): | ||
queryset = AccessCard.objects.order_by('id').all() | ||
select_related = ['user', 'owner', 'region'] | ||
serializer_class = AccessCardSerializer | ||
prefetch_related = ['access_zones'] | ||
extended_filter_fields = { | ||
'access_zones__name': ['access_zones__name__icontains'], | ||
'access_zones__id': ['access_zones__id'] | ||
} | ||
|
||
|
||
class AccessZoneViewSet(RalphAPIViewSet): | ||
queryset = AccessZone.objects.all() | ||
serializer_class = AccessZoneSerializer | ||
|
||
|
||
router.register(r'access-card', AccessCardViewSet) | ||
router.register(r'access-zone', AccessZoneViewSet) | ||
urlpatterns = [] |
42 changes: 42 additions & 0 deletions
42
src/ralph/access_cards/migrations/0002_auto_20200116_1248.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import mptt.fields | ||
import ralph.lib.mixins.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('access_cards', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AccessZone', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), | ||
('name', models.CharField(verbose_name='name', max_length=255)), | ||
('description', models.TextField(blank=True, null=True, help_text='Optional description')), | ||
('lft', models.PositiveIntegerField(db_index=True, editable=False)), | ||
('rght', models.PositiveIntegerField(db_index=True, editable=False)), | ||
('tree_id', models.PositiveIntegerField(db_index=True, editable=False)), | ||
('level', models.PositiveIntegerField(db_index=True, editable=False)), | ||
('parent', mptt.fields.TreeForeignKey(blank=True, null=True, related_name='children', to='access_cards.AccessZone')), | ||
], | ||
options={ | ||
'ordering': ['name'], | ||
}, | ||
bases=(ralph.lib.mixins.models.AdminAbsoluteUrlMixin, models.Model), | ||
), | ||
migrations.AddField( | ||
model_name='accesscard', | ||
name='access_zones', | ||
field=mptt.fields.TreeManyToManyField(blank=True, related_name='access_cards', to='access_cards.AccessZone'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='accesszone', | ||
unique_together=set([('name', 'parent')]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters