Skip to content

Commit

Permalink
add basic data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
lilioid committed Feb 29, 2024
1 parent 1353b00 commit 8bebc7f
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/mafiasi_kultur/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@

from . import models

admin.site.register(models.MafiasiUser, UserAdmin)
admin.site.login_template = "core/login.html"
admin.site.register(models.MafiasiUser, UserAdmin)
admin.site.register(models.AG)
admin.site.register(models.Medium)
admin.site.register(models.Proposal)
admin.site.register(models.Viewing)
admin.site.register(models.Vote)
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Generated by Django 4.2.10 on 2024-02-29 19:09

import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("mafiasi_kultur_core", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="AG",
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("name", models.CharField(max_length=64)),
],
),
migrations.CreateModel(
name="Medium",
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("name", models.CharField(max_length=128)),
(
"ag",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="mediums",
to="mafiasi_kultur_core.ag",
),
),
],
),
migrations.CreateModel(
name="Proposal",
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("note", models.TextField()),
(
"medium",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to="mafiasi_kultur_core.medium"
),
),
(
"proposed_by",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="proposed_mediums",
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="Vote",
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("value", models.IntegerField(choices=[(-1, "dislike"), (0, "don't care"), (1, "like")])),
(
"proposal",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="mafiasi_kultur_core.proposal"
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
],
),
migrations.CreateModel(
name="Viewing",
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("viewed_at", models.DateTimeField()),
("note", models.TextField()),
(
"medium",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to="mafiasi_kultur_core.medium"
),
),
],
),
migrations.AddField(
model_name="proposal",
name="votes",
field=models.ManyToManyField(through="mafiasi_kultur_core.Vote", to=settings.AUTH_USER_MODEL),
),
]
65 changes: 65 additions & 0 deletions src/mafiasi_kultur/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,68 @@ class MafiasiUser(AbstractUser):
"""

id = models.UUIDField(primary_key=True, default=uuid.uuid4)


class AG(models.Model):
"""
The AG for which everything is scoped
"""

id = models.UUIDField(primary_key=True, default=uuid.uuid4)
name = models.CharField(max_length=64)

def __str__(self):
return f"{self.name} AG"


class Medium(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
ag = models.ForeignKey(to="AG", on_delete=models.PROTECT, related_name="mediums")
name = models.CharField(max_length=128)

def __str__(self):
return self.name


class Proposal(models.Model):
"""
A proposal for a new media that the AG wishes to consume
"""

id = models.UUIDField(primary_key=True, default=uuid.uuid4)
medium = models.OneToOneField(to="Medium", on_delete=models.CASCADE)
note = models.TextField()
proposed_by = models.ForeignKey(
to="MafiasiUser", on_delete=models.PROTECT, related_name="proposed_mediums"
)
votes = models.ManyToManyField(to="MafiasiUser", through="Vote", through_fields=("proposal", "user"))

def __str__(self):
return self.medium.name


class Vote(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
proposal = models.ForeignKey(to="Proposal", on_delete=models.CASCADE)
user = models.ForeignKey(to="MafiasiUser", on_delete=models.CASCADE)
value = models.IntegerField(
choices=[
(-1, "dislike"),
(0, "don't care"),
(+1, "like"),
]
)


class Viewing(models.Model):
"""
A viewing of a certain medium
"""

id = models.UUIDField(primary_key=True, default=uuid.uuid4)
medium = models.OneToOneField(to="Medium", on_delete=models.CASCADE)
viewed_at = models.DateTimeField()
note = models.TextField()

def __str__(self):
return self.medium.name
2 changes: 1 addition & 1 deletion src/mafiasi_kultur/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
OPENID_CLIENT_ID = env.str("DJANGO_OPENID_CLIENT_ID")
OPENID_CLIENT_SECRET = env.str("DJANGO_OPENID_CLIENT_SECRET")
OPENID_ISSUER = env.str("OPENID_ISSUER", default="https://identity.mafiasi.de/realms/mafiasi")
OPENID_SCOPE = "openid"
OPENID_SCOPE = "openid profile"
OPENID_USER_MAPPER = "mafiasi_kultur.core.oidc_user_mapping.MafiasiUserMapper"
OPENID_ANY_USER_IS_ADMIN = env.bool("DJANGO_ANY_OPENID_USER_IS_ADMIN", default=False)
OPENID_SUPERUSER_GROUPS = env.list("DJANGO_OPENID_SUPERUSER_GROUPS", default=[])
Expand Down

0 comments on commit 8bebc7f

Please sign in to comment.