Skip to content

Commit

Permalink
Update org URL scheme from <id-slug> to <slug>
Browse files Browse the repository at this point in the history
  • Loading branch information
magnified103 committed Sep 26, 2023
1 parent 49b5b09 commit d152f94
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
14 changes: 8 additions & 6 deletions dmoj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

SEND_ACTIVATION_EMAIL = getattr(settings, 'SEND_ACTIVATION_EMAIL', True)
REGISTRATION_COMPLETE_TEMPLATE = 'registration/registration_complete.html' if SEND_ACTIVATION_EMAIL \
else 'registration/activation_complete.html'
else 'registration/activation_complete.html'

register_patterns = [
path('activate/complete/',
Expand Down Expand Up @@ -184,7 +184,7 @@ def paged_list_view(view, name):
path('users/', include([
path('', user.users, name='user_list'),
path('<int:page>', lambda request, page:
HttpResponsePermanentRedirect('%s?page=%s' % (reverse('user_list'), page))),
HttpResponsePermanentRedirect('%s?page=%s' % (reverse('user_list'), page))),
path('find', user.user_ranking_redirect, name='user_ranking_redirect'),
])),

Expand All @@ -204,7 +204,7 @@ def paged_list_view(view, name):
])),
path('/submissions/', paged_list_view(submission.AllUserSubmissions, 'all_user_submissions_old')),
path('/submissions/', lambda _, user:
HttpResponsePermanentRedirect(reverse('all_user_submissions', args=[user]))),
HttpResponsePermanentRedirect(reverse('all_user_submissions', args=[user]))),

path('/', lambda _, user: HttpResponsePermanentRedirect(reverse('user_page', args=[user]))),
])),
Expand Down Expand Up @@ -269,13 +269,13 @@ def paged_list_view(view, name):
path('contributors/', include([
path('', user.ContribList.as_view(), name='contributors_list'),
path('<int:page>', lambda request, page:
HttpResponsePermanentRedirect('%s?page=%s' % (reverse('contributors_list'), page))),
HttpResponsePermanentRedirect('%s?page=%s' % (reverse('contributors_list'), page))),
path('find', user.user_contributor_redirect, name='user_contributor_redirect'),
])),

path('organizations/', organization.OrganizationList.as_view(), name='organization_list'),
path('organizations/create', organization.CreateOrganization.as_view(), name='organization_create'),
path('organization/<int:pk>-<slug:slug>', include([
path('org/<slug:slug>', include([
path('', organization.OrganizationHome.as_view(), name='organization_home'),
path('/users/', organization.OrganizationUsers.as_view(), name='organization_users'),
path('/join', organization.JoinOrganization.as_view(), name='join_organization'),
Expand Down Expand Up @@ -305,8 +305,10 @@ def paged_list_view(view, name):
path('new', organization.BlogPostCreateOrganization.as_view(), name='blog_post_create_organization'),
])),

path('/', lambda _, pk, slug: HttpResponsePermanentRedirect(reverse('organization_home', args=[pk, slug]))),
path('/', lambda _, slug: HttpResponsePermanentRedirect(reverse('organization_home', args=[slug]))),
])),
path('organization/<int:pk>-<path:suffix>', lambda _, pk, suffix:
HttpResponsePermanentRedirect('/org/%s' % suffix)),

path('runtimes/', language.LanguageList.as_view(), name='runtime_list'),
path('runtimes/matrix/', status.version_matrix, name='version_matrix'),
Expand Down
4 changes: 2 additions & 2 deletions judge/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('organization_home', args=(self.id, self.slug))
return reverse('organization_home', args=[self.slug])

def get_users_url(self):
return reverse('organization_users', args=(self.id, self.slug))
return reverse('organization_users', args=[self.slug])

class Meta:
ordering = ['name']
Expand Down
20 changes: 10 additions & 10 deletions judge/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BaseOrganizationListView(OrganizationMixin, ListView):
slug_url_kwarg = 'slug'

def get_object(self):
return get_object_or_404(Organization, id=self.kwargs.get('pk'))
return get_object_or_404(Organization, slug=self.kwargs.get('slug'))

def get_context_data(self, **kwargs):
return super().get_context_data(organization=self.object, **kwargs)
Expand Down Expand Up @@ -119,7 +119,7 @@ def get_context_data(self, **kwargs):
context['users'] = ranker(context['users'])
context['partial'] = True
context['is_admin'] = self.can_edit_organization()
context['kick_url'] = reverse('organization_user_kick', args=[self.object.id, self.object.slug])
context['kick_url'] = reverse('organization_user_kick', args=[self.object.slug])
context['first_page_href'] = '.'
context.update(self.get_sort_context())
context.update(self.get_sort_paginate_context())
Expand Down Expand Up @@ -201,7 +201,7 @@ def form_valid(self, form):
request.state = 'P'
request.save()
return HttpResponseRedirect(reverse('request_organization_detail', args=(
request.organization.id, request.organization.slug, request.id,
request.organization.slug, request.id,
)))


Expand Down Expand Up @@ -432,9 +432,9 @@ def get_context_data(self, **kwargs):
return context

def dispatch(self, request, *args, **kwargs):
if 'pk' not in kwargs:
raise ImproperlyConfigured('Must pass a pk')
self.organization = get_object_or_404(Organization, pk=kwargs['pk'])
if 'slug' not in kwargs:
raise ImproperlyConfigured('Must pass a slug')
self.organization = get_object_or_404(Organization, slug=kwargs['slug'])
self.object = self.organization

