Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base stepper PR #689

Merged
merged 54 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9a049f5
Merge remote-tracking branch 'origin/update/django_dsc' into major/st…
miggol May 6, 2024
4d519cd
wip: Initial stepper code
miggol May 6, 2024
534e2ea
feat: Base template now includes stepper object
miggol May 6, 2024
be202d3
feat: Add stepper object to ProposalMixin context
miggol May 6, 2024
66c96d4
feat: New StepperContextMixin
miggol Jul 23, 2024
eee57be
wip: Checker class
miggol Jul 23, 2024
7641d8e
Merge remote-tracking branch 'origin/major/4' into major/stepper
miggol Jul 23, 2024
b93fcd5
feat: more rigourously define stepper and proposal in context
miggol Jul 24, 2024
4153ce7
feat: Stepper Layout class
miggol Jul 24, 2024
176b956
feat: Starting checkers, remove Pages, some renamed variables
miggol Jul 24, 2024
f2fbcda
fix: renamed variables in template
miggol Jul 24, 2024
a27ef68
fix: correctly define stepper with proposal in views
miggol Jul 24, 2024
2434dbc
wip: Move checkers and helpers into separate files
miggol Jul 24, 2024
c8337c0
feat: Provide request object to Stepper object
miggol Jul 31, 2024
5f87c14
breaking: Repurpose ProposalMixin for views with a proposal main object
miggol Jul 31, 2024
e99a6f9
feat: Provide Layout and PlaceholderItems access to stepper object
miggol Jul 31, 2024
55fc57e
feat: Provide current checking and associated css class
miggol Jul 31, 2024
842f0df
wip: Combine checkers and stepper items into one
miggol Jul 31, 2024
b0934c0
wip: Merging stepper items and checkers was a bad idea
miggol Jul 31, 2024
6c46870
fix: Refer to self.get_proposal() instead of self.object
miggol Aug 19, 2024
60cd6f7
wip: Adding more checkers up to and including WMO
miggol Aug 19, 2024
46b2d0d
wip: Adding studies stepper item
miggol Aug 19, 2024
9134c9e
Merge branch 'fix/small-django4-fixes' into major/stepper
miggol Aug 19, 2024
03d93ba
feat: Add appropriate stepper context mixins to views
miggol Aug 20, 2024
8d70e9c
feat: Recursive stepper includes
miggol Aug 20, 2024
6799ed6
feat: Provide stepper bubble css classes in context
miggol Aug 20, 2024
a7ad91d
feat: Stepper items added until StudyDesign
miggol Aug 20, 2024
e95a5d0
feat: Make proposal getting consistent in various views
miggol Aug 21, 2024
2390613
wip: UpdateOrCreateChecker
miggol Aug 22, 2024
cd9c8ed
fix: get_proposal for SessionMixin
miggol Aug 28, 2024
1c2480c
feat: Study sub-objects checkers and stepper items
miggol Aug 28, 2024
37b29b4
fix: Provision of default location for stepper items
miggol Aug 28, 2024
b1f5c71
feat: DM and Submit checkers and items
miggol Aug 28, 2024
757997b
fix: Basic details placeholders and ProposalCreate success_url
miggol Aug 28, 2024
d21bf46
feat: StudyEndChecker
miggol Aug 28, 2024
1d790d8
fix: Correct context inheritance, thanks Ty
miggol Aug 28, 2024
024c81c
Merge remote-tracking branch 'origin/major/4' into major/stepper
miggol Aug 28, 2024
84e6936
style: Paint everything black
miggol Aug 28, 2024
12de201
pr: Remove unnecessary BaseStepperComponent
miggol Sep 2, 2024
ddce7ec
pr: Just return the css classes
miggol Sep 2, 2024
a92b2d2
pr: Tidy up proposal getting and mixins
miggol Sep 2, 2024
902f9cb
pr: Remove TrajectoriesItem and just use an MFC
miggol Sep 2, 2024
12aa53e
fix: Stepper in Task views and session_set fix
miggol Sep 2, 2024
4ba78df
feat: Move renderable mixin to main/utils.py
miggol Sep 3, 2024
ed54927
feat: Make StepperItems renderable items
miggol Sep 3, 2024
e5cb6df
feat: Merge Layout and Stepper classes, simplify stepper building
miggol Sep 3, 2024
b7aae56
feat: Move some of the remaining items around
miggol Sep 3, 2024
3104d3d
fix: Provide location to TrajectoriesChecker
miggol Sep 3, 2024
127abe0
feat: Move all base classes to stepper_helpers.py
miggol Sep 3, 2024
afaa5f2
docs: Added docstrings and comments to stepper helpers
miggol Sep 3, 2024
8be1a57
style: Lick of black paint
miggol Sep 3, 2024
a930845
fix: Imports that were left behind
miggol Sep 9, 2024
123dc5c
fix: Incorrect reference to stepper
miggol Sep 9, 2024
4b8b130
fix: Misbehaviour caused by mutation of RegularProposalLayout
miggol Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions interventions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from main.views import CreateView, UpdateView, AllowErrorsOnBackbuttonMixin
from studies.models import Study
from studies.utils import get_study_progress
from studies.mixins import StudyFromURLMixin
from proposals.mixins import StepperContextMixin

