Repository: svthalia/concrexit

Issue:
Automatically set referral event-slide hyperlink to event page
In GitLab by @JobDoesburg on Dec 4, 2019, 19:29

<!--
    You want something new.
-->

### One-sentence description

Automatically set referral event-slide hyperlink to event page 

### Motivation

Usability

### Desired functionality

If you set a slide to be an event slide, automatically fill in the hyperlink field with a URL to the event page (and maybe also auto fill in the title to be the event title?)

### Suggested implementation

<!--
    If you have any notes on how we could achieve this feature,
    share them here.
-->


Discussion:
In GitLab by @se-bastiaan on Dec 4, 2019, 19:35

I'm not sure I understand correctly. The reference for an  slide is made from the event side. Do you want to autofill these values when you create it while adding an event? Since you're not selecting the event while creating the slide. 
In GitLab by @JobDoesburg on Dec 4, 2019, 20:01

If you add the event, and within that form also add the event slide, it should be autofilled.
In GitLab by @se-bastiaan on Dec 4, 2019, 20:12

Okay that is not really easy to do.
In GitLab by @JobDoesburg on Dec 4, 2019, 20:13

I never gave it an 'easy and fun' label

Resolving patch:
diff --git a/website/announcements/migrations/0016_rename_url_slide_custom_url.py b/website/announcements/migrations/0016_rename_url_slide_custom_url.py
new file mode 100644
--- /dev/null
+++ b/website/announcements/migrations/0016_rename_url_slide_custom_url.py
@@ -0,0 +1,27 @@
+# Generated by Django 4.1.7 on 2023-03-01 19:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("announcements", "0015_remove_slide_linked_event_slide_event"),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name="slide",
+            old_name="url",
+            new_name="custom_url",
+        ),
+        migrations.AlterField(
+            model_name="slide",
+            name="custom_url",
+            field=models.URLField(
+                blank=True,
+                help_text="Place the user is taken to when clicking the slide. If left blank, will default to the linked event, if any.",
+                null=True,
+                verbose_name="Link",
+            ),
+        ),
+    ]
diff --git a/website/announcements/models.py b/website/announcements/models.py
--- a/website/announcements/models.py
+++ b/website/announcements/models.py
@@ -188,9 +188,12 @@ class Slide(models.Model):
         verbose_name=_("Display only for authenticated members"), default=False
     )
 
-    url = models.URLField(
+    custom_url = models.URLField(
         verbose_name=_("Link"),
-        help_text=_("Place the user is taken to when clicking the slide"),
+        help_text=_(
+            "Place the user is taken to when clicking the slide. "
+            "If left blank, will default to the linked event, if any."
+        ),
         blank=True,
         null=True,
     )
@@ -242,5 +245,13 @@ def is_visible(self):
             and not (self.since is None and self.until is None)
         )
 
+    @property
+    def url(self):
+        if self.custom_url:
+            return self.custom_url
+        if self.event:
+            return self.event.get_absolute_url()
+        return None
+
     def __str__(self):
         return str(self.title)


Test patch: