[virtualcommons-svn] commit/vcweb: all...@sod19.asu.edu: fixes to group activity json api, needed t
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-08-11 22:06:20
|
1 new changeset in vcweb: http://bitbucket.org/virtualcommons/vcweb/changeset/1bd576f15ec5/ changeset: 1bd576f15ec5 user: all...@sod19.asu.edu date: 2011-08-12 00:06:07 summary: fixes to group activity json api, needed to reroll JSONResponseMixin since getting parameters didn't seem to be working affected #: 2 files (789 bytes) --- a/vcweb/lighterprints/urls.py Thu Aug 11 14:41:26 2011 -0700 +++ b/vcweb/lighterprints/urls.py Thu Aug 11 15:06:07 2011 -0700 @@ -1,7 +1,8 @@ from django.conf.urls.defaults import url, patterns from vcweb.lighterprints.views import (ActivityDetailView, ActivityListView, MobileView, - post_chat_message, perform_activity, DiscussionBoardView, login) + post_chat_message, perform_activity, DiscussionBoardView, login, + group_activity) urlpatterns = patterns('vcweb.lighterprints.views', url(r'^mobile$', MobileView.as_view(), name='mobile'), @@ -9,7 +10,7 @@ url(r'^activity/list/?$', ActivityListView.as_view()), url(r'^activity/(?P<activity_id>\d+)$', ActivityDetailView.as_view()), url(r'^discussion/(?P<experiment_id>\d+)/(?P<participant_id>\d+)', DiscussionBoardView.as_view()), - url(r'^api/group-activity', DiscussionBoardView.as_view()), + url(r'^api/group-activity/(?P<participant_group_id>\d+)', group_activity), url(r'^api/do-activity$', perform_activity), url(r'^api/post-chat', post_chat_message), url(r'^api/login', login), --- a/vcweb/lighterprints/views.py Thu Aug 11 14:41:26 2011 -0700 +++ b/vcweb/lighterprints/views.py Thu Aug 11 15:06:07 2011 -0700 @@ -1,6 +1,7 @@ from django.contrib import auth from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import get_object_or_404 +from django.utils.timesince import timesince from django.views.decorators.csrf import csrf_exempt from django.views.generic.detail import BaseDetailView from django.views.generic.edit import FormView @@ -9,6 +10,7 @@ from vcweb.core.forms import LoginForm from vcweb.core.models import (ChatMessage, Experiment, ParticipantGroupRelationship, ParticipantRoundDataValue) from vcweb.core.views import JSONResponseMixin, dumps, set_authentication_token +from vcweb.core.validate_jsonp import is_valid_jsonp_callback_value # FIXME: move ChatForm to core? from vcweb.lighterprints.forms import ActivityForm, ChatForm from vcweb.lighterprints.models import (Activity, is_activity_available, do_activity, get_lighterprints_experiment_metadata, get_activity_performed_parameter) @@ -113,12 +115,24 @@ class DoActivityView(FormView): pass +def group_activity(request, participant_group_id): + participant_group_relationship = get_object_or_404(ParticipantGroupRelationship, pk=participant_group_id) + content = get_group_activity_json(participant_group_relationship) + callback = request.GET.get('callback', '') + content_type = 'application/x-json' + if is_valid_jsonp_callback_value(callback): + content = '%s(%s)' % (callback, content) + content_type = 'text/javascript' + return HttpResponse(content, content_type) + return HttpResponseBadRequest(dumps({'response': "Could not perform activity"}), content_type='text/javascript') + + def get_group_activity_json(participant_group_relationship, number_of_activities=5): group = participant_group_relationship.group chat_messages = [] for chat_message in ChatMessage.objects.filter(participant_group_relationship__group=group).order_by('-date_created'): chat_messages.append({ - 'date_created': chat_message.date_created, + 'date_created': timesince(chat_message.date_created), 'message': chat_message.message, 'participant_number': participant_group_relationship.participant_number, 'participant': participant_group_relationship.participant Repository URL: https://bitbucket.org/virtualcommons/vcweb/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |