-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created models for penn wrapped -- issue with pip files though (#309)
* Created models * pip file fix * Fixed models.py and added to admin.py * models * Penn-Wrapped Backend Requests * fix github pipfile diff for no reason + others * Updated Models Finished Models for wrapped and serializer working * Fixes * Penn-Wrapped Prod Push Request Format: /wrapped/generate/semester=2020A --------- Co-authored-by: vcai122 <[email protected]>
- Loading branch information
1 parent
8315c52
commit d1044c2
Showing
13 changed files
with
454 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.contrib import admin | ||
|
||
from wrapped.models import ( | ||
GlobalStat, | ||
GlobalStatKey, | ||
GlobalStatPageField, | ||
IndividualStat, | ||
IndividualStatKey, | ||
IndividualStatPageField, | ||
Page, | ||
Semester, | ||
) | ||
|
||
|
||
class WrappedIndividualAdmin(admin.ModelAdmin): | ||
search_fields = ["user__username__icontains", "key__key__icontains", "semester__icontains"] | ||
list_display = ["user", "key", "value", "semester"] | ||
|
||
|
||
class WrappedGlobalAdmin(admin.ModelAdmin): | ||
|
||
list_display = ["key", "value", "semester"] | ||
search_fields = ["key__icontains"] | ||
|
||
|
||
class IndividualStatPageFieldAdmin(admin.TabularInline): | ||
model = IndividualStatPageField | ||
extra = 1 | ||
|
||
|
||
class GlobalStatPageFieldAdmin(admin.TabularInline): | ||
model = GlobalStatPageField | ||
extra = 1 | ||
|
||
|
||
class PageAdmin(admin.ModelAdmin): | ||
inlines = [IndividualStatPageFieldAdmin, GlobalStatPageFieldAdmin] | ||
|
||
|
||
admin.site.register(IndividualStat, WrappedIndividualAdmin) | ||
admin.site.register(GlobalStat, WrappedGlobalAdmin) | ||
admin.site.register(IndividualStatKey) | ||
admin.site.register(GlobalStatKey) | ||
admin.site.register(Page, PageAdmin) | ||
admin.site.register(Semester) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class WrappedConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "wrapped" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# Generated by Django 5.0.2 on 2024-11-10 16:21 | ||
|
||
import datetime | ||
|
||
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="GlobalStatKey", | ||
fields=[ | ||
("key", models.CharField(max_length=50, primary_key=True, serialize=False)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="IndividualStatKey", | ||
fields=[ | ||
("key", models.CharField(max_length=50, primary_key=True, serialize=False)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="GlobalStatPageField", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
("text_field_name", models.CharField(max_length=50)), | ||
( | ||
"global_stat_key", | ||
models.ForeignKey( | ||
default=None, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="wrapped.globalstatkey", | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="IndividualStatPageField", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
("text_field_name", models.CharField(max_length=50)), | ||
( | ||
"individual_stat_key", | ||
models.ForeignKey( | ||
default=None, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="wrapped.individualstatkey", | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Page", | ||
fields=[ | ||
("name", models.CharField(max_length=50, primary_key=True, serialize=False)), | ||
("template_path", models.CharField(max_length=50)), | ||
("duration", models.DurationField(blank=True, default=datetime.timedelta(0))), | ||
( | ||
"global_stats", | ||
models.ManyToManyField( | ||
blank=True, | ||
through="wrapped.GlobalStatPageField", | ||
to="wrapped.globalstatkey", | ||
), | ||
), | ||
( | ||
"individual_stats", | ||
models.ManyToManyField( | ||
blank=True, | ||
through="wrapped.IndividualStatPageField", | ||
to="wrapped.individualstatkey", | ||
), | ||
), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="individualstatpagefield", | ||
name="Page", | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="wrapped.page"), | ||
), | ||
migrations.AddField( | ||
model_name="globalstatpagefield", | ||
name="Page", | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="wrapped.page"), | ||
), | ||
migrations.CreateModel( | ||
name="Semester", | ||
fields=[ | ||
("semester", models.CharField(max_length=5, primary_key=True, serialize=False)), | ||
("pages", models.ManyToManyField(blank=True, to="wrapped.page")), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="IndividualStat", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
("value", models.CharField(max_length=50)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
( | ||
"key", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="wrapped.individualstatkey" | ||
), | ||
), | ||
( | ||
"semester", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="wrapped.semester" | ||
), | ||
), | ||
], | ||
options={ | ||
"unique_together": {("key", "semester", "user")}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="GlobalStat", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
("value", models.CharField(max_length=50)), | ||
( | ||
"key", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="wrapped.globalstatkey" | ||
), | ||
), | ||
( | ||
"semester", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="wrapped.semester" | ||
), | ||
), | ||
], | ||
options={ | ||
"unique_together": {("key", "semester")}, | ||
}, | ||
), | ||
] |
30 changes: 30 additions & 0 deletions
30
backend/wrapped/migrations/0002_rename_page_globalstatpagefield_page_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 5.0.2 on 2024-11-10 17:40 | ||
|
||
import datetime | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("wrapped", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="globalstatpagefield", | ||
old_name="Page", | ||
new_name="page", | ||
), | ||
migrations.RenameField( | ||
model_name="individualstatpagefield", | ||
old_name="Page", | ||
new_name="page", | ||
), | ||
migrations.AlterField( | ||
model_name="page", | ||
name="duration", | ||
field=models.DurationField(blank=True, default=datetime.timedelta(0), null=True), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from datetime import timedelta | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.db import models | ||
|
||
|
||
User = get_user_model() | ||
|
||
|
||
class StatKey(models.Model): | ||
key = models.CharField(max_length=50, primary_key=True, null=False, blank=False) | ||
|
||
def __str__(self) -> str: | ||
return self.key | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
|
||
class IndividualStatKey(StatKey): | ||
pass | ||
|
||
|
||
class GlobalStatKey(StatKey): | ||
pass | ||
|
||
|
||
class Semester(models.Model): | ||
semester = models.CharField(max_length=5, primary_key=True, null=False, blank=False) | ||
pages = models.ManyToManyField("Page", blank=True) | ||
|
||
|
||
class GlobalStat(models.Model): | ||
|
||
key = models.ForeignKey(GlobalStatKey, on_delete=models.CASCADE) | ||
value = models.CharField(max_length=50, null=False, blank=False) | ||
semester = models.ForeignKey(Semester, on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
unique_together = ("key", "semester") | ||
|
||
def __str__(self): | ||
return f"Global -- {self.key}-{str(self.semester)} : {self.value}" | ||
|
||
|
||
class IndividualStat(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
key = models.ForeignKey(IndividualStatKey, on_delete=models.CASCADE) | ||
|
||
value = models.CharField(max_length=50, null=False, blank=False) | ||
semester = models.ForeignKey(Semester, on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
unique_together = ("key", "semester", "user") | ||
|
||
def __str__(self) -> str: | ||
return f"User: {self.user} -- {self.key}-{str(self.semester)} : {self.value}" | ||
|
||
|
||
class Page(models.Model): | ||
|
||
name = models.CharField(max_length=50, primary_key=True, null=False, blank=False) | ||
template_path = models.CharField(max_length=50, null=False, blank=False) | ||
individual_stats = models.ManyToManyField( | ||
IndividualStatKey, through="IndividualStatPageField", blank=True | ||
) | ||
global_stats = models.ManyToManyField(GlobalStatKey, through="GlobalStatPageField", blank=True) | ||
duration = models.DurationField(blank=True, null=True, default=timedelta(minutes=0)) | ||
|
||
def __str__(self): | ||
return f"{self.name}" | ||
|
||
|
||
class IndividualStatPageField(models.Model): | ||
individual_stat_key = models.ForeignKey( | ||
IndividualStatKey, null=False, blank=False, default=None, on_delete=models.CASCADE | ||
) | ||
page = models.ForeignKey(Page, null=False, blank=False, on_delete=models.CASCADE) | ||
text_field_name = models.CharField(max_length=50, null=False, blank=False) | ||
|
||
def get_value(self, user, semester): | ||
return ( | ||
IndividualStat.objects.filter( | ||
user=user, key=self.individual_stat_key, semester=semester | ||
) | ||
.first() | ||
.value | ||
) | ||
|
||
def __str__(self): | ||
return f"{self.page} -> {self.text_field_name} : {self.individual_stat_key}" | ||
|
||
|
||
class GlobalStatPageField(models.Model): | ||
global_stat_key = models.ForeignKey( | ||
GlobalStatKey, null=False, blank=False, default=None, on_delete=models.CASCADE | ||
) | ||
page = models.ForeignKey(Page, null=False, blank=False, on_delete=models.CASCADE) | ||
text_field_name = models.CharField(max_length=50, null=False, blank=False) | ||
|
||
def get_value(self, _user, semester): | ||
return ( | ||
GlobalStat.objects.filter(key=self.global_stat_key.key, semester=semester).first().value | ||
) | ||
|
||
def __str__(self): | ||
return f"{self.page} -> {self.text_field_name} : {self.global_stat_key}" |
Oops, something went wrong.