mirror of https://github.com/interlegis/sigi.git
Sesostris Vieira
10 years ago
6 changed files with 5427 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
from django.contrib import admin |
|||
|
|||
# Register your models here. |
File diff suppressed because it is too large
@ -0,0 +1,327 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
from __future__ import unicode_literals |
|||
from django.db import models |
|||
|
|||
class CourseStatus(models.Model): |
|||
# databaseview: (postgresql dialect): |
|||
# |
|||
# CREATE OR REPLACE VIEW ilb_course_status AS |
|||
# SELECT DISTINCT u.id AS userid, c.id AS courseid, c.category, |
|||
# CASE |
|||
# WHEN e.enrol::text = 'ilbeadtutorado'::text AND ue.status = 1::bigint THEN 'Matrícula rejeitada'::text |
|||
# WHEN e.enrol::text = 'ilbead'::text AND ue.timeend < date_part('epoch'::text, now())::integer THEN 'Em curso'::text |
|||
# WHEN co.timestarted = 0 OR co.timestarted IS NULL THEN 'Abandono'::text |
|||
# WHEN co.timestarted > 0 AND co.timecompleted IS NULL THEN 'Reprovado'::text |
|||
# WHEN co.timecompleted IS NOT NULL THEN 'Aprovado'::text |
|||
# WHEN e.enrol::text <> 'ilbeadtutorado'::text THEN '?'::text |
|||
# ELSE ''::text |
|||
# END AS status |
|||
# FROM mdl_user u |
|||
# JOIN mdl_user_enrolments ue ON ue.userid = u.id |
|||
# JOIN mdl_enrol e ON e.id = ue.enrolid |
|||
# JOIN mdl_course c ON c.id = e.courseid |
|||
# LEFT JOIN mdl_course_completions co ON co.userid = u.id AND co.course = c.id; |
|||
|
|||
userid = models.IntegerField(primary_key=True) |
|||
courseid = models.IntegerField() |
|||
category = models.IntegerField() |
|||
status = models.CharField(max_length=100) |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'ilb_course_status' |
|||
|
|||
class Cohort(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
context = models.ForeignKey('Context', db_column='contextid') |
|||
name = models.CharField(max_length=254) |
|||
idnumber = models.CharField(max_length=100, blank=True) |
|||
description = models.TextField(blank=True) |
|||
descriptionformat = models.SmallIntegerField() |
|||
component = models.CharField(max_length=100) |
|||
timecreated = models.BigIntegerField() |
|||
timemodified = models.BigIntegerField() |
|||
# Manytomany |
|||
members = models.ManyToManyField('User', through='CohortMembers') |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_cohort' |
|||
|
|||
def __unicode__(self): |
|||
return self.name |
|||
|
|||
class CohortMembers(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
cohort = models.ForeignKey('Cohort', db_column='cohortid') |
|||
user = models.ForeignKey('User', db_column='userid') |
|||
timeadded = models.BigIntegerField() |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_cohort_members' |
|||
|
|||
class Context(models.Model): |
|||
CONTEXT_SYSTEM = 10 # System context level - only one instance in every system |
|||
CONTEXT_USER = 30 # User context level - one instance for each user describing what others can do to user |
|||
CONTEXT_COURSECAT = 40 # Course category context level - one instance for each category |
|||
CONTEXT_COURSE = 50 # Course context level - one instances for each course |
|||
CONTEXT_MODULE = 70 # Course module context level - one instance for each course module |
|||
CONTEXT_BLOCK = 80 # Block context level - one instance for each block, sticky blocks are tricky |
|||
# because ppl think they should be able to override them at lower contexts. |
|||
# Any other context level instance can be parent of block context. |
|||
|
|||
id = models.BigIntegerField(primary_key=True) |
|||
contextlevel = models.BigIntegerField() |
|||
instanceid = models.BigIntegerField() |
|||
path = models.CharField(max_length=255, blank=True) |
|||
depth = models.SmallIntegerField() |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_context' |
|||
|
|||
def __unicode__(self): |
|||
return self.path |
|||
|
|||
class Course(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
category = models.ForeignKey('CourseCategories', db_column='category', related_name='courses') |
|||
sortorder = models.BigIntegerField() |
|||
fullname = models.CharField(max_length=254) |
|||
shortname = models.CharField(max_length=255) |
|||
idnumber = models.CharField(max_length=100) |
|||
summary = models.TextField(blank=True) |
|||
format = models.CharField(max_length=21) |
|||
showgrades = models.SmallIntegerField() |
|||
modinfo = models.TextField(blank=True) |
|||
newsitems = models.IntegerField() |
|||
startdate = models.BigIntegerField() |
|||
marker = models.BigIntegerField() |
|||
maxbytes = models.BigIntegerField() |
|||
showreports = models.SmallIntegerField() |
|||
visible = models.SmallIntegerField() |
|||
groupmode = models.SmallIntegerField() |
|||
groupmodeforce = models.SmallIntegerField() |
|||
lang = models.CharField(max_length=30) |
|||
theme = models.CharField(max_length=50) |
|||
timecreated = models.BigIntegerField() |
|||
timemodified = models.BigIntegerField() |
|||
requested = models.SmallIntegerField() |
|||
defaultgroupingid = models.BigIntegerField() |
|||
enrolmax = models.BigIntegerField() |
|||
enablecompletion = models.SmallIntegerField() |
|||
legacyfiles = models.SmallIntegerField() |
|||
summaryformat = models.SmallIntegerField() |
|||
completionnotify = models.SmallIntegerField() |
|||
visibleold = models.SmallIntegerField() |
|||
sectioncache = models.TextField(blank=True) |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_course' |
|||
ordering = ['sortorder',] |
|||
|
|||
def __unicode__(self): |
|||
return self.fullname |
|||
|
|||
def total_alunos(self): |
|||
return sum(e.user_enrolments.count() for e in self.enrols.all()) |
|||
|
|||
def total_ativos(self): |
|||
return sum(e.user_enrolments.filter(status=0).count() for e in self.enrols.all()) |
|||
|
|||
def get_matriculas(self): |
|||
q = UserEnrolments.objects.none() |
|||
for e in self.enrols.all(): |
|||
q = q | e.user_enrolments.all() |
|||
return q |
|||
|
|||
class CourseCategories(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
name = models.CharField(max_length=255) |
|||
description = models.TextField(blank=True) |
|||
parent = models.ForeignKey('CourseCategories', db_column='parent', related_name='children') |
|||
sortorder = models.BigIntegerField() |
|||
coursecount = models.BigIntegerField() |
|||
visible = models.SmallIntegerField() |
|||
timemodified = models.BigIntegerField() |
|||
depth = models.BigIntegerField() |
|||
path = models.CharField(max_length=255) |
|||
theme = models.CharField(max_length=50, blank=True) |
|||
descriptionformat = models.SmallIntegerField() |
|||
visibleold = models.SmallIntegerField() |
|||
idnumber = models.CharField(max_length=100, blank=True) |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_course_categories' |
|||
ordering = ['sortorder',] |
|||
|
|||
def __unicode__(self): |
|||
return self.name |
|||
|
|||
def context(self): |
|||
return Context.objects.get(instanceid=self.id, contextlevel=Context.CONTEXT_COURSECAT) |
|||
|
|||
def total_turmas(self): |
|||
return self.coursecount + sum([c.coursecount for c in self.children.all()]) |
|||
|
|||
def total_alunos(self): |
|||
total = 0 |
|||
total = total + sum(c.total_alunos() for c in self.courses.all()) |
|||
total = total + sum(c.total_alunos() for c in self.children.all()) |
|||
return total |
|||
|
|||
def cohortids(self): |
|||
cids = [c.pk for c in self.context().cohort_set.all()] |
|||
for c in self.children.all(): |
|||
cids = cids + c.cohortids() |
|||
return cids |
|||
|
|||
def total_alunos_cohort(self): |
|||
return sum([c.members.distinct().count() for c in Cohort.objects.filter(pk__in=self.cohortids())]) |
|||
|
|||
def get_all_courses(self, only_visible=False): |
|||
if only_visible: |
|||
q = self.courses.filter(visible=1) |
|||
else: |
|||
q = self.courses.all() |
|||
for c in self.children.all(): |
|||
q = q | c.get_all_courses(only_visible=only_visible) |
|||
return q |
|||
|
|||
class CourseCompletions(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
user = models.ForeignKey('User', db_column='userid') |
|||
course = models.ForeignKey('Course', db_column='course') |
|||
timeenrolled = models.BigIntegerField() |
|||
timestarted = models.BigIntegerField() |
|||
timecompleted = models.BigIntegerField(blank=True, null=True) |
|||
reaggregate = models.BigIntegerField() |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_course_completions' |
|||
|
|||
class Enrol(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
enrol = models.CharField(max_length=20) |
|||
status = models.BigIntegerField() |
|||
course = models.ForeignKey('Course', db_column='courseid', related_name='enrols') |
|||
sortorder = models.BigIntegerField() |
|||
name = models.CharField(max_length=255, blank=True) |
|||
enrolperiod = models.BigIntegerField(blank=True, null=True) |
|||
enrolstartdate = models.BigIntegerField(blank=True, null=True) |
|||
enrolenddate = models.BigIntegerField(blank=True, null=True) |
|||
expirynotify = models.SmallIntegerField(blank=True, null=True) |
|||
expirythreshold = models.BigIntegerField(blank=True, null=True) |
|||
notifyall = models.SmallIntegerField(blank=True, null=True) |
|||
password = models.CharField(max_length=50, blank=True) |
|||
cost = models.CharField(max_length=20, blank=True) |
|||
currency = models.CharField(max_length=3, blank=True) |
|||
roleid = models.BigIntegerField(blank=True, null=True) |
|||
customint1 = models.BigIntegerField(blank=True, null=True) |
|||
customint2 = models.BigIntegerField(blank=True, null=True) |
|||
customint3 = models.BigIntegerField(blank=True, null=True) |
|||
customint4 = models.BigIntegerField(blank=True, null=True) |
|||
customchar1 = models.CharField(max_length=255, blank=True) |
|||
customchar2 = models.CharField(max_length=255, blank=True) |
|||
customdec1 = models.DecimalField(max_digits=12, decimal_places=7, blank=True, null=True) |
|||
customdec2 = models.DecimalField(max_digits=12, decimal_places=7, blank=True, null=True) |
|||
customtext1 = models.TextField(blank=True) |
|||
customtext2 = models.TextField(blank=True) |
|||
timecreated = models.BigIntegerField() |
|||
timemodified = models.BigIntegerField() |
|||
customint5 = models.BigIntegerField(blank=True, null=True) |
|||
customint6 = models.BigIntegerField(blank=True, null=True) |
|||
customint7 = models.BigIntegerField(blank=True, null=True) |
|||
customint8 = models.BigIntegerField(blank=True, null=True) |
|||
customchar3 = models.CharField(max_length=1333, blank=True) |
|||
customtext3 = models.TextField(blank=True) |
|||
customtext4 = models.TextField(blank=True) |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_enrol' |
|||
ordering = ['sortorder',] |
|||
|
|||
def __unicode__(self): |
|||
if not self.name: |
|||
return self.enrol |
|||
return self.name |
|||
|
|||
class User(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
auth = models.CharField(max_length=20) |
|||
confirmed = models.SmallIntegerField() |
|||
policyagreed = models.SmallIntegerField() |
|||
deleted = models.SmallIntegerField() |
|||
mnethostid = models.BigIntegerField() |
|||
username = models.CharField(max_length=100) |
|||
password = models.CharField(max_length=255) |
|||
firstname = models.CharField(max_length=100) |
|||
lastname = models.CharField(max_length=100) |
|||
email = models.CharField(max_length=100) |
|||
emailstop = models.SmallIntegerField() |
|||
icq = models.CharField(max_length=15) |
|||
skype = models.CharField(max_length=50) |
|||
yahoo = models.CharField(max_length=50) |
|||
aim = models.CharField(max_length=50) |
|||
msn = models.CharField(max_length=50) |
|||
phone1 = models.CharField(max_length=20) |
|||
phone2 = models.CharField(max_length=20) |
|||
institution = models.CharField(max_length=40) |
|||
department = models.CharField(max_length=30) |
|||
address = models.CharField(max_length=70) |
|||
city = models.CharField(max_length=120) |
|||
country = models.CharField(max_length=2) |
|||
lang = models.CharField(max_length=30) |
|||
theme = models.CharField(max_length=50) |
|||
timezone = models.CharField(max_length=100) |
|||
firstaccess = models.BigIntegerField() |
|||
lastaccess = models.BigIntegerField() |
|||
lastlogin = models.BigIntegerField() |
|||
currentlogin = models.BigIntegerField() |
|||
lastip = models.CharField(max_length=45) |
|||
secret = models.CharField(max_length=15) |
|||
picture = models.BigIntegerField() |
|||
url = models.CharField(max_length=255) |
|||
description = models.TextField(blank=True) |
|||
mailformat = models.SmallIntegerField() |
|||
maildigest = models.SmallIntegerField() |
|||
maildisplay = models.SmallIntegerField() |
|||
htmleditor = models.SmallIntegerField() |
|||
autosubscribe = models.SmallIntegerField() |
|||
trackforums = models.SmallIntegerField() |
|||
timemodified = models.BigIntegerField() |
|||
trustbitmask = models.BigIntegerField() |
|||
imagealt = models.CharField(max_length=255, blank=True) |
|||
idnumber = models.CharField(max_length=255) |
|||
descriptionformat = models.SmallIntegerField() |
|||
timecreated = models.BigIntegerField() |
|||
suspended = models.SmallIntegerField() |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_user' |
|||
|
|||
def __unicode__(self): |
|||
return u'%s %s' % (self.firstname, self.lastname) |
|||
|
|||
|
|||
class UserEnrolments(models.Model): |
|||
id = models.BigIntegerField(primary_key=True) |
|||
status = models.BigIntegerField() |
|||
enrol = models.ForeignKey('Enrol', db_column='enrolid', related_name='user_enrolments') |
|||
user = models.ForeignKey('User', db_column='userid', related_name='Enrolments') |
|||
timestart = models.BigIntegerField() |
|||
timeend = models.BigIntegerField() |
|||
modifierid = models.BigIntegerField() |
|||
timecreated = models.BigIntegerField() |
|||
timemodified = models.BigIntegerField() |
|||
|
|||
class Meta: |
|||
managed = False |
|||
db_table = 'mdl_user_enrolments' |
@ -0,0 +1,3 @@ |
|||
from django.test import TestCase |
|||
|
|||
# Create your tests here. |
@ -0,0 +1,3 @@ |
|||
from django.shortcuts import render |
|||
|
|||
# Create your views here. |
Loading…
Reference in new issue