Skip to content

Commit

Permalink
dissalow slashes in Ab IDs (names)
Browse files Browse the repository at this point in the history
  • Loading branch information
csntm-dev committed May 5, 2023
1 parent 676450e commit a1f3260
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions collation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class Meta:
model = models.Ab
exclude = ['section', 'indexed_basetext']

def clean_name(self):
name = self.cleaned_data['name']
if not name:
raise forms.ValidationError('Name cannot be empty')
if '/' in name or '\\' in name:
raise forms.ValidationError('Name cannot contain slashes "/" "\\"')
return name

def save(self, section_id: int, commit=True):
instance = super().save(commit=False)
instance.section_id = section_id
Expand Down
13 changes: 11 additions & 2 deletions collation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ def new_ab(request: HttpRequest, section_id: int):
resp = render(request, 'scraps/quick_message.html', {'message': 'Collation unit saved', 'timout': '3'})
resp['HX-Trigger'] = 'refreshAbs'
return resp
return render(request, 'collation/new_ab.html', {'page': {'active': 'collation'}})
return render(request, 'collation/new_ab.html', {
'page': {'active': 'collation'},
'section_id': section_id,
'new_ab_form': form
})


@login_required
Expand All @@ -165,7 +169,12 @@ def edit_ab(request: HttpRequest, ab_pk: int):
resp = HttpResponse('Ab saved')
resp['HX-Trigger'] = 'refreshAbs'
return resp
return render(request, 'collation/edit_ab.html', {'page': {'active': 'collation'}})
context = {
'page': {'active': 'collation'},
'form': form,
'ab': ab
}
return render(request, 'collation/edit_ab.html', context)
else:
ab = models.Ab.objects.get(pk=ab_pk)
ab.delete()
Expand Down

0 comments on commit a1f3260

Please sign in to comment.