Skip to content

Commit

Permalink
Implement Web Module (#73)
Browse files Browse the repository at this point in the history
* Implement Web Module

* Update help text

* Fix iSort

* PR Changes

* Fix Migrations
  • Loading branch information
NathHorrigan authored and mixxorz committed Jun 1, 2021
1 parent dbc74a5 commit 8440d7c
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 1 deletion.
11 changes: 11 additions & 0 deletions flare_portal/experiments/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
FearConditioningModule,
Participant,
Project,
WebModule,
)


Expand Down Expand Up @@ -93,3 +94,13 @@ class Meta:
required_answer = factory.Faker("random_element", elements=[True, False])

module = factory.SubFactory(CriterionModuleFactory)


class WebModuleFactory(factory.django.DjangoModelFactory):
class Meta:
model = WebModule

url = "http://google.com"
intro_text = factory.Faker("heading")
help_text = factory.Faker("paragraph")
append_participant_id = True
49 changes: 49 additions & 0 deletions flare_portal/experiments/migrations/0029_webmodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 3.1.4 on 2020-12-21 08:59

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("experiments", "0028_basic_info_unique"),
]

operations = [
migrations.CreateModel(
name="WebModule",
fields=[
(
"basemodule_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="experiments.basemodule",
),
),
("heading", models.CharField(max_length=255)),
("description", models.TextField(blank=True)),
("url", models.URLField(verbose_name="URL")),
(
"auto_close_url",
models.URLField(
blank=True,
help_text="Optional: Enter a URL here that if redirected to will automatically close this module.",
verbose_name="Automatic close URL",
),
),
(
"append_participant_id",
models.BooleanField(
blank=True,
help_text="Optional: Enabling this feature will append theparticpant's id to the url. This is useful if you are using a survey service such as Qualtrics or Google Forms.",
),
),
],
bases=("experiments.basemodule",),
),
]
2 changes: 2 additions & 0 deletions flare_portal/experiments/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CriterionModule,
CriterionQuestion,
FearConditioningModule,
WebModule,
)

__all__ = [
Expand All @@ -21,4 +22,5 @@
"FearConditioningModule",
"Participant",
"Project",
"WebModule",
]
37 changes: 37 additions & 0 deletions flare_portal/experiments/models/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,40 @@ def get_module_description(self) -> str:

def __str__(self) -> str:
return "Criterion - " + super().__str__()


class WebModule(BaseModule):
heading = models.CharField(max_length=255)
description = models.TextField(blank=True)
url = models.URLField(verbose_name="URL")
auto_close_url = models.URLField(
blank=True,
verbose_name="Automatic close URL",
help_text="Optional: Enter a URL here that if redirected to will "
"automatically close this module.",
)
append_participant_id = models.BooleanField(
blank=True,
help_text="Optional: Enabling this feature will append the"
"particpant's id to the url. This is useful if you are using a "
"survey service such as Qualtrics or Google Forms.",
)

def get_module_config(self) -> constants.ModuleConfigType:
return constants.ModuleConfigType(
id=self.pk,
type=self.get_module_tag(),
config={
"heading": self.heading,
"description": self.description,
"url": self.url,
"append_participant_id": self.append_participant_id,
"auto_close_url": self.auto_close_url,
},
)

def get_module_description(self) -> str:
return f"{self.heading} ({self.url})"

def __str__(self) -> str:
return "Web - " + super().__str__()
2 changes: 2 additions & 0 deletions flare_portal/experiments/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
FearConditioningData,
FearConditioningModule,
Participant,
WebModule,
)


Expand Down Expand Up @@ -208,6 +209,7 @@ class CreateMeta:
module_registry.register(BasicInfoModule)
module_registry.register(CriterionModule)
module_registry.register(FearConditioningModule)
module_registry.register(WebModule)


class DataViewMixin:
Expand Down
10 changes: 10 additions & 0 deletions flare_portal/static_src/sass/vendor/_tabler.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16078,6 +16078,16 @@ a.tag-addon:hover {
margin: 0;
}

.custom-switch--with-description {
padding-top: 0.75rem;
align-items: flex-start;
justify-content: space-between;

.custom-switch-description {
width: 50%;
}
}

.custom-switch-input {
position: absolute;
z-index: -1;
Expand Down
6 changes: 5 additions & 1 deletion flare_portal/templates/includes/form-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
{% if field|widget_type == 'horizontalcheckboxselectmultiple' %}
{{ field|add_error_class:"is-invalid" }}
{% elif field|widget_type == 'checkboxinput' %}
<label class="custom-switch">
<label class="custom-switch {% if field.help_text %}custom-switch--with-description{% endif %}">
{{ field|add_class:"custom-switch-input" }}
<span class="custom-switch-indicator"></span>
<span class="custom-switch-description">{{ field.label }}</span>

{% if field.help_text %}
<p class="custom-switch-description">{{ field.help_text }}</p>
{% endif %}
</label>
{% elif field|widget_type == 'select' %}
{{ field|add_class:"form-control custom-select"|add_error_class:"is-invalid"|attr:"data-selectize" }}
Expand Down

0 comments on commit 8440d7c

Please sign in to comment.