Skip to content

Commit

Permalink
feat: Level control feature (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 authored Nov 15, 2022
1 parent 7984f04 commit 746da41
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 218 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pytest = "==7.*"
pytest-xdist = "*"
pytest-order = "*"
codeforlife-portal = "*"
django-import-export = "*"
importlib-metadata = "<5" # Using version 5 causes an issue when trying to run pytest. Not sure why, linked to: https://stackoverflow.com/questions/73929564/entrypoints-object-has-no-attribute-get-digital-ocean

[requires]
Expand Down
128 changes: 106 additions & 22 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example_project/rapid_router_test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"django_otp.plugins.otp_static",
"django_otp.plugins.otp_totp",
"rest_framework",
"import_export",
"sekizai", # for javascript and css management
)

Expand Down
1 change: 1 addition & 0 deletions example_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"django_otp.plugins.otp_static",
"django_otp.plugins.otp_totp",
"rest_framework",
"import_export",
"sekizai", # for javascript and css management
)

Expand Down
2 changes: 1 addition & 1 deletion game/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class LevelAdmin(admin.ModelAdmin):
search_fields = ["name"]
raw_id_fields = ["next_level"]
raw_id_fields = ["next_level", "locked_for_class"]
readonly_fields = ["owner"]
list_display = ["name", "id", "episode", "owner"]

Expand Down
19 changes: 19 additions & 0 deletions game/migrations/0076_level_locked_for_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.15 on 2022-10-31 15:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0030_add_maintenance_banner'),
('game', '0075_level_48_houses'),
]

operations = [
migrations.AddField(
model_name='level',
name='locked_for_class',
field=models.ManyToManyField(blank=True, related_name='locked_levels', to='common.Class'),
),
]
3 changes: 2 additions & 1 deletion game/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from builtins import str

from common.models import UserProfile, Student
from common.models import UserProfile, Student, Class
from django.contrib.auth.models import User
from django.db import models

Expand Down Expand Up @@ -130,6 +130,7 @@ class Level(models.Model):
max_length=20, choices=character_choices(), blank=True, null=True, default=None
)
anonymous = models.BooleanField(default=False)
locked_for_class = models.ManyToManyField(Class, blank=True, related_name="locked_levels")
objects = LevelManager()

def __str__(self):
Expand Down
5 changes: 4 additions & 1 deletion game/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def can_play_or_delete_level(user, level):


def can_play_level(user, level, early_access):
if level.default and not level.episode.in_development:
if not user.is_anonymous and hasattr(user.userprofile, "student") and user.userprofile.student.class_field:
# If the user is a student, check that the level isn't locked for their class
return user.userprofile.student.class_field not in level.locked_for_class.all()
elif level.default and not level.episode.in_development:
return True
elif level.anonymous:
return False
Expand Down
10 changes: 10 additions & 0 deletions game/static/game/css/level_selection.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@
font-family: "Glyphicons Halflings";
margin-left: 10px;
}

#episodes .disabled,
#episodes .disabled:hover,
#episodes .disabled:focus,
#episodes .disabled:visited {
color: #a1a1a1;
cursor: default;
font-weight: 300;
text-decoration: none;
}
Loading

0 comments on commit 746da41

Please sign in to comment.