From 63ea452f171449e43d006eeeeb8aa73888998a96 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Wed, 29 Jun 2016 16:45:56 -0700 Subject: [PATCH 01/40] Add form to contact workers with --- expdj/apps/turk/forms.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/expdj/apps/turk/forms.py b/expdj/apps/turk/forms.py index eb35dad..d5674a3 100644 --- a/expdj/apps/turk/forms.py +++ b/expdj/apps/turk/forms.py @@ -31,3 +31,12 @@ def __init__(self, *args, **kwargs): self.helper.layout = Layout() tab_holder = TabHolder() self.helper.add_input(Submit("submit", "Save")) + +class WorkerContactForm(forms.Form): + subject = forms.CharField(label="Subject") + message = forms.CharField(label="Message") + + def __init__(self, *args, **kwargs): + super(ContactForm, self).__init__(*args, **kwargs) + self.helper = FormHelper(self) + self.helper.add_input(Submit("submit", "Send")) From dc1a96551dd661c2f2f2c0a1b290b35dbcf65265 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Wed, 29 Jun 2016 16:47:04 -0700 Subject: [PATCH 02/40] add contact worker function to assignment model, this model has access to all the information we need to generate connections and send information to workers. Add contact worker view to handle creating and processing the form --- expdj/apps/turk/models.py | 13 +++++++- expdj/apps/turk/views.py | 69 +++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/expdj/apps/turk/models.py b/expdj/apps/turk/models.py index 5319836..2d54ce4 100644 --- a/expdj/apps/turk/models.py +++ b/expdj/apps/turk/models.py @@ -407,7 +407,6 @@ class Assignment(models.Model): (True, 'Completed')), default=False,verbose_name="participant completed the entire assignment") - def create(self): init_connection_callback(sender=self.hit) @@ -480,6 +479,18 @@ def update(self, mturk_assignment=None, hit=None): self.save() + def contact_worker(self, subject, msg): + '''contact_worker uses the boto function notify_workers to send a + message a specific worker. + :subject: Subject of the message to send. + :msg: Contents of the message to send. + ''' + self.hit.generate_connection() + try: + self.hit.connection.notify_workers(self.worker.id, subject, msg) + except MTurkRequestError: + pass + def __unicode__(self): return self.mturk_id diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 6d12149..7bd9145 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -1,25 +1,32 @@ -from expdj.apps.experiments.views import check_battery_edit_permission, check_mturk_access, \ -get_battery_intro, deploy_battery -from expdj.apps.turk.utils import get_connection, get_worker_url, get_host, get_worker_experiments -from django.http.response import HttpResponseRedirect, HttpResponseForbidden, HttpResponse, Http404 -from django.shortcuts import get_object_or_404, render_to_response, render, redirect -from expdj.apps.turk.tasks import assign_experiment_credit, get_unique_experiments -from expdj.apps.experiments.utils import get_experiment_type, select_experiments -from expdj.apps.turk.models import Worker, HIT, Assignment, Result, get_worker -from expdj.apps.experiments.models import Battery, ExperimentTemplate +from datetime import timedelta, datetime +import json +import os +import requests + from expfactory.battery import get_load_static, get_experiment_run -from expdj.settings import BASE_DIR,STATIC_ROOT,MEDIA_ROOT +from numpy.random import choice +from optparse import make_option + from django.contrib.auth.decorators import login_required from django.core.management.base import BaseCommand -from django.views.decorators.csrf import ensure_csrf_cookie -from expdj.apps.turk.forms import HITForm -from datetime import timedelta, datetime +from django.http.response import (HttpResponseRedirect, HttpResponseForbidden, + HttpResponse, Http404, HttpResponseNotAllowed) +from django.shortcuts import get_object_or_404, render_to_response, render, redirect from django.utils import timezone -from optparse import make_option -from numpy.random import choice -import requests -import json -import os +from django.views.decorators.csrf import ensure_csrf_cookie + +from expdj.apps.experiments.models import (Assignment, Battery, + ExperimentTemplate) +from expdj.apps.experiments.views import (check_battery_edit_permission, + check_mturk_access, get_battery_intro, deploy_battery) +from expdj.apps.experiments.utils import get_experiment_type, select_experiments +from expdj.apps.turk.forms import HITForm, WorkerContactForm +from expdj.apps.turk.models import Worker, HIT, Assignment, Result, get_worker +from expdj.apps.turk.tasks import (assign_experiment_credit, + check_battery_dependencies, get_unique_experiments) +from expdj.apps.turk.utils import (get_connection, get_host, get_worker_url, + get_worker_experiments) +from expdj.settings import BASE_DIR,STATIC_ROOT,MEDIA_ROOT media_dir = os.path.join(BASE_DIR,MEDIA_ROOT) @@ -329,6 +336,32 @@ def edit_hit(request, bid, hid=None): else: return HttpResponseForbidden() +@login_required +def contact_worker(request, aid): + mturk_permission = check_mturk_access(request) + + if mturk_permission == False: + return HttpResponseForbidden() + + assignment = Assignments.objects.get(aid) + if request.method == "GET": + form = WorkerContactForm() + worker = assignment.worker + context = { + "form": form, + "worker": worker + } + return(request, "contact_worker_modal.html", context) + elif request.method == "POST": + form = WorkerContactForm(request.POST) + if form.is_valid(): + subject = form.cleaned_data['subject'] + message = form.cleaned_data['message'] + assignment.contact_worker(subject, message) + return manage_hit(assignment.hit.battery.id, assignment.hit.id) + else: + return HttpResponseNotAllowed() + # Expire a hit @login_required def expire_hit(request, hid): From 7e31470b3dac3b0f7058e41257f45cf1ae428b0d Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Wed, 29 Jun 2016 16:48:03 -0700 Subject: [PATCH 03/40] temporary contact worker button in manage hit view, still missing modal support, and a proper url route --- expdj/apps/turk/templates/turk/manage_hit.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/expdj/apps/turk/templates/turk/manage_hit.html b/expdj/apps/turk/templates/turk/manage_hit.html index d6e7fde..5b845ff 100644 --- a/expdj/apps/turk/templates/turk/manage_hit.html +++ b/expdj/apps/turk/templates/turk/manage_hit.html @@ -158,6 +158,7 @@

