[virtualcommons-svn] commit/vcweb: alllee: adding activity availability to json activity list
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-08-05 22:20:54
|
1 new changeset in vcweb: http://bitbucket.org/virtualcommons/vcweb/changeset/98aac8a8db97/ changeset: 98aac8a8db97 user: alllee date: 2011-08-06 00:20:41 summary: adding activity availability to json activity list affected #: 2 files (576 bytes) --- a/vcweb/lighterprints/models.py Fri Aug 05 14:48:24 2011 -0700 +++ b/vcweb/lighterprints/models.py Fri Aug 05 15:20:41 2011 -0700 @@ -68,6 +68,9 @@ return Experiment.objects.filter(experiment_metadata=get_lighterprints_experiment_metadata(), status__in=('ACTIVE', 'ROUND_IN_PROGRESS')) +def is_activity_available(participant=None, experiment=None, activity=None, **kwargs): + return True + @receiver(signals.midnight_tick) def update_active_experiments(sender, time=None, **kwargs): for experiment in get_active_experiments(): --- a/vcweb/lighterprints/views.py Fri Aug 05 14:48:24 2011 -0700 +++ b/vcweb/lighterprints/views.py Fri Aug 05 15:20:41 2011 -0700 @@ -9,7 +9,7 @@ from vcweb.core.views import JSONResponseMixin, dumps # FIXME: move to core? from vcweb.lighterprints.forms import ActivityForm, ChatForm -from vcweb.lighterprints.models import Activity +from vcweb.lighterprints.models import Activity, is_activity_available import collections import logging @@ -17,7 +17,6 @@ class ActivityListView(JSONResponseMixin, MultipleObjectTemplateResponseMixin, BaseListView): -# FIXME: replace with dynamic set model = Activity def get_context_data(self, **kwargs): @@ -31,6 +30,12 @@ activity_as_dict = {} for attr_name in ('pk', 'name', 'summary', 'display_name', 'description', 'savings', 'url', 'available_all_day', 'level', 'group_activity', 'icon_url', 'time_remaining'): activity_as_dict[attr_name] = getattr(activity, attr_name, None) + if self.request.user.is_authenticated(): + # authenticated request, figure out if this activity is available + experiment_id = self.request.GET.get('experiment_id') + participant = self.request.user.participant + experiment = get_object_or_404(Experiment, pk=experiment_id) + activity_as_dict['availability'] = is_activity_available(participant=participant, experiment=experiment, activity=activity) flattened_activities.append(activity_as_dict) context['activity_by_level'] = dict(activity_by_level) @@ -77,6 +82,7 @@ participant_group_relationship = get_object_or_404(ParticipantGroupRelationship, pk=participant_group_pk) activity = get_object_or_404(Activity, pk=activity_id) + return HttpResponse('', content_type='text/javascript') return HttpResponseBadRequest("Invalid activity post") 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. |