from .forms import InterventionForm
from .models import Intervention
Expand All @@ -12,7 +14,7 @@
##############################
# CRUD actions on Intervention
##############################
class InterventionMixin(object):
class InterventionMixin(StepperContextMixin):
"""Mixin for an Intervention, to use in both InterventionCreate and InterventionUpdate below"""

model = Intervention
Expand Down Expand Up @@ -48,25 +50,29 @@ def get_next_url(self):
next_url = "tasks:session_start"
return reverse(next_url, args=(pk,))

def get_proposal(self):
return self.get_object().study.proposal

def get_back_url(self):
return reverse("studies:design", args=(self.get_study().pk,))

def get_study(self):
raise NotImplementedError


class InterventionCreate(InterventionMixin, AllowErrorsOnBackbuttonMixin, CreateView):
class InterventionCreate(
StudyFromURLMixin,
InterventionMixin,
AllowErrorsOnBackbuttonMixin,
CreateView,
):
"""Creates a Intervention from a InterventionForm"""

def form_valid(self, form):
"""Sets the Study on the Intervention before starting validation."""
form.instance.study = self.get_study()
return super(InterventionCreate, self).form_valid(form)

def get_study(self):
"""Retrieves the Study from the pk kwarg"""
return Study.objects.get(pk=self.kwargs["pk"])


