From f6a3af5586ba0bc39c2d0b86228881c1c378bfe1 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Mon, 9 Jan 2023 17:31:24 +0100 Subject: [PATCH 1/3] include study.short_title in URLs --- .../templates/budgets/_study_detail_budgets.html | 6 +++--- .../budgets/templates/budgets/budget_base.html | 4 ++-- .../templates/budgets/budget_confirm_delete.html | 4 ++-- .../budgets/templates/budgets/budget_form.html | 2 +- .../templates/datasets/_study_detail_datasets.html | 6 +++--- .../datasets/templates/datasets/dataset_base.html | 4 ++-- .../templates/datasets/dataset_confirm_delete.html | 4 ++-- .../datasets/templates/datasets/dataset_form.html | 2 +- study_registration/deployments/api.py | 2 +- .../deployments/_study_detail_deployments.html | 6 +++--- .../templates/deployments/deployment_base.html | 4 ++-- .../deployments/deployment_confirm_delete.html | 4 ++-- .../templates/deployments/deployment_form.html | 2 +- study_registration/ethics/models.py | 2 +- .../ethics/templates/ethics/_study_detail_ethics.html | 6 +++--- .../templates/ethics/ethicsapplication_base.html | 4 ++-- .../ethics/ethicsapplication_confirm_delete.html | 4 ++-- .../templates/ethics/ethicsapplication_form.html | 2 +- .../publications/_study_detail_publications.html | 6 +++--- .../templates/publications/publication_base.html | 4 ++-- .../publications/publication_confirm_delete.html | 4 ++-- .../templates/publications/publication_form.html | 2 +- .../templates/studies/_study_detail_general.html | 4 ++-- .../templates/studies/study_confirm_delete.html | 4 ++-- .../studies/templates/studies/study_form.html | 4 ++-- .../studies/templates/studies/study_list.html | 2 +- study_registration/studies/urls.py | 8 ++++---- study_registration/templates/base.html | 2 +- study_registration/urls.py | 10 +++++----- 29 files changed, 59 insertions(+), 59 deletions(-) diff --git a/study_registration/budgets/templates/budgets/_study_detail_budgets.html b/study_registration/budgets/templates/budgets/_study_detail_budgets.html index 13f6ca26..9730172c 100644 --- a/study_registration/budgets/templates/budgets/_study_detail_budgets.html +++ b/study_registration/budgets/templates/budgets/_study_detail_budgets.html @@ -5,7 +5,7 @@

{% translate 'Budgets' %}

{% if is_owner %}
- {% translate 'Add budget' %} + {% translate 'Add budget' %}
{% endif %} @@ -13,8 +13,8 @@ {% for budget in study.budget_set.all %} {% if is_owner %}
- {% translate 'Update' %} - {% translate 'Delete' %} + {% translate 'Update' %} + {% translate 'Delete' %}
{% endif %} {{ budget.expected }} € diff --git a/study_registration/budgets/templates/budgets/budget_base.html b/study_registration/budgets/templates/budgets/budget_base.html index e24fe6fc..fe1e97f2 100644 --- a/study_registration/budgets/templates/budgets/budget_base.html +++ b/study_registration/budgets/templates/budgets/budget_base.html @@ -13,8 +13,8 @@ {% block breadcrumbs %} {{ block.super }} {% if budget %} - + {% else %} - + {% endif %} {% endblock %} diff --git a/study_registration/budgets/templates/budgets/budget_confirm_delete.html b/study_registration/budgets/templates/budgets/budget_confirm_delete.html index 5a052d64..db62d578 100644 --- a/study_registration/budgets/templates/budgets/budget_confirm_delete.html +++ b/study_registration/budgets/templates/budgets/budget_confirm_delete.html @@ -5,7 +5,7 @@ {% block breadcrumbs %} {{ block.super }} - + {% endblock %} {% block content %} @@ -17,7 +17,7 @@ {% endblocktranslate %}

- {% translate 'Cancel' %} + {% translate 'Cancel' %}
diff --git a/study_registration/budgets/templates/budgets/budget_form.html b/study_registration/budgets/templates/budgets/budget_form.html index b1e8ef0e..08bb747f 100644 --- a/study_registration/budgets/templates/budgets/budget_form.html +++ b/study_registration/budgets/templates/budgets/budget_form.html @@ -11,7 +11,7 @@ {% bootstrap_field form.approved_by %}
- {% translate 'Cancel' %} + {% translate 'Cancel' %}
diff --git a/study_registration/datasets/templates/datasets/_study_detail_datasets.html b/study_registration/datasets/templates/datasets/_study_detail_datasets.html index 4cd41a0e..4a1b40aa 100644 --- a/study_registration/datasets/templates/datasets/_study_detail_datasets.html +++ b/study_registration/datasets/templates/datasets/_study_detail_datasets.html @@ -5,7 +5,7 @@

