# HG changeset patch # User Peter Sanchez # Date 1680887189 21600 # Fri Apr 07 11:06:29 2023 -0600 # Branch redmine # Node ID 721356500c1b24c7ac6593f52df34d2b78c3f011 # Parent 408c472863566b0ad1770469430ba08d76f6548d Updating for Django 4.1+ diff --git a/trello_broker/forms.py b/trello_broker/forms.py --- a/trello_broker/forms.py +++ b/trello_broker/forms.py @@ -1,63 +1,64 @@ from django import forms from django.db.models import Q -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .models import BitBucketRepo, BitBucketRule class BitBucketRepoAdminForm(forms.ModelForm): class Meta: model = BitBucketRepo - fields = ('name', 'slug', 'access_key', 'trello_board') + fields = ("name", "slug", "access_key", "trello_board") def clean_access_key(self): - access_key = self.cleaned_data.get('access_key') - slug = self.cleaned_data.get('slug') + access_key = self.cleaned_data.get("access_key") + slug = self.cleaned_data.get("slug") if slug: query = Q(slug=slug) & Q(access_key=access_key) - if hasattr(self, 'instance'): + if hasattr(self, "instance"): query &= ~Q(pk=self.instance.pk) if BitBucketRepo.objects.filter(query).exists(): - raise forms.ValidationError(_( - 'There is already a BitBucket Repo stored with the ' - 'same slug & access_key.' - )) + raise forms.ValidationError( + _( + "There is already a BitBucket Repo stored with the " + "same slug & access_key." + ) + ) return access_key class BitBucketRuleAdminForm(forms.ModelForm): class Meta: model = BitBucketRule - fields = ('repo', 'action', 'update', 'archive', 'move', 'trello_list') + fields = ("repo", "action", "update", "archive", "move", "trello_list") def __init__(self, *args, **kwargs): super(BitBucketRuleAdminForm, self).__init__(*args, **kwargs) def clean_action(self): - if 'action' not in self.cleaned_data: - raise forms.ValidationError(_('This field is required.')) + if "action" not in self.cleaned_data: + raise forms.ValidationError(_("This field is required.")) - action = self.cleaned_data['action'] - query = Q(repo=self.cleaned_data['repo']) & \ - Q(action=action) - if hasattr(self, 'instance'): + action = self.cleaned_data["action"] + query = Q(repo=self.cleaned_data["repo"]) & Q(action=action) + if hasattr(self, "instance"): query &= ~Q(pk=self.instance.pk) if BitBucketRule.objects.filter(query).exists(): - raise forms.ValidationError(_( - 'A matching rule already exists for this BitBucketRepo' - )) + raise forms.ValidationError( + _("A matching rule already exists for this BitBucketRepo") + ) return action def clean_trello_list(self): - trello_list = self.cleaned_data.get('trello_list') + trello_list = self.cleaned_data.get("trello_list") if trello_list: - if not self.cleaned_data.get('move', False): - raise forms.ValidationError(_( - 'Rule must have "Move" checked to select a Trello list' - )) + if not self.cleaned_data.get("move", False): + raise forms.ValidationError( + _('Rule must have "Move" checked to select a Trello list') + ) else: - if self.cleaned_data.get('move', False): - raise forms.ValidationError(_( - 'This field is required when "Move" is checked.' - )) + if self.cleaned_data.get("move", False): + raise forms.ValidationError( + _('This field is required when "Move" is checked.') + ) return trello_list diff --git a/trello_broker/models.py b/trello_broker/models.py --- a/trello_broker/models.py +++ b/trello_broker/models.py @@ -1,6 +1,6 @@ from django.db import models from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from . import api Q = models.Q