if not self.allow_all_users and \
Expand All @@ -456,9 +456,9 @@ def can_edit_organization(self, org=None):

class CustomAdminOrganizationMixin(CustomOrganizationMixin):
def dispatch(self, request, *args, **kwargs):
if 'pk' not in kwargs:
raise ImproperlyConfigured('Must pass a pk')
self.organization = get_object_or_404(Organization, pk=kwargs['pk'])
if 'slug' not in kwargs:
raise ImproperlyConfigured('Must pass a slug')
self.organization = get_object_or_404(Organization, slug=kwargs['slug'])
if self.can_edit_organization():
return super(CustomAdminOrganizationMixin, self).dispatch(request, *args, **kwargs)
raise PermissionDenied
Expand Down Expand Up @@ -503,7 +503,7 @@ def get_queryset(self):

def get_context_data(self, **kwargs):
context = super(OrganizationHome, self).get_context_data(**kwargs)
context['first_page_href'] = reverse('organization_home', args=[self.object.pk, self.object.slug])
context['first_page_href'] = reverse('organization_home', args=[self.object.slug])
context['title'] = self.object.name
context['can_edit'] = self.can_edit_organization()
context['is_member'] = self.request.profile in self.object
Expand Down
12 changes: 6 additions & 6 deletions templates/organization/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,37 @@ <h3>{{ _('Controls') }} <i class="fa fa-question-circle"></i></h3>
<div class="sidebox-content" style="padding: 1em;">
{% if request.user.is_authenticated %}
{% if is_member %}
<form method="post" action="{{ url('leave_organization', organization.id, organization.slug) }}">
<form method="post" action="{{ url('leave_organization', organization.slug) }}">
{% csrf_token %}
<input type="submit" class="unselectable button full leave-organization" value="{{ _('Leave organization') }}">
</form>
{% elif organization.is_open %}
<form method="post" action="{{ url('join_organization', organization.id, organization.slug) }}">
<form method="post" action="{{ url('join_organization', organization.slug) }}">
{% csrf_token %}
<input type="submit" class="unselectable button full" value="{{ _('Join organization') }}">
</form>
{% else %}
<a href="{{ url('request_organization', organization.id, organization.slug) }}"
<a href="{{ url('request_organization', organization.slug) }}"
class="unselectable button full">{{ _('Request membership') }}</a>
{% endif %}
{% endif %}
<br>
{% if can_edit %}
{% if not organization.is_open %}
<div>
<a href="{{ url('organization_requests_pending', organization.id, organization.slug) }}">
<a href="{{ url('organization_requests_pending', organization.slug) }}">
{{ _('View requests') }}
{% if num_requests %}<span class="badge">{{ num_requests }}</span>{% endif %}
</a>
</div>
{% endif %}
{% if perms.judge.edit_organization_post %}
<div>
<a href="{{ url('blog_post_create_organization', organization.id, organization.slug) }}">{{ _('Create blog post') }}</a>
<a href="{{ url('blog_post_create_organization', organization.slug) }}">{{ _('Create blog post') }}</a>
</div>
{% endif %}
<div>
<a href="{{ url('edit_organization', organization.id, organization.slug) }}">{{ _('Edit organization') }}</a>
<a href="{{ url('edit_organization', organization.slug) }}">{{ _('Edit organization') }}</a>
</div>
{% endif %}
{% if perms.judge.change_organization %}
Expand Down
12 changes: 6 additions & 6 deletions templates/organization/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ <h2>{{ content_title or title }}</h2>
<br>
<div class="tabs">
<ul>
{{ make_tab('home', 'fa-info-circle', url('organization_home', organization.pk, organization.slug), _('Home')) }}
{{ make_tab('home', 'fa-info-circle', url('organization_home', organization.slug), _('Home')) }}
{{ make_tab('users', 'fa-university', organization.get_users_url(), _('Users')) }}
{{ make_tab('problem-list', 'fa-puzzle-piece', url('problem_list_organization', organization.pk, organization.slug), _('Problems list')) }}
{{ make_tab('contest-list', 'fa-trophy', url('contest_list_organization', organization.pk, organization.slug), _('Contests list')) }}
{{ make_tab('submission-list', 'fa-list', url('submission_list_organization', organization.pk, organization.slug), _('Submissions')) }}
{{ make_tab('problem-list', 'fa-puzzle-piece', url('problem_list_organization', organization.slug), _('Problems list')) }}
{{ make_tab('contest-list', 'fa-trophy', url('contest_list_organization', organization.slug), _('Contests list')) }}
{{ make_tab('submission-list', 'fa-list', url('submission_list_organization', organization.slug), _('Submissions')) }}
</ul>
<span class="spacer"></span>
<ul>
{% if organization.is_admin(request.profile) %}
{% if request.user.has_perm('judge.create_organization_problem') %}
{{ make_tab('create', 'fa-plus', url('problem_create_organization', organization.id, organization.slug), _('Create new problem')) }}
{{ make_tab('create', 'fa-plus', url('problem_create_organization', organization.slug), _('Create new problem')) }}
{% endif %}
{% if request.user.has_perm('judge.create_private_contest') %}
{{ make_tab('create', 'fa-plus', url('contest_create_organization', organization.id, organization.slug), _('Create new contest')) }}
{{ make_tab('create', 'fa-plus', url('contest_create_organization', organization.slug), _('Create new contest')) }}
{% endif %}
{% endif %}
</ul>
Expand Down

0 comments on commit d152f94

Please sign in to comment.