[virtualcommons-developer] commit/vcweb: dieg...@gmail.com: creating form for chat within and betwe
Status: Beta
Brought to you by:
alllee
From: <com...@bi...> - 2013-03-27 21:31:58
|
1 new commit in vcweb: https://bitbucket.org/virtualcommons/vcweb/commits/d6f1de14bbcb/ Changeset: d6f1de14bbcb User: dieg...@gmail.com Date: 2013-03-27 22:31:44 Summary: creating form for chat within and between group Affected #: 3 files diff -r 0d78692980a78f5136533fffb68a7f67ba900faa -r d6f1de14bbcb0eda4c678329b03a7b2ed6dca41b vcweb/broker/forms.py --- /dev/null +++ b/vcweb/broker/forms.py @@ -0,0 +1,8 @@ +from django import forms + +__author__ = 'diegogalafassi' + +class ChatPreferenceForm (forms.Form): + participant_group_id = forms.IntegerField() + chat_within_group = forms.BooleanField(default=False) + chat_between_group = forms.BooleanField(default=False) diff -r 0d78692980a78f5136533fffb68a7f67ba900faa -r d6f1de14bbcb0eda4c678329b03a7b2ed6dca41b vcweb/broker/models.py --- a/vcweb/broker/models.py +++ b/vcweb/broker/models.py @@ -19,7 +19,7 @@ @simplecache def get_participant_payoff_parameter(): - return Parameter.objects.get(name='participant_payoff') + return Parameter.objects.get(name='payoff') @simplecache diff -r 0d78692980a78f5136533fffb68a7f67ba900faa -r d6f1de14bbcb0eda4c678329b03a7b2ed6dca41b vcweb/broker/views.py --- a/vcweb/broker/views.py +++ b/vcweb/broker/views.py @@ -5,7 +5,7 @@ from vcweb.core.forms import ParticipantGroupIdForm, SingleIntegerDecisionForm from vcweb.core.http import JsonResponse from vcweb.core.models import (is_participant, is_experimenter, Experiment, ParticipantGroupRelationship, - ParticipantExperimentRelationship, RoundConfiguration, ChatMessage, ParticipantRoundDataValue) + ParticipantExperimentRelationship, RoundConfiguration, ChatMessage, ParticipantRoundDataValue, Parameter) from vcweb.broker.models import (get_max_harvest_hours, get_harvest_decision_parameter, get_conservation_decision_parameter, set_harvest_decision, set_conservation_decision, get_harvest_decision, @@ -14,9 +14,44 @@ import random import logging +from vcweb.broker.forms import ChatPreferenceForm logger = logging.getLogger(__name__) + +def get_chat_between_group_parameter(): + return Parameter.objects.get(Name="chat_between_group") + +def get_chat_within_group_parameter(): + return Parameter.objects.get(Name="chat_within_group") + +@participant_required +def submit_chat_preference (request, experiment_id=None,): + form = ChatPreferenceForm(request.POST or None) + experiment = get_object_or_404(Experiment, pk=experiment_id) + if form.is_valid(): + logger.debug("handing POST request, cleaned data: %s", form.cleaned_data) + participant_group_id = form.cleaned_data['participant_group_id'] + pgr = get_object_or_404(ParticipantGroupRelationship, pk=participant_group_id) + round_data = experiment.current_round_data + chat_within_group = form.cleaned_data['chat_within_group'] + chat_between_group = form.cleaned_data['chat_between_group'] + pgr.set_data_value(parameter=get_chat_within_group_parameter(), value=chat_within_group, round_data=round_data) + pgr.set_data_value(parameter=get_chat_between_group_parameter(), value=chat_between_group, round_data=round_data) + ncwg = ParticipantRoundDataValue.objects.filter(parameter=get_chat_within_group_parameter(), round_data=round_data, submitted=True).count() + ncbg = ParticipantRoundDataValue.objects.filter(parameter=get_chat_between_group_parameter(), round_data=round_data, submitted=True).count() + np = experiment.participant_set.count() + response_dict = { + 'success': True, + 'all_participants_submitted': False, + } + if ncwg == np and ncbg == np: + # everyone submitted a chat preference decision, create participant linkages + + response_dict['all_participants_submitted'] = True + return JsonResponse(dumps(response_dict)) + return JsonResponse(dumps({'success': False})) + @participant_required def submit_decision(request, experiment_id=None): form = SingleIntegerDecisionForm(request.POST or None) 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. |