Skip to content
Snippets Groups Projects
Commit 2f0936df authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Add custom dashboard buttons (#17)

Introduce model
Introduce admin interface
Show buttons on dashboard start page
parent a3e388c0
No related branches found
No related tags found
1 merge request!9Dashboard custom buttons
This commit is part of merge request !9. Comments created here will be created in the context of that merge request.
# 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']
# 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',
},
),
]
# 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})"
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment