[virtualcommons-svn] commit/vcweb: 2 new changesets
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-08-08 01:14:39
|
2 new changesets in vcweb: http://bitbucket.org/virtualcommons/vcweb/changeset/d67839ef489a/ changeset: d67839ef489a user: alllee date: 2011-08-08 03:06:43 summary: adding activity availability check affected #: 1 file (962 bytes) --- a/vcweb/lighterprints/models.py Fri Aug 05 15:20:41 2011 -0700 +++ b/vcweb/lighterprints/models.py Sun Aug 07 18:06:43 2011 -0700 @@ -1,10 +1,14 @@ from django.db import models from django.db.models import Sum from vcweb.core import signals, simplecache -from vcweb.core.models import Experiment, ExperimentMetadata, Experimenter, GroupRoundDataValue, Parameter +from vcweb.core.models import (Experiment, ExperimentMetadata, Experimenter, + GroupRoundDataValue, ParticipantRoundDataValue, Parameter) from django.dispatch import receiver import datetime +import logging +logger = logging.getLogger(__name__) + class Activity(models.Model): name = models.CharField(max_length=32, unique=True) display_name = models.CharField(max_length=64, null=True, blank=True) @@ -68,8 +72,22 @@ 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 +def is_activity_available(participant_group_relationship=None, activity=None, **kwargs): + if activity is None: + logger.debug("cannot check availability for non activity") + return False +# how often can a participant participate in an activity? For the time being, just +# whenever its schedule is available and + now = datetime.datetime.now() + current_time = now.time() + availabilities = ActivityAvailability.objects.filter(activity=activity, available_start_time__lte=current_time, available_end_time__gte=current_time) +# FIXME: check if this participant has already participated in this activity + data_value_set = ParticipantRoundDataValue.objects.filter(parameter=get_activity_performed_parameter(), + participant_group_relationship=participant_group_relationship, + submitted=True, + date_created__lte=now, + date_created__gte=now) + return availabilities.count() > 0 and data_value_set.count() == 0 @receiver(signals.midnight_tick) def update_active_experiments(sender, time=None, **kwargs): http://bitbucket.org/virtualcommons/vcweb/changeset/3223f6bd7cb5/ changeset: 3223f6bd7cb5 user: alllee date: 2011-08-08 03:14:28 summary: logic for performing activity affected #: 2 files (858 bytes) --- a/vcweb/lighterprints/models.py Sun Aug 07 18:06:43 2011 -0700 +++ b/vcweb/lighterprints/models.py Sun Aug 07 18:14:28 2011 -0700 @@ -72,23 +72,34 @@ return Experiment.objects.filter(experiment_metadata=get_lighterprints_experiment_metadata(), status__in=('ACTIVE', 'ROUND_IN_PROGRESS')) -def is_activity_available(participant_group_relationship=None, activity=None, **kwargs): +def is_activity_available(activity=None, participant_group_relationship=None, **kwargs): if activity is None: logger.debug("cannot check availability for non activity") return False -# how often can a participant participate in an activity? For the time being, just -# whenever its schedule is available and +# how often can a participant participate in an activity? +# whenever it falls within the ActivityAvailability schedule and if the participant +# hasn't already performed this activity during this cycle. now = datetime.datetime.now() current_time = now.time() availabilities = ActivityAvailability.objects.filter(activity=activity, available_start_time__lte=current_time, available_end_time__gte=current_time) # FIXME: check if this participant has already participated in this activity - data_value_set = ParticipantRoundDataValue.objects.filter(parameter=get_activity_performed_parameter(), + data_value_set = ParticipantRoundDataValue.objects.filter(parameter=get_activity_performed_parameter(), participant_group_relationship=participant_group_relationship, submitted=True, date_created__lte=now, date_created__gte=now) return availabilities.count() > 0 and data_value_set.count() == 0 +def do_activity(activity=None, participant_group_relationship=None): + if is_activity_available(activity, participant_group_relationship): + round_data = participant_group_relationship.group.current_round_data + return ParticipantRoundDataValue.objects.create(parameter=get_activity_performed_parameter(), + participant_group_relationship=participant_group_relationship, + round_data=round_data, + # FIXME: use activity unique name instead? + value=activity.pk + ) + @receiver(signals.midnight_tick) def update_active_experiments(sender, time=None, **kwargs): for experiment in get_active_experiments(): --- a/vcweb/lighterprints/views.py Sun Aug 07 18:06:43 2011 -0700 +++ b/vcweb/lighterprints/views.py Sun Aug 07 18:14:28 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, is_activity_available +from vcweb.lighterprints.models import Activity, is_activity_available, do_activity import collections import logging @@ -74,16 +74,16 @@ pass @csrf_exempt -def do_activity(request, activity_id): +def perform_activity_view(request, activity_id): form = ActivityForm(request.POST or None) if form.is_valid(): activity_id = form.cleaned_data['activity_id'] participant_group_pk = form.cleaned_data['participant_group_relationship_id'] 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') + performed_activity = do_activity(activity=activity, participant_group_relationship=participant_group_relationship) + logger.debug("performed activity %s", performed_activity) + return HttpResponse(dumps(performed_activity), 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. |