Skip to content
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

Update Django to 3.2 and other Python dependencies (#1286) #1300

Merged
merged 17 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions dashboard/common/db_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Some utility functions used by other classes in this project
import logging
from datetime import datetime
from typing import Any, Dict, List, TypedDict, Union
from typing import Dict, List, TypedDict, Union

from dateutil.parser import parse
import django
Expand Down Expand Up @@ -147,17 +147,17 @@ def get_user_courses_info(username: str, course_id: Union[int, None] = None) ->
return enrollments


def get_last_cronjob_run():
def get_last_cronjob_run() -> Union[datetime, None]:
try:
c = CronJobLog.objects.filter(is_success=1).latest('end_time')
end_time = c.end_time
return end_time
except CronJobLog.DoesNotExist:
logger.info("CronJobLog did not exist", exc_info = True)
return datetime.min
return None


def get_canvas_data_date():
def get_canvas_data_date() -> Union[datetime, None]:
if not settings.DATABASES.get('DATA_WAREHOUSE', {}).get('IS_UNIZIN'):
return get_last_cronjob_run()

Expand All @@ -170,4 +170,4 @@ def get_canvas_data_date():
return date
except Exception:
logger.info("Value could not be found from metadata", exc_info = True)
return datetime.min
return None
2 changes: 1 addition & 1 deletion dashboard/lti_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def extract_launch_variables_for_tool_use(request, message_launch):
MylaUser.objects.create(name=full_name, sis_name=username,
course_id=canvas_course_long_id,
user_id=canvas_user_long_id, sis_id=user_sis_id,
enrollment_type=MylaUser.ENROLLMENT_TYPES.TeacherEnrollment)
enrollment_type=MylaUser.EnrollmentType.TEACHER)
return course_id


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.6 on 2021-09-03 15:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0020_submission_submitted_at'),
]

operations = [
migrations.AlterField(
model_name='assignmentweightconsideration',
name='consider_weight',
field=models.BooleanField(blank=True, default=False, null=True, verbose_name='Consider Weight'),
),
]
21 changes: 9 additions & 12 deletions dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

logger = logging.getLogger(__name__)

from model_utils import Choices


class AcademicTerms(models.Model):
id = models.BigIntegerField(primary_key=True, verbose_name="Term Id")
Expand Down Expand Up @@ -134,7 +132,7 @@ class Meta:

class AssignmentWeightConsideration(models.Model):
course_id = models.BigIntegerField(primary_key=True, verbose_name="Course Id")
consider_weight = models.NullBooleanField(blank=True, default=False, verbose_name="Consider Weight")
consider_weight = models.BooleanField(null=True, blank=True, default=False, verbose_name="Consider Weight")

class Meta:
db_table = 'assignment_weight_consideration'
Expand Down Expand Up @@ -380,14 +378,13 @@ def get_user_in_course_id(self, user, course_id):
)

class User(models.Model):
ENROLLMENT_TYPES = Choices(
('StudentEnrollment', 'Student'),
#('StudentViewEnrollment', 'Student View'),
('TaEnrollment', 'Teaching Assistant'),
('TeacherEnrollment', 'Instructor'),
#('DesignerEnrollment', 'Designer'),
#('ObserverEnrollment', 'Observer'),
)
class EnrollmentType(models.TextChoices):
jonespm marked this conversation as resolved.
Show resolved Hide resolved
STUDENT = 'StudentEnrollment', 'Student'
TA = 'TaEnrollment', 'Teaching Assistant'
TEACHER = 'TeacherEnrollment', 'Instructor'
# STUDENT_VIEW = 'StudentViewEnrollment', 'Student View'
# DESIGNER = 'DesignerEnrollment', 'Designer'
# OBSERVER = 'ObserverEnrollment', 'Observer'

id = models.AutoField(primary_key=True, verbose_name="Table Id")
user_id = models.BigIntegerField(null=False, blank=False, verbose_name="User Id")
Expand All @@ -397,7 +394,7 @@ class User(models.Model):
course_id = models.BigIntegerField(blank=True, null=True, verbose_name="Course Id")
current_grade = models.FloatField(blank=True, null=True, verbose_name="Current Grade")
final_grade = models.FloatField(blank=True, null=True, verbose_name="Final Grade")
enrollment_type = models.CharField(max_length=50, choices=ENROLLMENT_TYPES, blank=True, null=True, verbose_name="Enrollment Type")
enrollment_type = models.CharField(max_length=50, choices=EnrollmentType.choices, blank=True, null=True, verbose_name="Enrollment Type")

objects = UserQuerySet.as_manager()

Expand Down
2 changes: 1 addition & 1 deletion dashboard/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def is_instructor_in_course_id(self, user, course_id):

