fixed unique check of APISecretForm
This commit is contained in:
parent
16f55f472b
commit
b44197a1c5
1 changed files with 10 additions and 0 deletions
|
@ -2,6 +2,7 @@ import string
|
|||
from datetime import timedelta
|
||||
from operator import attrgetter
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
from django.forms import BooleanField, Form, IntegerField, ModelChoiceField, ModelForm
|
||||
from django.utils import timezone
|
||||
|
@ -94,6 +95,15 @@ class APISecretForm(ModelForm):
|
|||
model = Secret
|
||||
fields = ['name', 'readonly', 'scope_grant_permissions', 'scope_editor', 'scope_mesh']
|
||||
|
||||
def clean(self):
|
||||
try:
|
||||
self.instance.user = self.request.user
|
||||
self.instance.name = self.cleaned_data['name']
|
||||
self.instance.validate_unique()
|
||||
except ValidationError as e:
|
||||
self._update_errors(e)
|
||||
return super().clean()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.instance.valid_until = (
|
||||
timezone.now()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue