Skip to content

Commit

Permalink
Merge pull request #41 from bear-rsg/dev
Browse files Browse the repository at this point in the history
cod-milinp-5
  • Loading branch information
mike-allaway authored Mar 1, 2024
2 parents 451723e + e135cc5 commit 1c4b8ff
Show file tree
Hide file tree
Showing 23 changed files with 594 additions and 129 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ django/static/
node_modules/
private_testdata*
outputdata/
django/general/migrations/


###################### Django Templated gitignore paths ######################
Expand Down
7 changes: 2 additions & 5 deletions django/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from django.contrib.auth.forms import UserChangeForm
from django.contrib.auth.models import Group
from account import forms
from .models import User, UsersImportSpreadsheet


Expand Down Expand Up @@ -32,21 +31,18 @@ class UserAdmin(DjangoUserAdmin):
Customise the admin interface: User
"""

add_form = forms.DashboardUserChangeForm
form = UserChangeForm
model = User
list_display = ['username',
'internal_id_number',
'first_name',
'last_name',
'email',
'role',
'default_language',
'is_internal',
'is_active',
'date_joined',
'last_login']
search_fields = ['username', 'first_name', 'last_name', 'email']
search_fields = ['username', 'first_name', 'last_name', 'email', 'internal_id_number']
list_filter = ['role', 'is_active', 'is_internal']
filter_horizontal = ('classes',)
readonly_fields = ['date_joined', 'last_login', 'is_staff', 'is_superuser']
Expand All @@ -64,6 +60,7 @@ class UserAdmin(DjangoUserAdmin):
'last_login')
fieldsets = None
actions = (delete_users,)
ordering = ['first_name', 'last_name']

def has_add_permission(self, request, obj=None):
return False
Expand Down
13 changes: 1 addition & 12 deletions django/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
from .models import User


class DashboardUserChangeForm(UserChangeForm):
"""
Form to specify fields in the user change form, which is only accessible via the Django admin
It's used in admin.py
"""

class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'role', 'default_language', 'classes')


class PublicUserChangeForm(UserChangeForm):
"""
Form to specify fields in the user change form, which is accessible through the public website
Expand Down Expand Up @@ -48,4 +37,4 @@ def __init__(self, *args, **kwargs):

class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'default_language', 'classes')
fields = ('first_name', 'last_name', 'email', 'classes')
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.9 on 2024-02-29 15:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('account', '0005_alter_user_managers'),
]

operations = [
migrations.AlterModelOptions(
name='user',
options={'ordering': ['first_name', 'last_name', 'id']},
),
migrations.RemoveField(
model_name='user',
name='default_language',
),
]
6 changes: 4 additions & 2 deletions django/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class User(AbstractUser):
is_internal = models.BooleanField(default=True, help_text='Is internal to the University of Birmingham, e.g. an active UoB student or staff member')
internal_id_number = models.CharField(max_length=255, help_text='If internal to the University of Birmingham, please provide a unique ID, e.g. student number, staff number', blank=True)
classes = models.ManyToManyField('exercises.SchoolClass', blank=True)
default_language = models.ForeignKey('exercises.Language', on_delete=models.SET_NULL, blank=True, null=True)

@property
def name(self):
Expand Down Expand Up @@ -102,7 +101,7 @@ def exercises_todo(self):
return exercises

def __str__(self):
return self.username
return f'{self.name} - {self.username} ({self.role})'

def save(self, *args, **kwargs):
# Force email to be lower case
Expand Down Expand Up @@ -140,3 +139,6 @@ def save(self, *args, **kwargs):
Group.objects.get(name='teacher_permissions_group').user_set.add(self)
elif self.role.name == 'guest':
Group.objects.get(name='guest_permissions_group').user_set.add(self)

class Meta:
ordering = ['first_name', 'last_name', 'id']
17 changes: 7 additions & 10 deletions django/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,16 @@ def get_redirect_url(self, *args, **kwargs):

# Get/create school class thrugh unique identifiers (year group, language, difficulty)
if str(user['year_group']) != 'nan' and str(user['language']) != 'nan' and str(user['difficulty']) != 'nan':
school_class_obj = exercise_models.SchoolClass.objects.get_or_create(
school_class_obj, school_class_is_new = exercise_models.SchoolClass.objects.get_or_create(
year_group=exercise_models.YearGroup.objects.get(name=user['year_group']),
language=exercise_models.Language.objects.get_or_create(name=user['language'])[0],
difficulty=exercise_models.Difficulty.objects.get(name=user['difficulty'])
)[0]
# Add the related class
user_obj.classes.add(school_class_obj)

# Set default language (if provided, else None)
if str(user['language']) != 'nan':
user_obj.default_language = exercise_models.Language.objects.get_or_create(name=user['language'])[0]
else:
user_obj.default_language = None
)
# Add/remove the related class from user
if 'remove_from_class' in user and str(user['remove_from_class']).lower() == 'y':
user_obj.classes.remove(school_class_obj)
else:
user_obj.classes.add(school_class_obj)

# Add additional user data
user_obj.internal_id_number = str(user['internal_id_number']).replace('.0', '') if str(user['internal_id_number']) != 'nan' else ''
Expand Down
49 changes: 45 additions & 4 deletions django/core/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -603,28 +603,38 @@ main {
}

.exerciseformat-showanswer {
color: #505050;
color: #1779C5;
font-size: 0.95em;
display: none;
}

.exerciseformat-showanswer label {
cursor: pointer;
font-size: 1.1em;
}

.exerciseformat-showanswer label:hover {
opacity: 0.9;
}

.exerciseformat-showanswer label i {
font-size: 1.2em;
}

.exerciseformat-showanswer .answer {
display: none;
padding: 0.5em;
margin-bottom: 1em;
background: #505050;
color: #EEE;
background: #1779C5;
color: #FFF;
text-align: left;
}

.exerciseformat-showanswer .answer img {
max-width: 10em;
display: block;
}

.exerciseformat-showanswer .answer-feedback {
margin-top: 1.3em;
}
Expand Down Expand Up @@ -773,10 +783,41 @@ main {
text-align: center;
}


/* Exercise: Detail: Format: ImageMatch (Reversed) */

.exerciseformat-imagematchreversed {
margin: 5em 0;
overflow: hidden;
padding-bottom: 1em;
vertical-align: top;
}

.exerciseformat-imagematchreversed-title {
padding: 0.5em 0;
font-weight: bold;
font-size: 1.5em;
}

.exerciseformat-imagematchreversed-image {
}

.exerciseformat-imagematchreversed input {
display: block;
margin-bottom: 0.5em;
scale: 1.5;
}

.exerciseformat-imagematchreversed img {
width: 100%;
border: 1px solid #DDD;
cursor: zoom-in;
}

/* Exercise: Detail: Format: MultipleChoice */

.exerciseformat-multiplechoice {
margin: 4em auto 10em auto;
margin: 3rem auto 7rem auto;
}

.exerciseformat-multiplechoice-question {
Expand Down
9 changes: 9 additions & 0 deletions django/core/static/css/custom_large.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@
display: inline-block;
width: calc(25% - 3.3em);
}

/* Exercise: Detail: Format: ImageMatch (Reversed) */

.exerciseformat-imagematchreversed-image {
display: inline-block;
margin: 1em;
width: calc(25% - 2.3em);
vertical-align: top;
}

/* Exercise: Detail: Format: Translation */

Expand Down
8 changes: 7 additions & 1 deletion django/core/static/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$(document).ready(function() {

// Popup
// Show
$('.popup-show').on('click', function() {
Expand All @@ -11,4 +11,10 @@ $(document).ready(function() {
$(this).closest('.popup').hide();
});

// Filter select lists
// "Owned By" and "Collaborators" lists to hide students and guests
$('#id_owned_by option, #id_collaborators option').each(function(){
if ($(this).text().includes('(student)') || $(this).text().includes('(guest)')) $(this).remove();
});

});
19 changes: 19 additions & 0 deletions django/exercises/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ def has_delete_permission(self, request, obj=None):
return False


class FontSizeAdminView(admin.ModelAdmin):
"""
Customise the admin interface: FontSize
"""
list_display = ('name', 'size_em')
list_display_links = ('name',)
search_fields = ('name', 'size_em')

def has_add_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


class ExerciseAdminView(admin.ModelAdmin):
"""
Customise the admin interface: Exercise
Expand Down Expand Up @@ -186,6 +204,7 @@ def has_delete_permission(self, request, obj=None):
admin.site.register(models.SchoolClass, SchoolClassAdminView)
admin.site.register(models.Theme, ThemeAdminView)
admin.site.register(models.Difficulty, DifficultyAdminView)
admin.site.register(models.FontSize, FontSizeAdminView)
admin.site.register(models.Exercise, ExerciseAdminView)

admin.site.register(models.SchoolClassAlertExercise, SchoolClassAlertExerciseAdminView)
Expand Down
Loading

0 comments on commit 1c4b8ff

Please sign in to comment.