class InterventionUpdate(InterventionMixin, AllowErrorsOnBackbuttonMixin, UpdateView):
"""Updates a Intervention from an InterventionForm"""
Expand Down
2 changes: 1 addition & 1 deletion main/templates/base/fetc_form_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{# todo: responsive design #}
<div class="col-3">
{% block stepper %}
{% include "base/stepper.html" %}
{% include stepper %}
{% endblock %}

</div>
Expand Down
20 changes: 8 additions & 12 deletions main/templates/base/stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
<div class="stepper">
<ul>
{% counter counter create 1 %}
{% for url in proposal.available_urls %}
{% for item in stepper.build_stepper %}
<li>
<a class="stepper-item" href="{{ url.url }}">
<span class="stepper-bubble stepper-bubble-largest">{% counter counter value %}</span>
<span>{{ url.title }}</span>
<a class="stepper-item {{ item.css_classes }}" href="{{ item.get_url }}">
<span class="stepper-bubble {{ bubble_size.0 }}">{% counter counter value %}</span>
<span>{{ item.title }}</span>
</a>
{% if url.children %}
{% counter depth create 1 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is not doing anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prevents a bit of ugliness caused by the empty <ul />.

image

Note the inconsistent item spacing and "tail" at the end

{% if item.children %}
<ul>
{% for child in url.children %}
<li>
<a class="stepper-item" href="{{ child.url }}">
<span class="stepper-bubble stepper-bubble-normal"></span>
<span>{{ child.title }}</span>
</a>
</li>
{% for child in item.children %}
{% include child with bubble_size=bubble_size|slice:"1:" %}
{% endfor %}
</ul>
{% endif %}
Expand Down
13 changes: 13 additions & 0 deletions main/templates/base/stepper_item.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<li>
<a class="stepper-item {{ item.css_classes }}" href="{{ item.get_url }}">
<span class="stepper-bubble {{ bubble_size.0 }}"></span>
<span>{{ item.title }}</span>
</a>
{% if item.children %}
<ul>
{% for child in item.children %}
{% include "base/stepper_item.html" with item=child bubble_size=bubble_size|slice:"1:" %}
{% endfor %}
</ul>
{% endif %}
</li>
14 changes: 14 additions & 0 deletions main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db.models import Q
from django.db.models.fields.files import FieldFile
from django.utils.translation import gettext_lazy as _
from django.template import loader, Template, Context

import magic # whoooooo
import pdftotext
Expand Down Expand Up @@ -162,3 +163,16 @@ def can_view_archive(user):
# If our tests are inconclusive,
# check for Humanities affiliation
return is_member_of_humanities(user)


class renderable:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this living here :)

def get_context_data(self):
context = Context()
return context

def render(self, extra_context={}):
context = self.get_context_data()
template = loader.get_template(self.template_name)
context.update(extra_context)
return template.render(context.flatten())
20 changes: 13 additions & 7 deletions observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from main.views import CreateView, UpdateView, AllowErrorsOnBackbuttonMixin
from fetc import settings
from studies.models import Study
from studies.utils import get_study_progress
from studies.mixins import StudyFromURLMixin
from proposals.mixins import StepperContextMixin

from .forms import ObservationForm, ObservationUpdateAttachmentsForm
from .models import Observation
Expand All @@ -13,7 +14,7 @@
#############################
# CRUD actions on Observation
#############################
class ObservationMixin(object):
class ObservationMixin(StepperContextMixin):
"""Mixin for a Observation, to use in both ObservationCreate and ObservationUpdate below"""

model = Observation
Expand Down Expand Up @@ -53,8 +54,12 @@ def get_back_url(self):
return reverse(next_url, args=(pk,))

def get_study(self):
# Um.... what?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha Dunno. Let's get rid and have this mixin get the StudyURLMixin as well.

raise NotImplementedError

def get_proposal(self):
return self.get_object().study.proposal


class AttachmentsUpdate(UpdateView):
model = Observation
Expand All @@ -63,18 +68,19 @@ class AttachmentsUpdate(UpdateView):
group_required = settings.GROUP_SECRETARY


class ObservationCreate(ObservationMixin, AllowErrorsOnBackbuttonMixin, CreateView):
class ObservationCreate(
StudyFromURLMixin,
ObservationMixin,
AllowErrorsOnBackbuttonMixin,
CreateView,
):
"""Creates an Observation from a ObservationForm"""

def form_valid(self, form):
"""Sets the Study on the Observation before starting validation."""
form.instance.study = self.get_study()
return super(ObservationCreate, self).form_valid(form)

def get_study(self):
"""Retrieves the Study from the pk kwarg"""
return Study.objects.get(pk=self.kwargs["pk"])


class ObservationUpdate(ObservationMixin, AllowErrorsOnBackbuttonMixin, UpdateView):
"""Updates a Observation from a ObservationForm"""
Expand Down
55 changes: 47 additions & 8 deletions proposals/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,64 @@
from .utils.proposal_utils import pdf_link_callback


class ProposalMixin(UserFormKwargsMixin):
model = Proposal
form_class = ProposalForm
class StepperContextMixin:
"""
Includes a stepper object in the view's context
"""

def get_next_url(self):
return reverse("proposals:researcher", args=(self.object.pk,))
def get_context_data(self, *args, **kwargs):
# Importing here to prevent circular import
from .utils.stepper import Stepper

context = super().get_context_data(*args, **kwargs)
# Try to determine proposal
proposal = Proposal()
if hasattr(self, "get_proposal"):
proposal = self.get_proposal()
# Initialize and insert stepper object
stepper = Stepper(
proposal,
request=self.request,
)
context["stepper"] = stepper
return context


class ProposalContextMixin:
class ProposalContextMixin(
StepperContextMixin,
):
def current_user_is_supervisor(self):
return self.object.supervisor == self.request.user
return self.get_proposal().supervisor == self.request.user

def get_proposal(
self,
):
try:
if self.model is Proposal:
return self.get_object()
except AttributeError:
raise RuntimeError(
"Couldn't find proposal object for ProposalContextMixin",
)

def get_context_data(self, **kwargs):
context = super(ProposalContextMixin, self).get_context_data(**kwargs)
context["is_supervisor"] = self.current_user_is_supervisor()
context["is_practice"] = self.object.is_practice()
context["is_practice"] = self.get_proposal().is_practice()
return context


class ProposalMixin(
ProposalContextMixin,
):
model = Proposal

def get_proposal(
self,
):
return self.get_object()


class PDFTemplateResponseMixin(TemplateResponseMixin):
"""
A mixin class that implements PDF rendering and Django response construction.
Expand Down
2 changes: 1 addition & 1 deletion proposals/templates/proposals/funding_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

{% block pre-form-text %}
<h3>{% trans "Informatie over financiering" %}</h3>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion proposals/templates/proposals/other_researchers_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

{% block pre-form-text %}
<h3>{% trans "Informatie over betrokken onderzoekers" %}</h3>
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
{% trans "Je bewerkt op het moment een oefenaanvraag. Deze kan niet ter beoordeling door de FETC-GW worden ingediend." %}
</div>
</div>
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion proposals/templates/proposals/pre_approved_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

{% block pre-form-text %}
<h3>{% trans "Informatie over eerdere toesting" %}</h3>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion proposals/templates/proposals/researcher_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

{% block pre-form-text %}
<h3>{% trans "Informatie over de onderzoeker" %}</h3>
{% endblock %}
{% endblock %}
Loading
Loading