class CanvasAdmin(models.Model): admin_id = models.IntegerField() role = models.CharField(max_length=100) user = models.ForeignKey(CanvasUser) def __init__(self, *args, **kwargs): data = kwargs.get("data") if data is None: return super(CanvasAdmin, self).__init__(*args, **kwargs) self.admin_id = data["id"] self.role = data["role"] self.user = CanvasUser(data=data["user"])
class Report(models.Model): report_id = models.IntegerField() account_id = models.IntegerField() type = models.CharField(max_length=500) url = models.CharField(max_length=500) status = models.CharField(max_length=50) progress = models.SmallIntegerField(max_length=3, default=0) attachment = models.ForeignKey(Attachment, null=True) def __init__(self, *args, **kwargs): data = kwargs.get("data") if data is None: return super(Report, self).__init__(*args, **kwargs) self.account_id = data["account_id"] self.report_id = data["id"] self.type = data["report"] self.url = data["file_url"] self.status = data["status"] self.progress = data["progress"] self.parameters = data["parameters"] if "attachment" in data: self.attachment = Attachment(data=data["attachment"])
class MemTest(models.Model): mt0 = models.ForeignKey(MemTest2)
class CanvasCourse(models.Model): RE_COURSE_SIS_ID = re.compile( r"^\d{4}-" # year r"(?:winter|spring|summer|autumn)-" # quarter r"[\w& ]+-" # curriculum r"\d{3}-" # course number r"[A-Z][A-Z0-9]?" # section id r"(?:-[A-F0-9]{32})?$", # ind. study instructor regid re.VERBOSE) course_id = models.IntegerField() sis_course_id = models.CharField(max_length=100, null=True) account_id = models.IntegerField() term = models.ForeignKey(CanvasTerm, null=True) code = models.CharField(max_length=100) name = models.CharField(max_length=200) course_url = models.CharField(max_length=2000) workflow_state = models.CharField(max_length=50) public_syllabus = models.NullBooleanField() syllabus_body = models.TextField(null=True) grading_standard_id = models.IntegerField(null=True) def __init__(self, *args, **kwargs): self.students = [] data = kwargs.get("data") if data is None: return super(CanvasCourse, self).__init__(*args, **kwargs) self.course_id = data["id"] self.sis_course_id = data.get("sis_course_id") self.account_id = data["account_id"] self.code = data["course_code"] self.name = data["name"] self.workflow_state = data["workflow_state"] self.public_syllabus = data["public_syllabus"] self.grading_standard_id = data.get("grading_standard_id") course_url = data["calendar"]["ics"] course_url = re.sub(r"(.*?[a-z]/).*", r"\1", course_url) self.course_url = "{}courses/{}".format(course_url, data["id"]) if "term" in data: self.term = CanvasTerm(data=data["term"]) if "syllabus_body" in data: self.syllabus_body = data["syllabus_body"] def is_unpublished(self): return self.workflow_state.lower() == "unpublished" def sws_course_id(self): if not self.is_academic_sis_id(): return try: (year, quarter, curr_abbr, course_num, section_id, reg_id) = self.sis_course_id.split('-', 5) except ValueError: (year, quarter, curr_abbr, course_num, section_id) = self.sis_course_id.split('-', 4) return '{year},{quarter},{curr_abbr},{course_num}/{section_id}'.format( year=year, quarter=quarter.lower(), curr_abbr=curr_abbr.upper(), course_num=course_num, section_id=section_id) def sws_instructor_regid(self): if not self.is_academic_sis_id(): return try: (year, quarter, curr_abbr, course_num, section_id, reg_id) = self.sis_course_id.split('-', 5) except ValueError: reg_id = None return reg_id def is_academic_sis_id(self): if (self.sis_course_id is None or self.RE_COURSE_SIS_ID.match(self.sis_course_id) is None): return False return True
class UwcalGroup(models.Model): GTYEP_CHOICES = ( (EDITOR, 'Editor'), (SHOWON, 'Showon'), ) calendar = models.ForeignKey(TrumbaCalendar) gtype = models.CharField(max_length=6, choices=GTYEP_CHOICES) def get_calendarid(self): return self.calendar.calendarid def get_campus_code(self): return self.calendar.campus def has_group_ref(self): return self.group_ref is not None def get_regid(self): if self.has_group_ref(): return self.group_ref.uwregid return None def get_group_id(self): if self.has_group_ref(): return self.group_ref.name return self.get_group_name() def get_group_admin(self): return self.calendar.get_group_admin() def get_group_desc(self): return self.calendar.get_group_desc(self.gtype) def get_group_name(self): return self.calendar.get_group_name(self.gtype) def get_group_title(self): return self.calendar.get_group_title(self.gtype) def get_member_manager(self): return self.calendar.get_group_name(EDITOR) def is_editor_group(self): return is_editor(self.gtype) def is_showon_group(self): return is_showon(self.gtype) def same_name(self, calendar): if self.group_ref is not None: group_name = self.group_ref.display_name return (group_name == calendar.name or group_name == calendar.get_group_title(self.gtype)) return False def set_calendar_name(self, cal_name): self.calendar.name = cal_name def to_json(self): group_ref_data = None if self.group_ref is not None: group_ref_data = { "id": self.group_ref.name, "regid": self.group_ref.uwregid, "displayName": self.group_ref.display_name } return { 'calendar': self.calendar.to_json(), 'gtype': self.gtype, 'group_ref': group_ref_data, 'members': [m.json_data() for m in self.members] } def __eq__(self, other): return (self.calendar == other.calendar and self.gtype == other.gtype and self.group_ref == other.group_ref) def __hash__(self): return super().__hash__() def __str__(self): return json.dumps(self.to_json()) def __init__(self, *args, **kwargs): super(UwcalGroup, self).__init__(*args, **kwargs) # self.group_ref is a GroupReference or Group object self.members = [] # a list of uw_gws.GroupMember