Skip to content

Instantly share code, notes, and snippets.

@hlian
Created March 19, 2010 22:08
Show Gist options
  • Save hlian/338252 to your computer and use it in GitHub Desktop.
Save hlian/338252 to your computer and use it in GitHub Desktop.
scg.apps.courses.api
import django.utils.simplejson as json
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from scg.apps.courses.models import Course
from scg.apps.reviews.models import CourseReview
def course(request, cid=None):
c = Course.objects.get(cid=cid)
r = CourseReview.objects.filter(course=c)
first, second = None, None
if len(r) >= 1:
first = r[0].comment
if len(r) >= 2:
second = r[1].comment
data = {
'first': first,
'second': second,
'link': reverse('scg.apps.courses.views.course_detail', args=[c.cid]),
}
return HttpResponse(json.dumps(data), mimetype='text/plain')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment