-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for storing partner information
When delivering data to customers, some partners may have access to various data before general availability. It is necessary to store this kind of information. This patch adds storage for partner metadata and allows linking partners to specific Variant.Arches on releases. Partner data can be completely edited through the API as well as the mapping. Partner types can only be modified in Django admin. JIRA: PDC-1048
- Loading branch information
Showing
11 changed files
with
618 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,9 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
from pdc.apps.common.register_to_admin import register | ||
|
||
register('partners') |
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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
import django_filters | ||
|
||
from pdc.apps.common import filters | ||
from . import models | ||
|
||
|
||
class PartnerFilterSet(django_filters.FilterSet): | ||
enabled = filters.CaseInsensitiveBooleanFilter() | ||
binary = filters.CaseInsensitiveBooleanFilter() | ||
source = filters.CaseInsensitiveBooleanFilter() | ||
|
||
class Meta: | ||
model = models.Partner | ||
fields = ('short', 'enabled', 'binary', 'source', 'ftp_dir', 'rsync_dir') | ||
|
||
|
||
class PartnerMappingFilterSet(django_filters.FilterSet): | ||
partner = filters.MultiValueFilter(name='partner__short') | ||
release = filters.MultiValueFilter(name='variant_arch__variant__release__release_id') | ||
variant = filters.MultiValueFilter(name='variant_arch__variant__variant_uid') | ||
arch = filters.MultiValueFilter(name='variant_arch__arch__name') | ||
|
||
class Meta: | ||
model = models.PartnerMapping | ||
fields = ('partner', 'release', 'variant', 'arch') |
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,56 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('release', '0002_auto_20150512_0719'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Partner', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('short', models.CharField(unique=True, max_length=100)), | ||
('name', models.CharField(max_length=250)), | ||
('binary', models.BooleanField(default=True)), | ||
('source', models.BooleanField(default=True)), | ||
('enabled', models.BooleanField(default=True)), | ||
('ftp_dir', models.CharField(max_length=500)), | ||
('rsync_dir', models.CharField(max_length=500)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='PartnerMapping', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('partner', models.ForeignKey(to='partners.Partner')), | ||
('variant_arch', models.ForeignKey(to='release.VariantArch')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='PartnerType', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('name', models.CharField(unique=True, max_length=100)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='partner', | ||
name='type', | ||
field=models.ForeignKey(to='partners.PartnerType'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='partnermapping', | ||
unique_together=set([('partner', 'variant_arch')]), | ||
), | ||
] |
Empty file.
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,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
from django.db import models | ||
|
||
|
||
class PartnerType(models.Model): | ||
name = models.CharField(unique=True, max_length=100) | ||
|
||
def __unicode__(self): | ||
return unicode(self.name) | ||
|
||
|
||
class Partner(models.Model): | ||
short = models.CharField(unique=True, max_length=100, blank=False) | ||
name = models.CharField(max_length=250, blank=False) | ||
type = models.ForeignKey(PartnerType) | ||
binary = models.BooleanField(default=True) | ||
source = models.BooleanField(default=True) | ||
enabled = models.BooleanField(default=True) | ||
ftp_dir = models.CharField(max_length=500) | ||
rsync_dir = models.CharField(max_length=500) | ||
|
||
def __unicode__(self): | ||
return u'{0.short} ({0.name})'.format(self) | ||
|
||
def export(self): | ||
result = {'type': self.type.name} | ||
for attr in ['short', 'name', 'binary', 'source', 'enabled', 'ftp_dir', 'rsync_dir']: | ||
result[attr] = getattr(self, attr) | ||
return result | ||
|
||
|
||
class PartnerMapping(models.Model): | ||
partner = models.ForeignKey(Partner) | ||
variant_arch = models.ForeignKey('release.VariantArch') | ||
|
||
class Meta: | ||
unique_together = (('partner', 'variant_arch'), ) | ||
|
||
def __unicode__(self): | ||
return u'{} {} {}'.format(self.partner, self.variant_arch.variant.release, | ||
self.variant_arch) | ||
|
||
def export(self): | ||
return { | ||
'partner': unicode(self.partner), | ||
'release': unicode(self.variant_arch.variant.release), | ||
'variant_arch': unicode(self.variant_arch) | ||
} |
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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
from rest_framework import serializers | ||
|
||
from pdc.apps.common.fields import ChoiceSlugField | ||
from pdc.apps.release import models as release_models | ||
from . import models | ||
|
||
|
||
class PartnerTypeSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = models.PartnerType | ||
fields = ('name', ) | ||
|
||
|
||
class PartnerSerializer(serializers.ModelSerializer): | ||
type = ChoiceSlugField(slug_field='name', | ||
queryset=models.PartnerType.objects.all()) | ||
|
||
class Meta: | ||
model = models.Partner | ||
fields = ('short', 'name', 'binary', 'source', 'type', 'enabled', | ||
'ftp_dir', 'rsync_dir') | ||
|
||
|
||
class PartnerMappingSerializer(serializers.ModelSerializer): | ||
partner = serializers.SlugRelatedField(slug_field='short', | ||
queryset=models.Partner.objects.all()) | ||
release = serializers.CharField(source='variant_arch.variant.release.release_id') | ||
variant = serializers.CharField(source='variant_arch.variant.variant_uid') | ||
arch = serializers.CharField(source='variant_arch.arch.name') | ||
|
||
class Meta: | ||
model = models.PartnerMapping | ||
fields = ('partner', 'release', 'variant', 'arch') | ||
|
||
def validate(self, attrs): | ||
try: | ||
variant_arch = attrs.get('variant_arch', {}) | ||
release_id = variant_arch.get('variant', {}).get('release', {}).get('release_id', '') | ||
variant_uid = variant_arch.get('variant', {}).get('variant_uid', '') | ||
arch = variant_arch.get('arch', {}).get('name', '') | ||
attrs['variant_arch'] = release_models.VariantArch.objects.get( | ||
variant__release__release_id=release_id, | ||
variant__variant_uid=variant_uid, | ||
arch__name=arch | ||
) | ||
except release_models.VariantArch.DoesNotExist: | ||
raise serializers.ValidationError( | ||
'No VariantArch for release_id=%s, variant_uid=%s, arch=%s' | ||
% (release_id, variant_uid, arch) | ||
) | ||
try: | ||
models.PartnerMapping.objects.get(**attrs) | ||
raise serializers.ValidationError('This partners mapping already exists.') | ||
except models.PartnerMapping.DoesNotExist: | ||
pass | ||
return super(PartnerMappingSerializer, self).validate(attrs) |
Oops, something went wrong.