Code view information of Instructors outside the homepage

25 views
Skip to first unread message

vantamtran

unread,
Apr 4, 2013, 7:35:05 AM4/4/13
to class2g...@googlegroups.com
Hi all,

I have read news about Class2Go and Edx! I very happy  but now I still research about class2go!

I post question in here I don't know who will is guide me! My skill python is not good! Thanks for you help me!

I have a problem with class2go : I want to view information of instructors outside homepage  (name, photo) And this is the code I add in course/landing/view.py :

#################################################################

def landing(request):
    
    if not request.user.is_authenticated():
        course_list = Course.objects.filter(mode='ready', institution_only = 0)
    else:
        course_list = Course.objects.filter(Q(mode='ready', 
                institution_only = 0) | Q(mode='ready', institution__id__in=request.user.get_profile().institutions.all()))
    
    course_instructors = CourseInstructor.objects.getByCourse(course=request.common_page_data['course'])
    instructors = []
    
    for ci in course_instructors:
        instructors.append(ci.instructor)

    site = getattr(settings, 'SITE_NAME_SHORT')
    r = render_to_response("sites/%s/landing.html" % site,
            {'hiring': hiring,
             'course_list':course_list,
     'instructors': instructors,
             'display_login': request.GET.__contains__('login')},
             context_instance=context)
    return r
##########################################################################

In landing.html I use but not success 

#############################
{% for instructor in instructors %}
 <h3>{{ instructor.name }}</h3>
{% endfor %}
############################

Thanks for help!

Joe Blaylock

unread,
Apr 4, 2013, 2:12:50 PM4/4/13
to vantamtran, class2g...@googlegroups.com
At first glance that looks right to me.  Have you got valid CourseInstructor objects in your system with the name field set? You could use the django admin interface at /admin/ to browse your objects and hopefully see.

You can insert debug output right before the call to render_to_response and then watch your console and use that to check whether instructors is getting set up with the right information.

Something like:
    site = getattr(settings, 'SITE_NAME_SHORT')
    print "DEBUG " + str([str(i) for i in instructors])
    r = render_to_response("sites/%s/landing.html" % site,
            {'hiring': hiring,
             'course_list':course_list,
    'instructors': instructors,
             'display_login': request.GET.__contains__('login')},
             context_instance=context)

If instructors is actually a list of courseinstructor objects as you expect, and courseinstructor objects have a name field as you expect, then something very bizarre indeed is going on.

--
You received this message because you are subscribed to the Google Groups "class2go users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to class2go-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

vantamtran

unread,
Apr 4, 2013, 10:00:58 PM4/4/13
to class2g...@googlegroups.com
Hi Joe, Thanks for reply!

Because default of class2go not view information instructors in homepage so I write code to view images and name intructors in homepage.

With the code I adding I get error: local variable 'course_instructors' referenced before assignment
####
course_instructors = CourseInstructor.objects.getByCourse(course=request.common_page_data['course'])
    instructors = []
    
    for ci in course_instructors: (error: local variable 'course_instructors' referenced before assignment)
        instructors.append(ci.instructor)

####
I don't know why "course_instructors" error! And in database table c2g_course_instructor has many data!



Joe Blaylock

unread,
Apr 5, 2013, 2:44:57 PM4/5/13
to vantamtran, class2g...@googlegroups.com
The formatting of your post is a bit confusing, and whitespace matters in Python. Perhaps you could put your code someplace that preserves formatting to make it easier to look at? For example, if you published a git branch, or made a gist (https://gist.github.com/) with it.

vantamtran

unread,
Apr 7, 2013, 11:21:53 PM4/7/13
to class2g...@googlegroups.com, vantamtran, jr...@stanford.edu
Thanks Joe, I have solved it!
Reply all
Reply to author
Forward
0 new messages