-
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.
request should look like this format: /wrapped/generate/?username=zharpaz&semester=2020A
- Loading branch information
1 parent
5d725aa
commit c65cd62
Showing
12 changed files
with
279 additions
and
51 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
49 changes: 49 additions & 0 deletions
49
backend/wrapped/migrations/0003_remove_page_template_remove_page_globalstat_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,49 @@ | ||
# Generated by Django 5.0.2 on 2024-10-18 21:11 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wrapped', '0002_remove_page_temp_remove_template_background_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='page', | ||
name='template', | ||
), | ||
migrations.RemoveField( | ||
model_name='page', | ||
name='GlobalStat', | ||
), | ||
migrations.RemoveField( | ||
model_name='page', | ||
name='IndividualStat', | ||
), | ||
migrations.AddField( | ||
model_name='page', | ||
name='template_path', | ||
field=models.CharField(default='nothing', max_length=50), | ||
preserve_default=False, | ||
), | ||
migrations.CreateModel( | ||
name='StatLocation', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('text_field_name', models.CharField(max_length=50)), | ||
('GlobalStatKey', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wrapped.globalstat')), | ||
('IndividualStatKey', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wrapped.userstatkey')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='page', | ||
name='stat_locations', | ||
field=models.ManyToManyField(blank=True, to='wrapped.statlocation'), | ||
), | ||
migrations.DeleteModel( | ||
name='Template', | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
backend/wrapped/migrations/0004_statlocation_one_foreign_key_must_be_null.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,17 @@ | ||
# Generated by Django 5.0.2 on 2024-10-18 21:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wrapped', '0003_remove_page_template_remove_page_globalstat_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name='statlocation', | ||
constraint=models.CheckConstraint(check=models.Q(models.Q(('GlobalStatKey', False), ('IndividualStatKey', True)), models.Q(('GlobalStatKey', True), ('IndividualStatKey', False)), _connector='OR'), name='one_foreign_key_must_be_null'), | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
backend/wrapped/migrations/0005_alter_statlocation_globalstatkey_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,24 @@ | ||
# Generated by Django 5.0.2 on 2024-10-18 21:31 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wrapped', '0004_statlocation_one_foreign_key_must_be_null'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='statlocation', | ||
name='GlobalStatKey', | ||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='wrapped.globalstat'), | ||
), | ||
migrations.AlterField( | ||
model_name='statlocation', | ||
name='IndividualStatKey', | ||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='wrapped.userstatkey'), | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
backend/wrapped/migrations/0006_remove_statlocation_one_foreign_key_must_be_null.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,17 @@ | ||
# Generated by Django 5.0.2 on 2024-10-18 21:32 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wrapped', '0005_alter_statlocation_globalstatkey_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveConstraint( | ||
model_name='statlocation', | ||
name='one_foreign_key_must_be_null', | ||
), | ||
] |
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,19 @@ | ||
# Generated by Django 5.0.2 on 2024-10-18 21:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wrapped', '0006_remove_statlocation_one_foreign_key_must_be_null'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='page', | ||
name='name', | ||
field=models.CharField(default='old', max_length=50), | ||
preserve_default=False, | ||
), | ||
] |
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,19 @@ | ||
# Generated by Django 5.0.2 on 2024-10-20 17:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wrapped', '0007_page_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='page', | ||
name='semester', | ||
field=models.CharField(default='2020A', max_length=5), | ||
preserve_default=False, | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from django.contrib.auth import get_user_model | ||
from rest_framework import serializers | ||
|
||
from wrapped.models import GlobalStat, IndividualStat, UserStatKey, StatLocation, Page | ||
|
||
User = get_user_model() | ||
|
||
class MiniUserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ["username", "first_name", "last_name"] | ||
|
||
|
||
class StatLocationSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = StatLocation | ||
fields = ["IndividualStatKey", "GlobalStatKey", "text_field_name"] | ||
|
||
class IndividualStatSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = IndividualStat | ||
fields = ["user", "stat_key", "stat_value", "semester"] | ||
|
||
class GlobalStatSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = GlobalStat | ||
fields = ["stat_key", "stat_value", "semester"] | ||
|
||
class UserStatKeySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = UserStatKey | ||
fields = ["stat_key"] | ||
|
||
class PageSerializer(serializers.ModelSerializer): | ||
stat_location_data = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = Page | ||
fields = ["name", "template_path", "stat_location_data"] | ||
|
||
def get_stat_location_data(self, obj): | ||
location_stat_dict = {} | ||
for stat_location in obj.stat_locations.all(): | ||
individual_stat_data = None | ||
if stat_location.IndividualStatKey: | ||
individual_stats = IndividualStat.objects.filter(stat_key=stat_location.IndividualStatKey).filter(semester=obj.semester) | ||
individual_stat_data = IndividualStatSerializer(individual_stats, many=True).data | ||
|
||
global_stat_data = None | ||
if stat_location.GlobalStatKey: | ||
global_stat_data = GlobalStatSerializer(stat_location.GlobalStatKey, many=False).data | ||
|
||
if global_stat_data == None: | ||
|
||
location_stat_dict[stat_location.text_field_name] = individual_stat_data[0]["stat_value"] | ||
else: | ||
location_stat_dict[stat_location.text_field_name] = global_stat_data["stat_value"] | ||
|
||
|
||
return location_stat_dict | ||
|
||
|
||
|
||
|
||
|
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,7 @@ | ||
from django.contrib import admin | ||
from django.urls import path | ||
from .views import GeneratePage | ||
urlpatterns = [ | ||
path('generate/', GeneratePage.as_view({"get" : "user_generation"}), name='user_generation'), | ||
] | ||
|
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