{% translate 'Raw data folders' %}

{% if is_owner %}
- {% translate 'Add data folder' %} + {% translate 'Add data folder' %}
{% endif %} @@ -13,8 +13,8 @@ {% for dataset in study.dataset_set.all %} {% if is_owner %}
- {% translate 'Update' %} - {% translate 'Delete' %} + {% translate 'Update' %} + {% translate 'Delete' %}
{% endif %}
diff --git a/study_registration/datasets/templates/datasets/dataset_base.html b/study_registration/datasets/templates/datasets/dataset_base.html index f24de64d..fc2d2958 100644 --- a/study_registration/datasets/templates/datasets/dataset_base.html +++ b/study_registration/datasets/templates/datasets/dataset_base.html @@ -13,8 +13,8 @@ {% block breadcrumbs %} {{ block.super }} {% if dataset %} - + {% else %} - + {% endif %} {% endblock %} diff --git a/study_registration/datasets/templates/datasets/dataset_confirm_delete.html b/study_registration/datasets/templates/datasets/dataset_confirm_delete.html index 337594a9..de5e10ed 100644 --- a/study_registration/datasets/templates/datasets/dataset_confirm_delete.html +++ b/study_registration/datasets/templates/datasets/dataset_confirm_delete.html @@ -5,7 +5,7 @@ {% block breadcrumbs %} {{ block.super }} - + {% endblock %} {% block content %} @@ -17,7 +17,7 @@ {% endblocktranslate %}

- {% translate 'Cancel' %} + {% translate 'Cancel' %}
diff --git a/study_registration/datasets/templates/datasets/dataset_form.html b/study_registration/datasets/templates/datasets/dataset_form.html index 58934926..085df162 100644 --- a/study_registration/datasets/templates/datasets/dataset_form.html +++ b/study_registration/datasets/templates/datasets/dataset_form.html @@ -48,7 +48,7 @@ diff --git a/study_registration/deployments/api.py b/study_registration/deployments/api.py index 64d5bdcb..65b2bc03 100644 --- a/study_registration/deployments/api.py +++ b/study_registration/deployments/api.py @@ -12,7 +12,7 @@ class DeploymentsApiView(View): return { 'study_identifier': str(deployment.study), 'study_url': self.request.build_absolute_uri( - reverse('studies:api', args=[deployment.study.pk]) + reverse('studies:api', args=[deployment.study.pk, deployment.study.short_title]) ), 'git_repo': deployment.git_repo, 'git_ref': deployment.git_ref, diff --git a/study_registration/deployments/templates/deployments/_study_detail_deployments.html b/study_registration/deployments/templates/deployments/_study_detail_deployments.html index e8f2083e..cf37d4b5 100644 --- a/study_registration/deployments/templates/deployments/_study_detail_deployments.html +++ b/study_registration/deployments/templates/deployments/_study_detail_deployments.html @@ -5,7 +5,7 @@

{% translate 'Deployments' %}

{% if is_owner %} {% endif %} @@ -13,8 +13,8 @@ {% for deployment in study.deployment_set.all %} {% if is_owner %} {% endif %} {{ deployment }} diff --git a/study_registration/deployments/templates/deployments/deployment_base.html b/study_registration/deployments/templates/deployments/deployment_base.html index 3f590b97..41677b53 100644 --- a/study_registration/deployments/templates/deployments/deployment_base.html +++ b/study_registration/deployments/templates/deployments/deployment_base.html @@ -13,8 +13,8 @@ {% block breadcrumbs %} {{ block.super }} {% if deployment %} - + {% else %} - + {% endif %} {% endblock %} diff --git a/study_registration/deployments/templates/deployments/deployment_confirm_delete.html b/study_registration/deployments/templates/deployments/deployment_confirm_delete.html index 870fb18d..fefe3976 100644 --- a/study_registration/deployments/templates/deployments/deployment_confirm_delete.html +++ b/study_registration/deployments/templates/deployments/deployment_confirm_delete.html @@ -5,7 +5,7 @@ {% block breadcrumbs %} {{ block.super }} - + {% endblock %} {% block content %} @@ -17,7 +17,7 @@ {% endblocktranslate %}

- {% translate 'Cancel' %} + {% translate 'Cancel' %}
diff --git a/study_registration/deployments/templates/deployments/deployment_form.html b/study_registration/deployments/templates/deployments/deployment_form.html index 67b809b6..a9b53cd6 100644 --- a/study_registration/deployments/templates/deployments/deployment_form.html +++ b/study_registration/deployments/templates/deployments/deployment_form.html @@ -14,7 +14,7 @@ {% bootstrap_field form.enddate %} diff --git a/study_registration/ethics/models.py b/study_registration/ethics/models.py index 0a922eef..1d7d813c 100644 --- a/study_registration/ethics/models.py +++ b/study_registration/ethics/models.py @@ -15,7 +15,7 @@ class EthicsBoard(models.Model): def get_upload_path(instance, filename): - return '{}/ethics/{}'.format(instance.study.pk, filename) + return '{}-{}/ethics/{}'.format(instance.study.pk, instance.study.short_title, filename) class EthicsApplication(models.Model): diff --git a/study_registration/ethics/templates/ethics/_study_detail_ethics.html b/study_registration/ethics/templates/ethics/_study_detail_ethics.html index 10fcf441..885b744e 100644 --- a/study_registration/ethics/templates/ethics/_study_detail_ethics.html +++ b/study_registration/ethics/templates/ethics/_study_detail_ethics.html @@ -5,7 +5,7 @@

{% translate 'Ethics applications' %}

{% if is_owner %} {% endif %} @@ -13,8 +13,8 @@ {% for application in study.ethicsapplication_set.all %} {% if is_owner %} {% endif %}
diff --git a/study_registration/ethics/templates/ethics/ethicsapplication_base.html b/study_registration/ethics/templates/ethics/ethicsapplication_base.html index 2e3018bc..3fca97df 100644 --- a/study_registration/ethics/templates/ethics/ethicsapplication_base.html +++ b/study_registration/ethics/templates/ethics/ethicsapplication_base.html @@ -13,8 +13,8 @@ {% block breadcrumbs %} {{ block.super }} {% if ethicsapplication %} - + {% else %} - + {% endif %} {% endblock %} diff --git a/study_registration/ethics/templates/ethics/ethicsapplication_confirm_delete.html b/study_registration/ethics/templates/ethics/ethicsapplication_confirm_delete.html index ca15bd70..188c7152 100644 --- a/study_registration/ethics/templates/ethics/ethicsapplication_confirm_delete.html +++ b/study_registration/ethics/templates/ethics/ethicsapplication_confirm_delete.html @@ -5,7 +5,7 @@ {% block breadcrumbs %} {{ block.super }} - + {% endblock %} {% block content %} @@ -17,7 +17,7 @@ {% endblocktranslate %}

- {% translate 'Cancel' %} + {% translate 'Cancel' %}
diff --git a/study_registration/ethics/templates/ethics/ethicsapplication_form.html b/study_registration/ethics/templates/ethics/ethicsapplication_form.html index ba9f0dea..afabf2d1 100644 --- a/study_registration/ethics/templates/ethics/ethicsapplication_form.html +++ b/study_registration/ethics/templates/ethics/ethicsapplication_form.html @@ -12,7 +12,7 @@ {% bootstrap_field form.approval %} diff --git a/study_registration/publications/templates/publications/_study_detail_publications.html b/study_registration/publications/templates/publications/_study_detail_publications.html index fa0b6d1c..7710b502 100644 --- a/study_registration/publications/templates/publications/_study_detail_publications.html +++ b/study_registration/publications/templates/publications/_study_detail_publications.html @@ -5,7 +5,7 @@

{% translate 'Publications' %}

{% if is_owner %} {% endif %}
@@ -15,8 +15,8 @@
  • {% if is_owner %} {% endif %} {{ publication.title }}. diff --git a/study_registration/publications/templates/publications/publication_base.html b/study_registration/publications/templates/publications/publication_base.html index ddbbd665..37460ed6 100644 --- a/study_registration/publications/templates/publications/publication_base.html +++ b/study_registration/publications/templates/publications/publication_base.html @@ -13,8 +13,8 @@ {% block breadcrumbs %} {{ block.super }} {% if publication %} -
  • + {% else %} - + {% endif %} {% endblock %} diff --git a/study_registration/publications/templates/publications/publication_confirm_delete.html b/study_registration/publications/templates/publications/publication_confirm_delete.html index a060d11b..53d5b368 100644 --- a/study_registration/publications/templates/publications/publication_confirm_delete.html +++ b/study_registration/publications/templates/publications/publication_confirm_delete.html @@ -5,7 +5,7 @@ {% block breadcrumbs %} {{ block.super }} - + {% endblock %} {% block content %} @@ -17,7 +17,7 @@ {% endblocktranslate %}

    - {% translate 'Cancel' %} + {% translate 'Cancel' %}
    diff --git a/study_registration/publications/templates/publications/publication_form.html b/study_registration/publications/templates/publications/publication_form.html index e56d4304..43561c6c 100644 --- a/study_registration/publications/templates/publications/publication_form.html +++ b/study_registration/publications/templates/publications/publication_form.html @@ -13,7 +13,7 @@ {% bootstrap_field form.year %} diff --git a/study_registration/studies/templates/studies/_study_detail_general.html b/study_registration/studies/templates/studies/_study_detail_general.html index 920fe12b..d213319e 100644 --- a/study_registration/studies/templates/studies/_study_detail_general.html +++ b/study_registration/studies/templates/studies/_study_detail_general.html @@ -5,8 +5,8 @@

    {{ study.title }}

    {% if is_owner %} {% endif %} diff --git a/study_registration/studies/templates/studies/study_confirm_delete.html b/study_registration/studies/templates/studies/study_confirm_delete.html index 269e73d4..e3f03597 100644 --- a/study_registration/studies/templates/studies/study_confirm_delete.html +++ b/study_registration/studies/templates/studies/study_confirm_delete.html @@ -5,7 +5,7 @@ {% block breadcrumbs %} {{ block.super }} - + {% endblock %} {% block content %} @@ -17,7 +17,7 @@ {% endblocktranslate %}

    - {% translate 'Cancel' %} + {% translate 'Cancel' %}
    diff --git a/study_registration/studies/templates/studies/study_form.html b/study_registration/studies/templates/studies/study_form.html index 77c6ab71..d1418e2b 100644 --- a/study_registration/studies/templates/studies/study_form.html +++ b/study_registration/studies/templates/studies/study_form.html @@ -13,7 +13,7 @@ {% block breadcrumbs %} {{ block.super }} {% if study %} - + {% else %} {% endif %} @@ -45,7 +45,7 @@
    {% if study %} - {% translate 'Cancel' %} + {% translate 'Cancel' %} {% else %} {% translate 'Cancel' %} {% endif %} diff --git a/study_registration/studies/templates/studies/study_list.html b/study_registration/studies/templates/studies/study_list.html index a2b44c4a..d7b89100 100644 --- a/study_registration/studies/templates/studies/study_list.html +++ b/study_registration/studies/templates/studies/study_list.html @@ -11,7 +11,7 @@ {% for study in object_list %}
  • -

    {{ study.title }}

    +

    {{ study.title }}

    {% icon 'user' %} {{ study.contact_person.get_full_name }} {% for keyword in study.keyword_set.all %} {{ keyword }} diff --git a/study_registration/studies/urls.py b/study_registration/studies/urls.py index a6d1c905..46dce1ba 100644 --- a/study_registration/studies/urls.py +++ b/study_registration/studies/urls.py @@ -13,8 +13,8 @@ urlpatterns = [ path('', StudyListView.as_view(), name='list'), path('mine/', MyStudiesView.as_view(), name='mine'), path('new/', StudyCreateView.as_view(), name='create'), - path('/', StudyDetailView.as_view(), name='detail'), - path('.json', StudyApiView.as_view(), name='api'), - path('/update/', StudyUpdateView.as_view(), name='update'), - path('/delete/', StudyDeleteView.as_view(), name='delete'), + path('-/', StudyDetailView.as_view(), name='detail'), + path('-.json', StudyApiView.as_view(), name='api'), + path('-/update/', StudyUpdateView.as_view(), name='update'), + path('-/delete/', StudyDeleteView.as_view(), name='delete'), ] diff --git a/study_registration/templates/base.html b/study_registration/templates/base.html index 92e37a4b..c0320db5 100644 --- a/study_registration/templates/base.html +++ b/study_registration/templates/base.html @@ -41,7 +41,7 @@
    diff --git a/study_registration/urls.py b/study_registration/urls.py index 655f19aa..446d8938 100644 --- a/study_registration/urls.py +++ b/study_registration/urls.py @@ -20,23 +20,23 @@ urlpatterns = [ template_name='bootstrap_theme.css', content_type='text/css' ), name='bootstrap-theme'), path( - 'studies//publications/', + 'studies/-/publications/', include('study_registration.publications.urls', namespace='publications'), ), path( - 'studies//ethics/', + 'studies/-/ethics/', include('study_registration.ethics.urls', namespace='ethics'), ), path( - 'studies//datasets/', + 'studies/-/datasets/', include('study_registration.datasets.urls', namespace='datasets'), ), path( - 'studies//budgets/', + 'studies/-/budgets/', include('study_registration.budgets.urls', namespace='budgets'), ), path( - 'studies//deployments/', + 'studies/-/deployments/', include(deployment_urls, namespace='deployments'), ), path('api/deployments/', include(deployment_urls.apipatterns)), -- GitLab From a443461cd85ad71ed353757ce6c96fcf8efc3ec6 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Mon, 9 Jan 2023 17:33:17 +0100 Subject: [PATCH 2/3] redirect to correct short_title --- study_registration/studies/mixins.py | 17 +++++++++++++++++ study_registration/studies/views.py | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/study_registration/studies/mixins.py b/study_registration/studies/mixins.py index 9dd257d6..ba5be507 100644 --- a/study_registration/studies/mixins.py +++ b/study_registration/studies/mixins.py @@ -1,10 +1,25 @@ from django.contrib.auth.mixins import LoginRequiredMixin +from django.http.response import HttpResponseRedirectBase from django.shortcuts import get_object_or_404 from django.urls import reverse from .models import Study +class HttpResponseRedirect(HttpResponseRedirectBase): + status_code = 307 # instead of 302 to keep POST requests + + +def redirect_to_correct_study_id(request, study): + parts = request.path.split('/') + parts[2] = '{}-{}'.format(study.pk, study.short_title) + url = '/'.join(parts) + query = request.GET.urlencode() + if query: + url += '?' + query + return HttpResponseRedirect(url) + + class StudyAspectMixin(LoginRequiredMixin): def dispatch(self, request, **kwargs): if not request.user.is_authenticated: @@ -13,6 +28,8 @@ class StudyAspectMixin(LoginRequiredMixin): self.study = get_object_or_404(Study, pk=kwargs['study_pk']) else: self.study = get_object_or_404(Study, pk=kwargs['study_pk'], owners=request.user) + if self.study.short_title != kwargs['study_short']: + return redirect_to_correct_study_id(request, self.study) return super().dispatch(request, **kwargs) def get_object(self): diff --git a/study_registration/studies/views.py b/study_registration/studies/views.py index bb2a4a1a..5f5823d2 100644 --- a/study_registration/studies/views.py +++ b/study_registration/studies/views.py @@ -12,6 +12,7 @@ from django.views.generic import UpdateView from .forms import StudyForm from .models import Study +from .mixins import redirect_to_correct_study_id def split_with_quotes(s): @@ -109,6 +110,12 @@ class MyStudiesView(LoginRequiredMixin, RedirectView): class StudyDetailView(DetailView): model = Study + def dispatch(self, request, **kwargs): + study = super().get_object() + if study.short_title != self.kwargs['short']: + return redirect_to_correct_study_id(self.request, study) + return super().dispatch(request, **kwargs) + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['is_owner'] = ( @@ -149,6 +156,12 @@ class StudyUpdateView(OwnerRequiredMixin, UpdateView): model = Study form_class = StudyForm + def dispatch(self, request, **kwargs): + study = super().get_object() + if study.short_title != self.kwargs['short']: + return redirect_to_correct_study_id(self.request, study) + return super().dispatch(request, **kwargs) + def get_success_url(self): return reverse('studies:detail', args=[self.object.pk]) @@ -156,5 +169,11 @@ class StudyUpdateView(OwnerRequiredMixin, UpdateView): class StudyDeleteView(OwnerRequiredMixin, DeleteView): model = Study + def dispatch(self, request, **kwargs): + study = super().get_object() + if study.short_title != self.kwargs['short']: + return redirect_to_correct_study_id(self.request, study) + return super().dispatch(request, **kwargs) + def get_success_url(self): return reverse('studies:list') -- GitLab From 061dd77f028eec7ee4c6b07d414a52596f0af202 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Mon, 9 Jan 2023 17:46:27 +0100 Subject: [PATCH 3/3] display full ID in study detail view --- .../studies/templates/studies/_study_detail_general.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/study_registration/studies/templates/studies/_study_detail_general.html b/study_registration/studies/templates/studies/_study_detail_general.html index d213319e..2d98c76e 100644 --- a/study_registration/studies/templates/studies/_study_detail_general.html +++ b/study_registration/studies/templates/studies/_study_detail_general.html @@ -33,7 +33,7 @@
    {% translate 'Study ID' %}
    -
    {{ study|display:'id' }}
    +
    {{ study }}
    {{ study|verbose_name:'created_at' }}
    {{ study|display:'created_at' }}
    -- GitLab