Skip to content

Commit f555e47

Browse files
authored
Merge pull request #41 from renderbox/TC-1052-qa-admin-panel-creating-new-roll-causes-error-
Adds site attribute to PermafrostRoleCreateForm
2 parents 25500b3 + aa46f03 commit f555e47

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

permafrost/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.2.13"
1+
VERSION = "0.2.14"

permafrost/forms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Permafrost Forms
22
from django.conf import settings
33
from django.contrib.auth.models import Permission
4+
from django.contrib.sites.models import Site
45
from django.core.exceptions import ValidationError
56
from django.forms import ModelForm
67
from django.forms.fields import CharField, ChoiceField, BooleanField
@@ -66,7 +67,7 @@ class Meta:
6667

6768
def __init__(self, *args, **kwargs):
6869
super().__init__(*args, **kwargs)
69-
70+
self.site = kwargs.pop('site', Site.objects.get_current())
7071
self.fields['category'].choices = CHOICES
7172

7273
category = self.initial.get(
@@ -86,6 +87,7 @@ def __init__(self, *args, **kwargs):
8687
bootstrappify(self.fields)
8788

8889
def save(self, commit=True):
90+
self.instance.site = self.site
8991
instance = super().save(commit)
9092
category = instance.category
9193

@@ -109,7 +111,7 @@ def clean_name(self):
109111
name_exists = PermafrostRole.objects.filter(
110112

111113
name=name,
112-
site__id=settings.SITE_ID,
114+
site=self.site,
113115

114116
).exclude(pk=self.instance.pk).first()
115117

@@ -118,7 +120,7 @@ def clean_name(self):
118120
try:
119121
name_exists = PermafrostRole.objects.get(
120122
name=name,
121-
site__id=settings.SITE_ID
123+
site=self.site
122124
)
123125
except PermafrostRole.DoesNotExist:
124126
pass

permafrost/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ def post(self, request, *args, **kwargs):
156156
submitted = SelectPermafrostRoleTypeForm(request.POST)
157157
permission_categories = {}
158158
if submitted.is_valid():
159-
form = PermafrostRoleCreateForm(initial=submitted.cleaned_data)
159+
160+
kwargs = {'initial': submitted.cleaned_data}
161+
if hasattr(request, 'site'):
162+
kwargs['site'] = request.site
163+
164+
form = PermafrostRoleCreateForm(**kwargs)
160165
category = submitted.cleaned_data["category"]
161166
required = get_required_by_category(category=category)
162167
optional = get_optional_by_category(category=category)

0 commit comments

Comments
 (0)