diff --git a/dmoj/urls.py b/dmoj/urls.py index 2d8abc1d4..5e2b0bab4 100644 --- a/dmoj/urls.py +++ b/dmoj/urls.py @@ -275,7 +275,7 @@ def paged_list_view(view, name): path('organizations/', organization.OrganizationList.as_view(), name='organization_list'), path('organizations/create', organization.CreateOrganization.as_view(), name='organization_create'), - path('organization/-', include([ + path('org/', 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'), @@ -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/-', + 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'), diff --git a/judge/models/profile.py b/judge/models/profile.py index c4cc117d6..e84e4efaa 100644 --- a/judge/models/profile.py +++ b/judge/models/profile.py @@ -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'] diff --git a/judge/views/organization.py b/judge/views/organization.py index 90af785ce..de8ddeac5 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -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) @@ -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()) @@ -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, ))) @@ -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 \ @@ -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 @@ -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 diff --git a/templates/organization/home.html b/templates/organization/home.html index 66421d131..bfb394305 100644 --- a/templates/organization/home.html +++ b/templates/organization/home.html @@ -89,17 +89,17 @@

{{ _('Controls') }}