From 2f0936df09a5464f393cb6fb30398d088e141746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Mon, 13 Jan 2020 00:59:44 +0100 Subject: [PATCH] Add custom dashboard buttons (#17) Introduce model Introduce admin interface Show buttons on dashboard start page --- AKDashboard/admin.py | 11 ++++++- AKDashboard/migrations/0001_initial.py | 32 +++++++++++++++++++ AKDashboard/models.py | 32 ++++++++++++++++++- .../templates/AKDashboard/dashboard.html | 9 ++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 AKDashboard/migrations/0001_initial.py diff --git a/AKDashboard/admin.py b/AKDashboard/admin.py index 846f6b40..724ac31c 100644 --- a/AKDashboard/admin.py +++ b/AKDashboard/admin.py @@ -1 +1,10 @@ -# Register your models here. +from django.contrib import admin +from AKDashboard.models import DashboardButton + + +@admin.register(DashboardButton) +class DashboardButtonAdmin(admin.ModelAdmin): + list_display = ['text', 'url', 'event'] + list_filter = ['event'] + search_fields = ['text', 'url'] + list_display_links = ['text'] diff --git a/AKDashboard/migrations/0001_initial.py b/AKDashboard/migrations/0001_initial.py new file mode 100644 index 00000000..0d969dca --- /dev/null +++ b/AKDashboard/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 2.2.6 on 2020-01-12 23:30 + +from django.db import migrations, models +import django.db.models.deletion +import fontawesome_5.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('AKModel', '0026_akslot_updated'), + ] + + operations = [ + migrations.CreateModel( + name='DashboardButton', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.CharField(help_text='Text that will be shown on the button', max_length=50, verbose_name='Text')), + ('url', models.URLField(help_text='URL this button links to', verbose_name='Link URL')), + ('icon', fontawesome_5.fields.IconField(blank=True, default='external-link-alt', help_text='Symbol represeting this button.', max_length=60, verbose_name='Icon')), + ('color', models.PositiveSmallIntegerField(choices=[(0, 'primary'), (1, 'success'), (2, 'info'), (3, 'warning'), (4, 'danger')], default=0, help_text='Style (Color) of this button (bootstrap class)', verbose_name='Button Style')), + ('event', models.ForeignKey(help_text='Event this button belongs to', on_delete=django.db.models.deletion.CASCADE, to='AKModel.Event', verbose_name='Event')), + ], + options={ + 'verbose_name': 'Dashboard Button', + 'verbose_name_plural': 'Dashboard Buttons', + }, + ), + ] diff --git a/AKDashboard/models.py b/AKDashboard/models.py index 6b202199..f0e2745a 100644 --- a/AKDashboard/models.py +++ b/AKDashboard/models.py @@ -1 +1,31 @@ -# Create your models here. +from django.db import models +from django.utils.translation import gettext_lazy as _ +from fontawesome_5.fields import IconField + +from AKModel.models import Event + + +class DashboardButton(models.Model): + class Meta: + verbose_name = _("Dashboard Button") + verbose_name_plural = _("Dashboard Buttons") + + COLOR_CHOICES = ( + (0, "primary"), + (1, "success"), + (2, "info"), + (3, "warning"), + (4, "danger"), + ) + + text = models.CharField(max_length=50, blank=False, verbose_name=_("Text"), + help_text=_("Text that will be shown on the button")) + url = models.URLField(blank=False, verbose_name=_("Link URL"), help_text=_("URL this button links to")) + icon = IconField(default="external-link-alt", verbose_name=_("Icon"), help_text="Symbol represeting this button.") + color = models.PositiveSmallIntegerField(choices=COLOR_CHOICES, default=0, blank=False, + verbose_name=_("Button Style"), help_text=_("Style (Color) of this button (bootstrap class)")) + event = models.ForeignKey(to=Event, on_delete=models.CASCADE, blank=False, null=False, + verbose_name=_("Event"), help_text=_("Event this button belongs to")) + + def __str__(self): + return f"{self.text} ({self.event})" diff --git a/AKDashboard/templates/AKDashboard/dashboard.html b/AKDashboard/templates/AKDashboard/dashboard.html index 3d28e9e4..5f4df6f2 100644 --- a/AKDashboard/templates/AKDashboard/dashboard.html +++ b/AKDashboard/templates/AKDashboard/dashboard.html @@ -48,6 +48,15 @@ </div> </a> {% endif %} + {% for button in event.dashboardbutton_set.all %} + <a class="dashboard-box btn btn-{{ button.get_color_display }}" + href="{{ button.url }}"> + <div class="col-sm-12 col-md-3 col-lg-2 dashboard-button"> + {% if button.icon %}<span class="fa">{{ button.icon.as_html }}</span>{% endif %} + <span class='text'>{{ button.text }}</span> + </div> + </a> + {% endfor %} </div> {% if event.contact_email %} <p> -- GitLab