fix: avoid project url conflicts
This commit is contained in:
parent
a98fe4305e
commit
5303ce3ef2
3 changed files with 9 additions and 6 deletions
|
@ -162,4 +162,6 @@ CELERY_RESULT_SERIALIZER = 'json'
|
||||||
|
|
||||||
AUTH_USER_MODEL = 'accounts.User'
|
AUTH_USER_MODEL = 'accounts.User'
|
||||||
|
|
||||||
RESERVED_PROJECT_NAME = [ 'login', 'logout', 'profile', 'admin', 'django-admin' ]
|
RESERVED_PROJECT_URLS = [
|
||||||
|
'login', 'logout', 'profile', 'admin', 'django-admin'
|
||||||
|
]
|
||||||
|
|
|
@ -5,7 +5,7 @@ urlpatterns = [
|
||||||
# Administration: redirect on first available admin page
|
# Administration: redirect on first available admin page
|
||||||
url(r'^admin/$', 'tracker.views.admin', name='admin'),
|
url(r'^admin/$', 'tracker.views.admin', name='admin'),
|
||||||
# Settings
|
# Settings
|
||||||
url(r'^admin/settings/$', 'tracker.views.settings', name='settings'),
|
url(r'^admin/settings/$', 'tracker.views.settings_list', name='settings'),
|
||||||
# Projects
|
# Projects
|
||||||
url(r'^$', 'tracker.views.project_list', name='list-project'),
|
url(r'^$', 'tracker.views.project_list', name='list-project'),
|
||||||
url(r'^add/$', 'tracker.views.project_add', name='add-project'),
|
url(r'^add/$', 'tracker.views.project_add', name='add-project'),
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.contrib import messages
|
||||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from tracker.forms import *
|
from tracker.forms import *
|
||||||
from tracker.models import *
|
from tracker.models import *
|
||||||
|
@ -39,7 +40,7 @@ def admin(request):
|
||||||
############
|
############
|
||||||
|
|
||||||
@project_perm_required('manage_settings')
|
@project_perm_required('manage_settings')
|
||||||
def settings(request):
|
def settings_list(request):
|
||||||
return render(request, 'tracker/settings.html')
|
return render(request, 'tracker/settings.html')
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,9 +67,9 @@ def project_add(request):
|
||||||
if request.method == 'POST' and form.is_valid():
|
if request.method == 'POST' and form.is_valid():
|
||||||
|
|
||||||
name = form.cleaned_data['name']
|
name = form.cleaned_data['name']
|
||||||
if Project.objects.filter(name__iexact=name).exists():
|
if name in settings.RESERVED_PROJECT_URLS:
|
||||||
form._errors['name'] = ['There is already a project '
|
form._errors['name'] = ['Sorry, this URL is reserved '
|
||||||
'with a similar name.']
|
'and can not be used.']
|
||||||
else:
|
else:
|
||||||
project = form.save()
|
project = form.save()
|
||||||
messages.success(request, 'Project added successfully.')
|
messages.success(request, 'Project added successfully.')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue