Skip to content

Commit

Permalink
Merge pull request #268 from elixir-luxembourg/207-remove-unqiueness-…
Browse files Browse the repository at this point in the history
…constraint-on-data-declaration-title

207 remove uniqueness constraint on data declaration title
  • Loading branch information
vildead authored Aug 2, 2021
2 parents 6e47287 + d114024 commit 80f5897
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
11 changes: 11 additions & 0 deletions core/forms/data_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from core.models import DataDeclaration, Partner, Contract, GDPRRole
from core.models.contract import PartnerRole

def validate_title_unique(title, dataset):
duplicates = DataDeclaration.objects.filter(title=title,
dataset=dataset)
if duplicates.exists():
raise ValidationError({'title': 'Data declaration with the same title already exists for the dataset.'})

class DataDeclarationEditForm(forms.ModelForm):

Expand Down Expand Up @@ -51,6 +56,9 @@ def clean(self):
Override to check selected Partner and Contract match
"""
cleaned_data = super().clean()

validate_title_unique(cleaned_data.get('title'), self.instance.dataset)

source_partner = cleaned_data.get("partner", None)
source_contract = cleaned_data.get("contract", None)
is_signatory = False
Expand Down Expand Up @@ -185,6 +193,9 @@ def clean(self):
* samples_location field can be specified only when the "generated_from_samples" field is true #70
"""
cleaned_data = super().clean()

validate_title_unique(cleaned_data.get('title'), self.dataset)

return cleaned_data

def save(self, commit=True):
Expand Down
28 changes: 0 additions & 28 deletions core/importer/datasets_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,6 @@ def get_dataset(elu_accession, title):

return True

# @staticmethod
# def process_local_custodians(dataset_dict):
# result = []
#
# local_custodians = dataset_dict.get('local_custodian', [])
#
# for local_custodian in local_custodians:
# custodian_str_strip = local_custodian.strip()
# user = (User.objects.filter(full_name__icontains=custodian_str_strip.lower()) | User.objects.filter(
# full_name__icontains=custodian_str_strip.upper())).first()
# if user is None:
# names = custodian_str_strip.split(maxsplit=1)
#
# if len(names) == 2:
# logger.warning('no user found for %s and inactive user will be created', custodian_str_strip)
# usr_name = names[0].strip().lower() + '.' + names[1].strip().lower()
# user = User.objects.create(username=usr_name, password='', first_name=names[0], last_name=names[1],is_active=False,
# email='inactive.user@uni.lu',
# )
# user.staff = True
# g = Group.objects.get(name=GroupConstants.VIP.value)
# user.groups.add(g)
# user.save()
# result.append(user)
#
# else:
# result.append(user)
# return result

def process_project(self, project_acronym):
try:
Expand Down
23 changes: 23 additions & 0 deletions core/migrations/0023_remove_datadec_title_unq_constraint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.24 on 2021-07-28 20:59

import core.models.utils
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0022_elu_accession_null_constraint'),
]

operations = [
migrations.AlterField(
model_name='datadeclaration',
name='title',
field=core.models.utils.TextFieldWithInputWidget(help_text='Title is a brief description for the data declaration. Think of how you - in the lab - refer to data from a particular source; use that as the title.', max_length=255, verbose_name='Title'),
),
migrations.AddConstraint(
model_name='datadeclaration',
constraint=models.UniqueConstraint(fields=('title', 'dataset'), name='unique_title_dataset'),
),
]
4 changes: 2 additions & 2 deletions core/models/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def clean(self):

user = models.ForeignKey('core.User',
related_name='user',
verbose_name='User with access',
verbose_name='User that has the access',
on_delete=models.CASCADE,
null=True,
blank=True,
help_text='Select either an User, or a Contact'
help_text='Use either `contact` or `user`'
)

was_generated_automatically = models.BooleanField(
Expand Down
6 changes: 4 additions & 2 deletions core/models/data_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Meta:
(constants.Permissions.VIEW.value, 'View the dataset'),
(constants.Permissions.PROTECTED.value, 'View the protected elements'),
)
constraints = [
models.UniqueConstraint(fields=['title', 'dataset'], name='unique_title_dataset')
]

access_procedure = models.TextField(verbose_name='Remarks on the access procedure',
blank=True,
Expand Down Expand Up @@ -174,8 +177,7 @@ class Meta:

title = TextFieldWithInputWidget(blank=False,
max_length=255,
verbose_name='Title',
unique=True,
verbose_name='Title',
help_text='Title is a brief description for the data declaration. Think of how you - in the lab - refer to data from a particular source; use that as the title.')

unique_id = models.UUIDField(default=uuid.uuid4,
Expand Down

0 comments on commit 80f5897

Please sign in to comment.