try:
result = User.objects.get_user_in_course_id(user, course_id).filter(
enrollment_type=User.ENROLLMENT_TYPES.TeacherEnrollment
enrollment_type=User.EnrollmentType.TEACHER
).count() > 0
except User.DoesNotExist:
logger.error(f'Permission is_instructor_in_course_id: user {user.id} is not an instructor in course {course_id}')
Expand Down
7 changes: 2 additions & 5 deletions dashboard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
'graphene_django',
'django_cron',
'watchman',
'macros',
'pinax.eventlog',
'webpack_loader',
'rules.apps.AutodiscoverRulesConfig',
Expand Down Expand Up @@ -147,7 +146,6 @@
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
'django_su.context_processors.is_su',
'django_settings_export.settings_export',
'dashboard.context_processors.get_git_version_info',
'dashboard.context_processors.get_myla_globals',
'dashboard.context_processors.last_updated'
Expand Down Expand Up @@ -239,6 +237,8 @@
**ENV.get('LRS', {})
}

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

Expand Down Expand Up @@ -451,9 +451,6 @@
# Time to run cron
RUN_AT_TIMES = ENV.get('RUN_AT_TIMES', [])

# Add any settings you need to be available to templates in this array
SETTINGS_EXPORT = ['LOGIN_URL','LOGOUT_URL','DEBUG', 'GA_ID', 'RESOURCE_VALUES']

# Number of weeks max to allow by default. some begin/end dates in Canvas aren't correct
MAX_DEFAULT_WEEKS = ENV.get("MAX_DEFAULT_WEEKS", 16)

Expand Down
15 changes: 8 additions & 7 deletions dashboard/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
{% load static %}
{% load macros %}
{% load tz %}

<!DOCTYPE html>
<!-- Use this as a "macro", no default title set -->
{% macro title %}
{% block title %}{% endblock %}
{% endmacro %}
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% use_macro title %}</title>
<title>{% block title %}{% endblock %}</title>
jonespm marked this conversation as resolved.
Show resolved Hide resolved
<link rel="stylesheet" type="text/css" href="{% static '@fortawesome/fontawesome-free/css/all.css' %}">
<link rel="stylesheet" type="text/css" href="{% static '@fortawesome/fontawesome-free/css/fontawesome.css' %}">
<link rel="stylesheet" type="text/css" href="{% static '@fortawesome/fontawesome-free/css/fontawesome.min.css' %}">
Expand Down Expand Up @@ -56,7 +51,13 @@
(commit), {{ git_version.branch }} (branch)
</td>
{% endif %}
<td style="text-align: left">Data last updated on {{last_updated|date:"m/d/Y P T"}}</td>
<td style="text-align: left">
{% if last_updated %}
Data last updated on {{last_updated|date:"m/d/Y P T"}}
{% else %}
Data not loaded yet
{% endif %}
</td>
</tr>
</table>
</footer>
Expand Down
8 changes: 4 additions & 4 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ def grade_distribution(request, course_id=0):
logger.debug(f"Grades distribution: {grades}")
BinningGrade = find_binning_grade_value(grades)
if BinningGrade is not None and not BinningGrade.binning_all:
df['current_grade'] = df['current_grade'].replace(df['current_grade'].head(BinningGrade.index),
BinningGrade.value)
scores_to_replace = df['current_grade'].head(BinningGrade.index).to_list()
df['current_grade'] = df['current_grade'].replace(scores_to_replace, BinningGrade.value)
summary['show_dash_line'] = show_dashed_line(df['current_grade'].iloc[0], BinningGrade)

if df[df['current_grade'] > 100.0].shape[0] > 0:
Expand All @@ -466,7 +466,7 @@ def grade_distribution(request, course_id=0):
# json for eventlog
data = {
"course_id": course_id,
"show_number_on_bars": df['show_number_on_bars'].values[0]
"show_number_on_bars": int(df['show_number_on_bars'].values[0])
}
eventlog(request.user, EventLogTypes.EVENT_VIEW_GRADE_DISTRIBUTION.value, extra=data)

Expand Down Expand Up @@ -654,7 +654,7 @@ def get_course_assignments(course_id):
if hidden_assignments:
assignments_in_course['name'] = assignments_in_course['name'].fillna(assignments_in_course['assign_grp_name']+' Group Unavailable Assignments')
assignments_in_course['towards_final_grade']=assignments_in_course.apply(lambda x: percent_calculation(consider_weight, total_points,hidden_assignments, x), axis=1)
assignments_in_course['calender_week']=assignments_in_course['due_date'].dt.week
assignments_in_course['calender_week']=assignments_in_course['due_date'].dt.isocalendar().week
assignments_in_course['calender_week']=assignments_in_course['calender_week'].fillna(0).astype(int)
min_week=find_min_week(course_id)
max_week=assignments_in_course['calender_week'].max()
Expand Down