Skip to content

Commit

Permalink
Merge branch 'major/4' into feature/review_and_secretary_pages_redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
EdoStorm96 committed Sep 17, 2024
2 parents e52b7e2 + f68d2ca commit 887ed5f
Show file tree
Hide file tree
Showing 22 changed files with 1,507 additions and 65 deletions.
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 sidebar %}
{% 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 %}
{% 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:

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?
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

0 comments on commit 887ed5f

Please sign in to comment.