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

Production Release - 2024-06-25 #414

Merged
merged 13 commits into from
Jun 25, 2024
Merged
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ This is an example of how to list things you need to use the software and how to
```sh
pip install -r requirements/requirements-dev.txt
```

set up the git hook scripts
```sh
pre-commit install
```
5. Copy `.env.template.local` file, rename to `.env` and use variables for your local postgres database.
Copy in Linux:
```sh
Expand Down
74 changes: 41 additions & 33 deletions home/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,28 @@ class Meta:
template = "blocks/heading.html"


class ListItemBlock(blocks.StructBlock):
text = blocks.CharBlock()
link = blocks.URLBlock(required=False)
icon = blocks.CharBlock(
max_length=50,
required=False,
help_text="Use font awesome class names ex: 'fa-solid fa-xs fa-tv'",
)
icon_color = blocks.CharBlock(
max_length=50, required=False, help_text="Names, hex etc ex: 'grey', '#999999'"
)


class ListBlock(blocks.StructBlock):
size = blocks.ChoiceBlock(
style = blocks.ChoiceBlock(
choices=[
("circle", "unordered list"),
("decimal", "ordered list"),
("none", "unstyled"),
]
)
text = blocks.RichTextBlock(features=["ul"], icon="list-ol")
list_items = blocks.ListBlock(ListItemBlock())

def __str__(self):
return self.text
Expand All @@ -81,7 +94,9 @@ class Meta:


class TextWithHeadingWithRightImageBlock(blocks.StructBlock):
heading = blocks.CharBlock(max_length=255, class_name="heading-blog")
heading = blocks.CharBlock(
max_length=255, class_name="heading-blog", required=False
)
text = blocks.TextBlock()
image = ImageChooserBlock()

Expand All @@ -94,7 +109,7 @@ class Meta:


class TextWithHeadingWithLeftImageBlock(blocks.StructBlock):
heading = blocks.CharBlock(max_length=255, class_name="blog")
heading = blocks.CharBlock(max_length=255, class_name="blog", required=False)
text = blocks.TextBlock()
image = ImageChooserBlock()

Expand All @@ -106,30 +121,6 @@ class Meta:
template = "blocks/text-with-heading-left-image.html"


class RightImageLeftTextBlock(blocks.StructBlock):
image = ImageChooserBlock()
text = blocks.TextBlock()

def __str__(self):
return self.text

class Meta:
label = "Text Block: Right Image"
template = "blocks/right-image-left-text.html"


class LeftImageRightTextBlock(blocks.StructBlock):
image = ImageChooserBlock()
text = blocks.TextBlock()

def __str__(self):
return self.text

class Meta:
label = "Text Block: Left Image"
template = "blocks/left-image-right-text.html"


class QuoteBlock(blocks.StructBlock):
text = blocks.CharBlock(max_length=255)
attribution = blocks.CharBlock(max_length=255)
Expand Down Expand Up @@ -184,10 +175,9 @@ class Meta:


class TextHeadingImageBlock(blocks.StructBlock):
heading = blocks.CharBlock(max_length=255)
text = blocks.TextBlock()
heading = blocks.CharBlock(max_length=255, required=False)
text = blocks.TextBlock(required=False)
image = ImageChooserBlock()
# TODO: Add left or right side

def __str__(self):
return self.heading
Expand All @@ -209,6 +199,25 @@ class Meta:
template = "blocks/caption.html"


class VerticalImageCardBlock(blocks.StreamBlock):
images = blocks.StructBlock(
[
("image", ImageChooserBlock(required=True, help_text="size: 800X450px")),
("caption", CustomCaption()),
(
"description",
blocks.CharBlock(
max_length=300, required=False, help_text="300 characters limit"
),
),
("link", blocks.URLBlock(required=False)),
]
)

class Meta:
template = "blocks/vertical_image_cards_block.html"


class RichTextBlock(blocks.StructBlock):
text = blocks.RichTextBlock(
max_length=10000,
Expand Down Expand Up @@ -243,9 +252,8 @@ class BaseStreamBlock(blocks.StreamBlock):
text_with_heading_and_image = TextHeadingImageBlock()
text_with_heading_and_right_image = TextWithHeadingWithRightImageBlock()
text_with_heading_and_left_image = TextWithHeadingWithLeftImageBlock()
right_image_left_text = RightImageLeftTextBlock()
left_image_right_text = LeftImageRightTextBlock()
left_quote_right_image = QuoteLeftImageBlock(icon="openquote")
video_embed = VideoEmbed()
table = CustomTableBlock()
code_block = CodeBlock()
vertical_image_cards = VerticalImageCardBlock()
21 changes: 20 additions & 1 deletion home/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def make_choices(question: Question) -> list[tuple[str, str]]:


class BaseSurveyForm(forms.Form):
def __init__(self, survey, user, *args, **kwargs):
def __init__(self, *args, survey, user, **kwargs):
self.survey = survey
self.user = user if user.is_authenticated else None
self.field_names = []
Expand Down Expand Up @@ -158,3 +158,22 @@ def save(self):
value=value,
user_survey_response=user_survey_response,
)


class UserSurveyResponseForm(BaseSurveyForm):
def __init__(self, *args, instance, **kwargs):
self.survey = instance.survey
self.user_survey_response = instance
super().__init__(*args, survey=self.survey, user=instance.user, *args, **kwargs)
self._set_initial_data()

def _set_initial_data(self):
question_responses = self.user_survey_response.userquestionresponse_set.all()

for question_response in question_responses:
field_name = f"field_survey_{question_response.question.id}"
if question_response.question.type_field == TypeField.MULTI_SELECT:
self.fields[field_name].initial = question_response.value.split(",")
else:
self.fields[field_name].initial = question_response.value
self.fields[field_name].disabled = True
6 changes: 3 additions & 3 deletions home/managers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from django.db.models import Exists
from django.db.models import OuterRef
from django.db.models import Subquery
from django.db.models import Value
from django.db.models.query import QuerySet
from django.utils import timezone
Expand Down Expand Up @@ -37,10 +37,10 @@ def with_applications(self, user):
if user.is_anonymous:
return self.annotate(completed_application=Value(False))
return self.annotate(
completed_application=Exists(
completed_application=Subquery(
UserSurveyResponse.objects.filter(
survey_id=OuterRef("application_survey_id"), user_id=user.id
)
).values("id")[:1]
)
)

Expand Down
Loading
Loading