diff --git a/README.md b/README.md index f985ad0..bc646ee 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## O projekte Trojsten ID vznikol ako náhrada predchádzajúceho `login.trojsten.sk` riešenia. Jeho snahou je vytvoriť jednotný -prihlasovací systém pre všetky Trojsten stránky a služby. Taktiež poskytuje informácie o používateľoch a (čoskoro) +prihlasovací systém pre všetky Trojsten stránky a služby. Taktiež poskytuje informácie o používateľoch a verejné profily. ## Inštalácia a quick-start diff --git a/trojstenid/badges/__init__.py b/trojstenid/badges/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/trojstenid/badges/admin.py b/trojstenid/badges/admin.py new file mode 100644 index 0000000..99a8287 --- /dev/null +++ b/trojstenid/badges/admin.py @@ -0,0 +1,18 @@ +from django.contrib import admin + +from trojstenid.badges.models import Badge, BadgeAssignment, BadgeGroup + + +class BadgeAssignmentInline(admin.TabularInline): + model = BadgeAssignment + + +@admin.register(Badge) +class BadgeAdmin(admin.ModelAdmin): + list_filter = ["group", "title"] + inlines = [BadgeAssignmentInline] + + +@admin.register(BadgeGroup) +class BadgeGroupAdmin(admin.ModelAdmin): + list_filter = ["title"] diff --git a/trojstenid/badges/apps.py b/trojstenid/badges/apps.py new file mode 100644 index 0000000..1d58983 --- /dev/null +++ b/trojstenid/badges/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class BadgesConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "trojstenid.badges" diff --git a/trojstenid/badges/migrations/0001_initial.py b/trojstenid/badges/migrations/0001_initial.py new file mode 100644 index 0000000..9b53f92 --- /dev/null +++ b/trojstenid/badges/migrations/0001_initial.py @@ -0,0 +1,97 @@ +# Generated by Django 4.2.4 on 2023-09-10 19:09 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="Badge", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("image", models.ImageField(upload_to="")), + ("title", models.CharField(max_length=100)), + ("description", models.CharField(max_length=300)), + ("order", models.IntegerField(default=0)), + ], + options={ + "ordering": ["group", "order", "title"], + }, + ), + migrations.CreateModel( + name="BadgeGroup", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ], + options={ + "ordering": ["title"], + }, + ), + migrations.CreateModel( + name="BadgeAssignment", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "badge", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="badges.badge" + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + migrations.AddField( + model_name="badge", + name="group", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="badges.badgegroup" + ), + ), + migrations.AddConstraint( + model_name="badgeassignment", + constraint=models.UniqueConstraint( + models.F("badge"), models.F("user"), name="badge_assignment__unique" + ), + ), + ] diff --git a/trojstenid/badges/migrations/__init__.py b/trojstenid/badges/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/trojstenid/badges/models.py b/trojstenid/badges/models.py new file mode 100644 index 0000000..0d064ac --- /dev/null +++ b/trojstenid/badges/models.py @@ -0,0 +1,38 @@ +from django.conf import settings +from django.db import models +from django.db.models import UniqueConstraint + + +class BadgeGroup(models.Model): + title = models.CharField(max_length=100) + + class Meta: + ordering = ["title"] + + def __str__(self): + return self.title + + +class Badge(models.Model): + image = models.ImageField() + title = models.CharField(max_length=100) + description = models.CharField(max_length=300) + group = models.ForeignKey(BadgeGroup, on_delete=models.CASCADE) + order = models.IntegerField(default=0) + + class Meta: + ordering = ["group", "order", "title"] + + def __str__(self): + return self.title + + +class BadgeAssignment(models.Model): + badge = models.ForeignKey(Badge, on_delete=models.CASCADE) + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + created_at = models.DateTimeField(auto_now_add=True) + + class Meta: + constraints = [ + UniqueConstraint("badge", "user", name="badge_assignment__unique"), + ] diff --git a/trojstenid/badges/views.py b/trojstenid/badges/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/trojstenid/badges/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/trojstenid/profiles/templates/profile/profile.html b/trojstenid/profiles/templates/profile/profile.html new file mode 100644 index 0000000..342ce11 --- /dev/null +++ b/trojstenid/profiles/templates/profile/profile.html @@ -0,0 +1,53 @@ +{% extends "base.html" %} + +{% block title %}{{ object.get_full_name }} - {{ block.super }}{% endblock %} + +{% block body %} + +
{{ item.title }}
+{{ item.description }}
+Tento používateľ zatiaľ nezískal žiadne odznaky.
+