-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created models for penn wrapped -- issue with pip files though #309
Merged
+454
−0
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f14d390
Created models
zachHarpaz e0dbbff
pip file fix
zachHarpaz 3c8596f
Fixed models.py and added to admin.py
zachHarpaz 5d725aa
models
zachHarpaz c65cd62
Penn-Wrapped Backend Requests
zachHarpaz eb43f14
fix github pipfile diff for no reason + others
vcai122 2786e10
Updated Models
zachHarpaz 5ec9cf9
Merge branch 'penn-wrapped' of https://github.com/pennlabs/penn-mobil…
zachHarpaz cad94c5
Fixes
zachHarpaz 775468f
Penn-Wrapped Prod Push
zachHarpaz 5408760
Merge branch 'master' of https://github.com/pennlabs/penn-mobile into…
zachHarpaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}" | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's call this something more descriptive to its actual inherent meaning. Maybe |
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to prefix with
stat_
because it's a bit redundant