Commit 8018f75b by Xavier Antoviaque

Fix anonymous_user_id retreival & model storage, add course_id

parent e29009fa
...@@ -131,11 +131,13 @@ class AnswerBlock(LightChild): ...@@ -131,11 +131,13 @@ class AnswerBlock(LightChild):
if not name: if not name:
raise ValueError, 'AnswerBlock.name field need to be set to a non-null/empty value' raise ValueError, 'AnswerBlock.name field need to be set to a non-null/empty value'
# TODO-WORKBENCH-WORKAROUND: Remove use of getattr(), used to work on both LMS & workbench student_id = self.xmodule_runtime.anonymous_student_id
student_id = getattr(self.runtime, 'anonymous_student_id', 'student1') # TODO: How do we get the course id?
course_id = 'default'
answer_data, created = Answer.objects.get_or_create( answer_data, created = Answer.objects.get_or_create(
student_id=student_id, student_id=student_id,
course_id=course_id,
name=name name=name
) )
return answer_data return answer_data
...@@ -84,7 +84,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin): ...@@ -84,7 +84,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
def add_node_as_child(cls, block, xml_child, child_id): def add_node_as_child(cls, block, xml_child, child_id):
# Instantiate child # Instantiate child
child_class = cls.get_class_by_element(xml_child.tag) child_class = cls.get_class_by_element(xml_child.tag)
child = child_class(block.runtime) child = child_class(block)
child.name = u'{}_{}'.format(block.name, child_id) child.name = u'{}_{}'.format(block.name, child_id)
# Add any children the child may itself have # Add any children the child may itself have
...@@ -168,8 +168,16 @@ class LightChild(Plugin, LightChildrenMixin): ...@@ -168,8 +168,16 @@ class LightChild(Plugin, LightChildrenMixin):
""" """
entry_point = 'xblock.light_children' entry_point = 'xblock.light_children'
def __init__(self, runtime): def __init__(self, parent):
self.runtime = runtime self.parent = parent
@property
def runtime(self):
return self.parent.runtime
@property
def xmodule_runtime(self):
return self.parent.xmodule_runtime
def save(self): def save(self):
pass pass
......
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Answer.course_id'
db.add_column('mentoring_answer', 'course_id',
self.gf('django.db.models.fields.CharField')(default='default', max_length=50, db_index=True),
keep_default=False)
# Changing field 'Answer.student_id'
db.alter_column('mentoring_answer', 'student_id', self.gf('django.db.models.fields.CharField')(max_length=32))
def backwards(self, orm):
# Deleting field 'Answer.course_id'
db.delete_column('mentoring_answer', 'course_id')
# Changing field 'Answer.student_id'
db.alter_column('mentoring_answer', 'student_id', self.gf('django.db.models.fields.CharField')(max_length=20))
models = {
'mentoring.answer': {
'Meta': {'unique_together': "(('student_id', 'name'),)", 'object_name': 'Answer'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified_on': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'student_id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_index': 'True'}),
'student_input': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
}
}
complete_apps = ['mentoring']
\ No newline at end of file
...@@ -39,7 +39,8 @@ class Answer(models.Model): ...@@ -39,7 +39,8 @@ class Answer(models.Model):
unique_together = (('student_id', 'name'),) unique_together = (('student_id', 'name'),)
name = models.CharField(max_length=50, db_index=True) name = models.CharField(max_length=50, db_index=True)
student_id = models.CharField(max_length=20, db_index=True) student_id = models.CharField(max_length=32, db_index=True)
course_id = models.CharField(max_length=50, db_index=True)
student_input = models.TextField(blank=True, default='') student_input = models.TextField(blank=True, default='')
created_on = models.DateTimeField('created on', auto_now_add=True) created_on = models.DateTimeField('created on', auto_now_add=True)
modified_on = models.DateTimeField('modified on', auto_now=True) modified_on = models.DateTimeField('modified on', auto_now=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment