Skip to content

Commit

Permalink
Merge pull request #2704 from carpentries/feature/2703-automatically-…
Browse files Browse the repository at this point in the history
…generate-and-update-survey-link

Automatically generate and update survey link
  • Loading branch information
pbanaszkiewicz authored Oct 7, 2024
2 parents e3a9c15 + e24db94 commit c9808a3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion amy/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class EventSerializer(serializers.ModelSerializer):

human_readable_date = serializers.CharField(read_only=True)
eligible_for_instructor_recruitment = serializers.BooleanField(read_only=True)
workshop_reports_link = serializers.CharField(read_only=True)
workshop_reports_link = serializers.CharField(
read_only=True, source="instructors_pre"
)
main_tag = serializers.SerializerMethodField()

class Meta:
Expand Down
3 changes: 1 addition & 2 deletions amy/templates/includes/event_details_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
<tr class="{% if not event.url %}table-danger{% endif %}"><th>Website URL:</th><td colspan="2">{{ event.website_url|default:"&mdash;"|urlize_newtab }} {% if event.url %}<a href="{% url 'validate_event' event.slug %}" class="btn btn-primary btn-sm float-right" id="validate_event" data-toggle="modal" data-target="#validation_modal">Validate event</a>{% else %}<a class="btn btn-danger btn-sm float-right" id="error_event_url" tabindex="0" role="button" data-toggle="popover" title="Validation error" data-content="Cannot validate an event without URL pointing to the event website, e.g.: <code>https://swcarpentry.github.io/2015-05-24-training</code>" data-html="true" data-trigger="focus">Error</a>{% endif %}</td></tr>
<tr><th>Language:</th><td colspan="2">{{ event.language|default:"&mdash;" }}</td></tr>
<tr><th>Eventbrite key:</th><td colspan="2">{% if event.reg_key %}<a href="https://www.eventbrite.com/myevent?eid={{ event.reg_key }}" title="Go to Eventbrite's page for this event" target="_blank" rel="noreferrer">{{ event.reg_key }}</a>{% else %}&mdash;{% endif %}</td></tr>
<tr><th>Pre-workshop assessment survey for instructors</th><td colspan="2">{{ event.instructors_pre|default:"&mdash;"|urlize_newtab}}</td></tr>
<tr><th>Post-workshop assessment survey for instructors</th><td colspan="2">{{ event.instructors_post|default:"&mdash;"|urlize_newtab}}</td></tr>
<tr><th>Assessment survey for instructors:</th><td colspan="2">{{ event.instructors_pre|default:"&mdash;"|urlize_newtab}}</td></tr>
<tr class="{% if not event.attendance %}table-danger{% endif %}">
<th>Attendance:</th>
<td colspan="2">
Expand Down
11 changes: 9 additions & 2 deletions amy/workshops/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ class EventForm(forms.ModelForm):
required=False,
)

instructors_pre = forms.URLField(
label="Assessment survey for instructors:",
help_text=(
"Auto-generated as long as the event is NOT marked as complete and "
"it has a slug."
),
required=False,
)

helper = BootstrapHelper(add_cancel_button=False, duplicate_buttons_on_top=True)

class Meta:
Expand Down Expand Up @@ -438,7 +447,6 @@ class Meta:
"lessons",
"public_status",
"instructors_pre",
"instructors_post",
"comment",
]
widgets = {
Expand Down Expand Up @@ -486,7 +494,6 @@ def __init__(self, *args, **kwargs):
"manual_attendance",
"contact",
"instructors_pre",
"instructors_post",
Div(
Div(HTML("Location details"), css_class="card-header"),
Div(
Expand Down
3 changes: 3 additions & 0 deletions amy/workshops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,9 @@ def save(self, *args, **kwargs):
self.latitude = None
self.longitude = None

if self.slug and not self.completed:
self.instructors_pre = reports_link(self.slug)

super().save(*args, **kwargs)


Expand Down
2 changes: 2 additions & 0 deletions amy/workshops/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ def test_merging_basic_attributes(self):
"longitude": self.event_a.longitude,
"learners_pre": self.event_b.learners_pre,
"learners_post": self.event_a.learners_post,
# Doesn't follow strategy, because it's refreshed with a slug from Event A:
"instructors_pre": self.event_b.instructors_pre,
"instructors_post": self.event_a.instructors_post,
"learners_longterm": self.event_b.learners_longterm,
Expand All @@ -1113,6 +1114,7 @@ def test_merging_basic_attributes(self):
rv = self.client.post(self.url, data=self.strategy)
self.assertEqual(rv.status_code, 302)
self.event_b.refresh_from_db()
assertions["instructors_pre"] = self.event_b.instructors_pre # needs refresh

for key, value in assertions.items():
self.assertEqual(getattr(self.event_b, key), value, key)
Expand Down

0 comments on commit c9808a3

Please sign in to comment.