Approved

Worker ID Status Accept Time + Contact @@ -167,6 +168,7 @@

Approved

{{ assignment.worker }} {{ assignment.status }} {{ assignment.accept_time | localize }} + Contact Worker {% endfor %} From d551fe6f752921c889683be744f6910f4b445eac Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Thu, 30 Jun 2016 15:10:04 -0700 Subject: [PATCH 04/40] added template for contact worker form --- .../templates/turk/contact_worker_modal.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 expdj/apps/turk/templates/turk/contact_worker_modal.html diff --git a/expdj/apps/turk/templates/turk/contact_worker_modal.html b/expdj/apps/turk/templates/turk/contact_worker_modal.html new file mode 100644 index 0000000..8fdb15e --- /dev/null +++ b/expdj/apps/turk/templates/turk/contact_worker_modal.html @@ -0,0 +1,19 @@ +{% load crispy_forms_tags %} + From 23c3d9db58811e3a749adf004f7eb92fa8a8e3db Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:32:10 -0700 Subject: [PATCH 05/40] fix import issues in turk views. Added url for contact worker. Added code to load contact worker view in manage_hit template --- .../apps/turk/templates/turk/manage_hit.html | 9 ++++- expdj/apps/turk/urls.py | 39 ++++++++++++++----- expdj/apps/turk/utils.py | 18 ++++++--- expdj/apps/turk/views.py | 5 +-- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/expdj/apps/turk/templates/turk/manage_hit.html b/expdj/apps/turk/templates/turk/manage_hit.html index 5b845ff..58e3d46 100644 --- a/expdj/apps/turk/templates/turk/manage_hit.html +++ b/expdj/apps/turk/templates/turk/manage_hit.html @@ -168,7 +168,7 @@

Approved

{{ assignment.worker }} {{ assignment.status }} {{ assignment.accept_time | localize }} - Contact Worker + Contact Worker {% endfor %} @@ -177,6 +177,8 @@

Approved

{% endif %} + {% endblock %} @@ -192,6 +194,11 @@

Approved

$('.collapse').collapse('hide'); }) +$('.contact_worker').on("click", function(e) { + e.preventDefault(); + $('#contact_modal').modal("show").load(this.href); +}); + }) {% endblock %} diff --git a/expdj/apps/turk/urls.py b/expdj/apps/turk/urls.py index 1bdf124..73c84d8 100644 --- a/expdj/apps/turk/urls.py +++ b/expdj/apps/turk/urls.py @@ -1,6 +1,6 @@ -from expdj.apps.turk.views import edit_hit, delete_hit, expire_hit, preview_hit, \ -serve_hit, multiple_new_hit, end_assignment, finished_view, not_consent_view, \ -survey_submit, manage_hit +from expdj.apps.turk.views import (edit_hit, delete_hit, expire_hit, + preview_hit, serve_hit, multiple_new_hit, end_assignment, finished_view, + not_consent_view, survey_submit, manage_hit, contact_worker) from expdj.apps.experiments.views import sync from django.views.generic.base import TemplateView from django.conf.urls import patterns, url @@ -8,9 +8,21 @@ urlpatterns = patterns('', # HITS url(r'^hits/(?P\d+|[A-Z]{8})/new$',edit_hit,name='new_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/manage$',manage_hit,name='manage_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/multiple$',multiple_new_hit,name='multiple_new_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/edit$',edit_hit,name='edit_hit'), + url( + r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/manage$', + manage_hit, + name='manage_hit' + ), + url( + r'^hits/(?P\d+|[A-Z]{8})/multiple$', + multiple_new_hit, + name='multiple_new_hit' + ), + url( + r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/edit$', + edit_hit, + name='edit_hit' + ), url(r'^hits/(?P\d+|[A-Z]{8})/delete$',delete_hit,name='delete_hit'), url(r'^hits/(?P\d+|[A-Z]{8})/expire$',expire_hit,name='expire_hit'), @@ -18,9 +30,18 @@ url(r'^accept/(?P\d+|[A-Z]{8})',serve_hit,name='serve_hit'), url(r'^turk/(?P\d+|[A-Z]{8})',preview_hit,name='preview_hit'), url(r'^turk/preview',not_consent_view,name='not_consent_view'), - url(r'^turk/end/(?P\d+|[A-Z]{8})',end_assignment,name='end_assignment'), - url(r'^surveys/(?P\d+|[A-Z]{8})/(?P[A-Za-z0-9]{30})/submit$',survey_submit,name='survey_submit'), + url( + r'^turk/end/(?P\d+|[A-Z]{8})', + end_assignment, + name='end_assignment' + ), + url( + r'^surveys/(?P\d+|[A-Z]{8})/(?P[A-Za-z0-9]{30})/submit$', + survey_submit, + name='survey_submit' + ), url(r'^sync/(?P\d+|[A-Z]{8})/$',sync,name='sync_data'), url(r'^sync/$',sync,name='sync_data'), - url(r'^finished$', finished_view, name="finished_view") + url(r'^finished$', finished_view, name="finished_view"), + url(r'^worker/contact/(?P\d+)',contact_worker,name='contact_worker') ) diff --git a/expdj/apps/turk/utils.py b/expdj/apps/turk/utils.py index ad525ee..c8902f9 100644 --- a/expdj/apps/turk/utils.py +++ b/expdj/apps/turk/utils.py @@ -1,16 +1,19 @@ -from expdj.apps.experiments.models import Experiment -from boto.mturk.connection import MTurkConnection -from expdj.settings import BASE_DIR, MTURK_ALLOW -from boto.mturk.question import ExternalQuestion -from boto.mturk.price import Price import ConfigParser import datetime -import pandas import json import os +from boto.mturk.connection import MTurkConnection +from boto.mturk.price import Price +from boto.mturk.question import ExternalQuestion +import pandas + from django.conf import settings +from expdj.apps.experiments.models import Experiment +from expdj.settings import BASE_DIR, MTURK_ALLOW + + # RESULTS UTILS def to_dict(input_ordered_dict): @@ -132,3 +135,6 @@ def get_time_difference(d1,d2,format='%Y-%m-%d %H:%M:%S'): if isinstance(d2,str): d2 = datetime.datetime.strptime(d2, format) return (d2 - d1).total_seconds() / 60 + + + diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 7bd9145..335689c 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -15,15 +15,14 @@ from django.utils import timezone from django.views.decorators.csrf import ensure_csrf_cookie -from expdj.apps.experiments.models import (Assignment, Battery, - ExperimentTemplate) +from expdj.apps.experiments.models import (Battery, ExperimentTemplate) from expdj.apps.experiments.views import (check_battery_edit_permission, check_mturk_access, get_battery_intro, deploy_battery) from expdj.apps.experiments.utils import get_experiment_type, select_experiments from expdj.apps.turk.forms import HITForm, WorkerContactForm from expdj.apps.turk.models import Worker, HIT, Assignment, Result, get_worker from expdj.apps.turk.tasks import (assign_experiment_credit, - check_battery_dependencies, get_unique_experiments) + get_unique_experiments) from expdj.apps.turk.utils import (get_connection, get_host, get_worker_url, get_worker_experiments) from expdj.settings import BASE_DIR,STATIC_ROOT,MEDIA_ROOT From 786ef3b47620a662c90e63175be4802b06cb2c60 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:49:37 -0700 Subject: [PATCH 06/40] fixed a couple sytax issues --- expdj/apps/turk/forms.py | 2 +- expdj/apps/turk/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/expdj/apps/turk/forms.py b/expdj/apps/turk/forms.py index d5674a3..4f7ccf3 100644 --- a/expdj/apps/turk/forms.py +++ b/expdj/apps/turk/forms.py @@ -37,6 +37,6 @@ class WorkerContactForm(forms.Form): message = forms.CharField(label="Message") def __init__(self, *args, **kwargs): - super(ContactForm, self).__init__(*args, **kwargs) + super(WorkerContactForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.add_input(Submit("submit", "Send")) diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 335689c..628af15 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -342,7 +342,7 @@ def contact_worker(request, aid): if mturk_permission == False: return HttpResponseForbidden() - assignment = Assignments.objects.get(aid) + assignment = Assignment.objects.get(id=aid) if request.method == "GET": form = WorkerContactForm() worker = assignment.worker @@ -350,7 +350,7 @@ def contact_worker(request, aid): "form": form, "worker": worker } - return(request, "contact_worker_modal.html", context) + return render(request, "turk/contact_worker_modal.html", context) elif request.method == "POST": form = WorkerContactForm(request.POST) if form.is_valid(): From 6b2f4cb428e1d2845ae9810de3d4e0a039bc1e5e Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:51:36 -0700 Subject: [PATCH 07/40] forgot to pass request to manage_hit when redirecting in contact worker --- expdj/apps/turk/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 628af15..317c98d 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -357,7 +357,8 @@ def contact_worker(request, aid): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] assignment.contact_worker(subject, message) - return manage_hit(assignment.hit.battery.id, assignment.hit.id) + return manage_hit(request, assignment.hit.battery.id, + assignment.hit.id) else: return HttpResponseNotAllowed() From 81e3cea70bf1d7c6d55e1b01353f56f657cd14c7 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 16:00:21 -0700 Subject: [PATCH 08/40] added missing form tags for contact worker modal --- expdj/apps/turk/templates/turk/contact_worker_modal.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expdj/apps/turk/templates/turk/contact_worker_modal.html b/expdj/apps/turk/templates/turk/contact_worker_modal.html index 8fdb15e..7d6f9ad 100644 --- a/expdj/apps/turk/templates/turk/contact_worker_modal.html +++ b/expdj/apps/turk/templates/turk/contact_worker_modal.html @@ -7,9 +7,9 @@ {% endif %} + {% endblock %} @@ -192,6 +194,11 @@

Approved

$('.collapse').collapse('hide'); }) +$('.contact_worker').on("click", function(e) { + e.preventDefault(); + $('#contact_modal').modal("show").load(this.href); +}); + }) {% endblock %} diff --git a/expdj/apps/turk/urls.py b/expdj/apps/turk/urls.py index 1bdf124..73c84d8 100644 --- a/expdj/apps/turk/urls.py +++ b/expdj/apps/turk/urls.py @@ -1,6 +1,6 @@ -from expdj.apps.turk.views import edit_hit, delete_hit, expire_hit, preview_hit, \ -serve_hit, multiple_new_hit, end_assignment, finished_view, not_consent_view, \ -survey_submit, manage_hit +from expdj.apps.turk.views import (edit_hit, delete_hit, expire_hit, + preview_hit, serve_hit, multiple_new_hit, end_assignment, finished_view, + not_consent_view, survey_submit, manage_hit, contact_worker) from expdj.apps.experiments.views import sync from django.views.generic.base import TemplateView from django.conf.urls import patterns, url @@ -8,9 +8,21 @@ urlpatterns = patterns('', # HITS url(r'^hits/(?P\d+|[A-Z]{8})/new$',edit_hit,name='new_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/manage$',manage_hit,name='manage_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/multiple$',multiple_new_hit,name='multiple_new_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/edit$',edit_hit,name='edit_hit'), + url( + r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/manage$', + manage_hit, + name='manage_hit' + ), + url( + r'^hits/(?P\d+|[A-Z]{8})/multiple$', + multiple_new_hit, + name='multiple_new_hit' + ), + url( + r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/edit$', + edit_hit, + name='edit_hit' + ), url(r'^hits/(?P\d+|[A-Z]{8})/delete$',delete_hit,name='delete_hit'), url(r'^hits/(?P\d+|[A-Z]{8})/expire$',expire_hit,name='expire_hit'), @@ -18,9 +30,18 @@ url(r'^accept/(?P\d+|[A-Z]{8})',serve_hit,name='serve_hit'), url(r'^turk/(?P\d+|[A-Z]{8})',preview_hit,name='preview_hit'), url(r'^turk/preview',not_consent_view,name='not_consent_view'), - url(r'^turk/end/(?P\d+|[A-Z]{8})',end_assignment,name='end_assignment'), - url(r'^surveys/(?P\d+|[A-Z]{8})/(?P[A-Za-z0-9]{30})/submit$',survey_submit,name='survey_submit'), + url( + r'^turk/end/(?P\d+|[A-Z]{8})', + end_assignment, + name='end_assignment' + ), + url( + r'^surveys/(?P\d+|[A-Z]{8})/(?P[A-Za-z0-9]{30})/submit$', + survey_submit, + name='survey_submit' + ), url(r'^sync/(?P\d+|[A-Z]{8})/$',sync,name='sync_data'), url(r'^sync/$',sync,name='sync_data'), - url(r'^finished$', finished_view, name="finished_view") + url(r'^finished$', finished_view, name="finished_view"), + url(r'^worker/contact/(?P\d+)',contact_worker,name='contact_worker') ) diff --git a/expdj/apps/turk/utils.py b/expdj/apps/turk/utils.py index 6ec8592..1f9b803 100644 --- a/expdj/apps/turk/utils.py +++ b/expdj/apps/turk/utils.py @@ -1,16 +1,19 @@ -from expdj.apps.experiments.models import Experiment -from boto.mturk.connection import MTurkConnection -from expdj.settings import BASE_DIR, MTURK_ALLOW -from boto.mturk.question import ExternalQuestion -from boto.mturk.price import Price import ConfigParser import datetime -import pandas import json import os +from boto.mturk.connection import MTurkConnection +from boto.mturk.price import Price +from boto.mturk.question import ExternalQuestion +import pandas + from django.conf import settings +from expdj.apps.experiments.models import Experiment +from expdj.settings import BASE_DIR, MTURK_ALLOW + + # RESULTS UTILS def to_dict(input_ordered_dict): @@ -132,3 +135,6 @@ def get_time_difference(d1,d2,format='%Y-%m-%d %H:%M:%S'): if isinstance(d2,str): d2 = datetime.datetime.strptime(d2, format) return (d2 - d1).total_seconds() / 60 + + + diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 9c6aae0..76d3e3e 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -15,15 +15,14 @@ from django.utils import timezone from django.views.decorators.csrf import ensure_csrf_cookie -from expdj.apps.experiments.models import (Assignment, Battery, - ExperimentTemplate) +from expdj.apps.experiments.models import (Battery, ExperimentTemplate) from expdj.apps.experiments.views import (check_battery_edit_permission, check_mturk_access, get_battery_intro, deploy_battery) from expdj.apps.experiments.utils import get_experiment_type, select_experiments from expdj.apps.turk.forms import HITForm, WorkerContactForm from expdj.apps.turk.models import Worker, HIT, Assignment, Result, get_worker from expdj.apps.turk.tasks import (assign_experiment_credit, - check_battery_dependencies, get_unique_experiments) + get_unique_experiments) from expdj.apps.turk.utils import (get_connection, get_host, get_worker_url, get_worker_experiments) from expdj.settings import BASE_DIR,STATIC_ROOT,MEDIA_ROOT From 8b60c7cecbfdb71ebf19ed525e519b0c94bb6311 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:49:37 -0700 Subject: [PATCH 17/40] fixed a couple sytax issues --- expdj/apps/turk/forms.py | 2 +- expdj/apps/turk/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/expdj/apps/turk/forms.py b/expdj/apps/turk/forms.py index d5674a3..4f7ccf3 100644 --- a/expdj/apps/turk/forms.py +++ b/expdj/apps/turk/forms.py @@ -37,6 +37,6 @@ class WorkerContactForm(forms.Form): message = forms.CharField(label="Message") def __init__(self, *args, **kwargs): - super(ContactForm, self).__init__(*args, **kwargs) + super(WorkerContactForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.add_input(Submit("submit", "Send")) diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 76d3e3e..4f2f722 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -347,7 +347,7 @@ def contact_worker(request, aid): if mturk_permission == False: return HttpResponseForbidden() - assignment = Assignments.objects.get(aid) + assignment = Assignment.objects.get(id=aid) if request.method == "GET": form = WorkerContactForm() worker = assignment.worker @@ -355,7 +355,7 @@ def contact_worker(request, aid): "form": form, "worker": worker } - return(request, "contact_worker_modal.html", context) + return render(request, "turk/contact_worker_modal.html", context) elif request.method == "POST": form = WorkerContactForm(request.POST) if form.is_valid(): From 4e5565b94aff6b8b9c0d256d3bc577d5539a9696 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:51:36 -0700 Subject: [PATCH 18/40] forgot to pass request to manage_hit when redirecting in contact worker --- expdj/apps/turk/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 4f2f722..067014a 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -362,7 +362,8 @@ def contact_worker(request, aid): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] assignment.contact_worker(subject, message) - return manage_hit(assignment.hit.battery.id, assignment.hit.id) + return manage_hit(request, assignment.hit.battery.id, + assignment.hit.id) else: return HttpResponseNotAllowed() From e06b802e45f24cd0ef60ad4f5abde490f63066d1 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 16:00:21 -0700 Subject: [PATCH 19/40] added missing form tags for contact worker modal --- expdj/apps/turk/templates/turk/contact_worker_modal.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expdj/apps/turk/templates/turk/contact_worker_modal.html b/expdj/apps/turk/templates/turk/contact_worker_modal.html index 8fdb15e..7d6f9ad 100644 --- a/expdj/apps/turk/templates/turk/contact_worker_modal.html +++ b/expdj/apps/turk/templates/turk/contact_worker_modal.html @@ -7,9 +7,9 @@ {% endif %} + {% endblock %} @@ -192,6 +194,11 @@

Approved

$('.collapse').collapse('hide'); }) +$('.contact_worker').on("click", function(e) { + e.preventDefault(); + $('#contact_modal').modal("show").load(this.href); +}); + }) {% endblock %} diff --git a/expdj/apps/turk/urls.py b/expdj/apps/turk/urls.py index 1bdf124..73c84d8 100644 --- a/expdj/apps/turk/urls.py +++ b/expdj/apps/turk/urls.py @@ -1,6 +1,6 @@ -from expdj.apps.turk.views import edit_hit, delete_hit, expire_hit, preview_hit, \ -serve_hit, multiple_new_hit, end_assignment, finished_view, not_consent_view, \ -survey_submit, manage_hit +from expdj.apps.turk.views import (edit_hit, delete_hit, expire_hit, + preview_hit, serve_hit, multiple_new_hit, end_assignment, finished_view, + not_consent_view, survey_submit, manage_hit, contact_worker) from expdj.apps.experiments.views import sync from django.views.generic.base import TemplateView from django.conf.urls import patterns, url @@ -8,9 +8,21 @@ urlpatterns = patterns('', # HITS url(r'^hits/(?P\d+|[A-Z]{8})/new$',edit_hit,name='new_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/manage$',manage_hit,name='manage_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/multiple$',multiple_new_hit,name='multiple_new_hit'), - url(r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/edit$',edit_hit,name='edit_hit'), + url( + r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/manage$', + manage_hit, + name='manage_hit' + ), + url( + r'^hits/(?P\d+|[A-Z]{8})/multiple$', + multiple_new_hit, + name='multiple_new_hit' + ), + url( + r'^hits/(?P\d+|[A-Z]{8})/(?P\d+|[A-Z]{8})/edit$', + edit_hit, + name='edit_hit' + ), url(r'^hits/(?P\d+|[A-Z]{8})/delete$',delete_hit,name='delete_hit'), url(r'^hits/(?P\d+|[A-Z]{8})/expire$',expire_hit,name='expire_hit'), @@ -18,9 +30,18 @@ url(r'^accept/(?P\d+|[A-Z]{8})',serve_hit,name='serve_hit'), url(r'^turk/(?P\d+|[A-Z]{8})',preview_hit,name='preview_hit'), url(r'^turk/preview',not_consent_view,name='not_consent_view'), - url(r'^turk/end/(?P\d+|[A-Z]{8})',end_assignment,name='end_assignment'), - url(r'^surveys/(?P\d+|[A-Z]{8})/(?P[A-Za-z0-9]{30})/submit$',survey_submit,name='survey_submit'), + url( + r'^turk/end/(?P\d+|[A-Z]{8})', + end_assignment, + name='end_assignment' + ), + url( + r'^surveys/(?P\d+|[A-Z]{8})/(?P[A-Za-z0-9]{30})/submit$', + survey_submit, + name='survey_submit' + ), url(r'^sync/(?P\d+|[A-Z]{8})/$',sync,name='sync_data'), url(r'^sync/$',sync,name='sync_data'), - url(r'^finished$', finished_view, name="finished_view") + url(r'^finished$', finished_view, name="finished_view"), + url(r'^worker/contact/(?P\d+)',contact_worker,name='contact_worker') ) diff --git a/expdj/apps/turk/utils.py b/expdj/apps/turk/utils.py index 6ec8592..1f9b803 100644 --- a/expdj/apps/turk/utils.py +++ b/expdj/apps/turk/utils.py @@ -1,16 +1,19 @@ -from expdj.apps.experiments.models import Experiment -from boto.mturk.connection import MTurkConnection -from expdj.settings import BASE_DIR, MTURK_ALLOW -from boto.mturk.question import ExternalQuestion -from boto.mturk.price import Price import ConfigParser import datetime -import pandas import json import os +from boto.mturk.connection import MTurkConnection +from boto.mturk.price import Price +from boto.mturk.question import ExternalQuestion +import pandas + from django.conf import settings +from expdj.apps.experiments.models import Experiment +from expdj.settings import BASE_DIR, MTURK_ALLOW + + # RESULTS UTILS def to_dict(input_ordered_dict): @@ -132,3 +135,6 @@ def get_time_difference(d1,d2,format='%Y-%m-%d %H:%M:%S'): if isinstance(d2,str): d2 = datetime.datetime.strptime(d2, format) return (d2 - d1).total_seconds() / 60 + + + diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 9c6aae0..76d3e3e 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -15,15 +15,14 @@ from django.utils import timezone from django.views.decorators.csrf import ensure_csrf_cookie -from expdj.apps.experiments.models import (Assignment, Battery, - ExperimentTemplate) +from expdj.apps.experiments.models import (Battery, ExperimentTemplate) from expdj.apps.experiments.views import (check_battery_edit_permission, check_mturk_access, get_battery_intro, deploy_battery) from expdj.apps.experiments.utils import get_experiment_type, select_experiments from expdj.apps.turk.forms import HITForm, WorkerContactForm from expdj.apps.turk.models import Worker, HIT, Assignment, Result, get_worker from expdj.apps.turk.tasks import (assign_experiment_credit, - check_battery_dependencies, get_unique_experiments) + get_unique_experiments) from expdj.apps.turk.utils import (get_connection, get_host, get_worker_url, get_worker_experiments) from expdj.settings import BASE_DIR,STATIC_ROOT,MEDIA_ROOT From e6230ea264ff2d21a38a4e2c503371352d6e0762 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:49:37 -0700 Subject: [PATCH 28/40] fixed a couple sytax issues --- expdj/apps/turk/forms.py | 2 +- expdj/apps/turk/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/expdj/apps/turk/forms.py b/expdj/apps/turk/forms.py index d5674a3..4f7ccf3 100644 --- a/expdj/apps/turk/forms.py +++ b/expdj/apps/turk/forms.py @@ -37,6 +37,6 @@ class WorkerContactForm(forms.Form): message = forms.CharField(label="Message") def __init__(self, *args, **kwargs): - super(ContactForm, self).__init__(*args, **kwargs) + super(WorkerContactForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.add_input(Submit("submit", "Send")) diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 76d3e3e..4f2f722 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -347,7 +347,7 @@ def contact_worker(request, aid): if mturk_permission == False: return HttpResponseForbidden() - assignment = Assignments.objects.get(aid) + assignment = Assignment.objects.get(id=aid) if request.method == "GET": form = WorkerContactForm() worker = assignment.worker @@ -355,7 +355,7 @@ def contact_worker(request, aid): "form": form, "worker": worker } - return(request, "contact_worker_modal.html", context) + return render(request, "turk/contact_worker_modal.html", context) elif request.method == "POST": form = WorkerContactForm(request.POST) if form.is_valid(): From ded399923b2d845a58a23128c89a075ca79be3bc Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 15:51:36 -0700 Subject: [PATCH 29/40] forgot to pass request to manage_hit when redirecting in contact worker --- expdj/apps/turk/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/expdj/apps/turk/views.py b/expdj/apps/turk/views.py index 4f2f722..067014a 100644 --- a/expdj/apps/turk/views.py +++ b/expdj/apps/turk/views.py @@ -362,7 +362,8 @@ def contact_worker(request, aid): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] assignment.contact_worker(subject, message) - return manage_hit(assignment.hit.battery.id, assignment.hit.id) + return manage_hit(request, assignment.hit.battery.id, + assignment.hit.id) else: return HttpResponseNotAllowed() From e7ea322a0f34d64ef64084d27ce41943a0cb0cd7 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Sun, 3 Jul 2016 16:00:21 -0700 Subject: [PATCH 30/40] added missing form tags for contact worker modal --- expdj/apps/turk/templates/turk/contact_worker_modal.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expdj/apps/turk/templates/turk/contact_worker_modal.html b/expdj/apps/turk/templates/turk/contact_worker_modal.html index 8fdb15e..7d6f9ad 100644 --- a/expdj/apps/turk/templates/turk/contact_worker_modal.html +++ b/expdj/apps/turk/templates/turk/contact_worker_modal.html @@ -7,9 +7,9 @@