A Database created by Moodle

14 views
Skip to first unread message

Skylar Saveland

unread,
May 16, 2009, 5:57:38 PM5/16/09
to pinax-lms
Maybe a good way to move forward is to create model definitions that
will work with a DB created by Moodle. With inspecdb, one gets fairly
close (not really but at least one gets some idea).

Moodle however, I believe, basically uses strings for almost
everything and doesn't have DateTimeFields that I can tell. I'm not
really in a position to speculate why inspectdb turned output exactly
what it did; it would take some time to understand.

I am tempted to paste the 2598 lines here for the latest stable
default Moodle install. Oh, why not? Okay, I thought better of
pasting that many lines of code (plus, how can you yank to the ssh
clients clipboard? I think I would have to turn on X11
forwarding.. ). A little taste is below. A lot of the models and
fields that are not required could be shaved off (although inspectdb
didn't seem to understand anything of what should allow blank/null).
I wonder how Moodle handles these things?

It is probably not the way that I would want to design the relations
(which exactly are the relations anyways?) and would take quite a bit
of translating to really fit Django's ORM on top of the Moodle's DB
but it might be a worthy goal.

Do you all think that it is a worthy goal? Applicable to pinax-lms or
would I be out in the wilderness alone with django-moodle?

I was thinking that the only useability hurdle for a school that was
running webctvista/moodle/pinax-lms would be transferring the session/
reading the moodle cookie and authenticating users based on it. idk,
it ANYTHING would be an improvement on WebCTVista...


class MdlCourse(models.Model):
id = models.TextField(primary_key=True) # This field type is a
guess.
category = models.TextField() # This field type is a guess.
sortorder = models.TextField() # This field type is a guess.
password = models.CharField(max_length=50)
fullname = models.CharField(max_length=254)
shortname = models.CharField(max_length=100)
idnumber = models.CharField(max_length=100)
summary = models.TextField()
format = models.CharField(max_length=10)
showgrades = models.SmallIntegerField()
modinfo = models.TextField()
newsitems = models.IntegerField()
teacher = models.CharField(max_length=100)
teachers = models.CharField(max_length=100)
student = models.CharField(max_length=100)
students = models.CharField(max_length=100)
guest = models.SmallIntegerField()
startdate = models.TextField() # This field type is a guess.
enrolperiod = models.TextField() # This field type is a guess.
numsections = models.IntegerField()
marker = models.TextField() # This field type is a guess.
maxbytes = models.TextField() # This field type is a guess.
showreports = models.SmallIntegerField()
visible = models.SmallIntegerField()
hiddensections = models.SmallIntegerField()
groupmode = models.SmallIntegerField()
groupmodeforce = models.SmallIntegerField()
defaultgroupingid = models.TextField() # This field type is a
guess.
lang = models.CharField(max_length=30)
theme = models.CharField(max_length=50)
cost = models.CharField(max_length=10)
currency = models.CharField(max_length=3)
timecreated = models.TextField() # This field type is a guess.
timemodified = models.TextField() # This field type is a guess.
metacourse = models.SmallIntegerField()
requested = models.SmallIntegerField()
restrictmodules = models.SmallIntegerField()
expirynotify = models.SmallIntegerField()
expirythreshold = models.TextField() # This field type is a guess.
notifystudents = models.SmallIntegerField()
enrollable = models.SmallIntegerField()
enrolstartdate = models.TextField() # This field type is a guess.
enrolenddate = models.TextField() # This field type is a guess.
enrol = models.CharField(max_length=20)
defaultrole = models.TextField() # This field type is a guess.
class Meta:
db_table = u'mdl_course'

I will put up a project on github if anyone is interested and I can at
least put the 2598 lines of models up there ... maybe just a complete
project that can tie in to an existing DB and use the admin and start
writing model methods and help_text and changing to the appropriate
fields.

Am I totally insane or is this a possible route that people will want
to travel with me?

Bruce D'Arcus

unread,
May 17, 2009, 12:41:43 PM5/17/09
to pina...@googlegroups.com
Just a quick comment; if the below really reflects the Moodle data
model, it would seem to present real limitations for a next-generation
CMS; there's just way too much packed into a single model.

As I've said elsewhere on this group, you really need core models that reflect:

1) abstract courses
2) concrete course instances
3) enrollments

[ ... and a few others I'm forgetting ...]

Bruce

Skylar Saveland

unread,
May 18, 2009, 11:37:57 AM5/18/09
to pinax-lms
Well, this idea might be sunk before it leaves the harbor.

timemodified = models.TextField() # This field type is a guess.

That is a bigint column. Apparently Django can not transact with a
bigint column?

http://code.djangoproject.com/ticket/399

All of Moodle's dates and times are apparently represented as unix
timestamps in bigint.

So, the Django ORM transacting with such a db is hopeless right now or
is there a fix?

Skylar Saveland

unread,
May 18, 2009, 4:30:11 PM5/18/09
to pinax-lms
If anyone would like to look at the inspectdb of the Moodle tables you
can find them here:

http://github.com/ssavelan/django-moodle/blob/10b707b74de82a717c39c78743ad57e7187164aa/moodels.py

On May 18, 11:37 am, Skylar Saveland <skylar.savel...@gmail.com>
wrote:

Skylar Saveland

unread,
May 18, 2009, 4:53:29 PM5/18/09
to pinax-lms
> http://github.com/ssavelan/django-moodle/blob/10b707b74de82a717c39c78...

Looking it over some more I see that all of the primary keys and then
FKs are bigint too.

(dates and times in Moodle are unix timestamps stored as bigint too).

Is this a deal-stopper for integrating with an existing Moodle user
and course base?

Skylar Saveland

unread,
May 18, 2009, 5:13:49 PM5/18/09
to pinax-lms
> (dates and times in Moodle are unix timestamps stored as bigint too).
>
> Is this a deal-stopper for integrating with an existing Moodle user
> and course base?

Apparently this int/bigint for keys will not be at all a problem. So,
the only fields I see that are incompatible are the dates and times.
Since Django can transact with bigint like it was an int I think that
writing a custom field that will return a python datetime object from
a bigint column will not be too arduous.

Skylar Saveland

unread,
May 18, 2009, 6:10:30 PM5/18/09
to pinax-lms
> writing a custom field that will return a python datetime object from
> a bigint column will not be too arduous.

datetime.datetime.fromtimestamp(m.lastaccess) produces a datetime
object from a Moodle record.

Maybe I should stop talking and get to coding ;)
Reply all
Reply to author
Forward
0 new messages