Commit a1914a88c73e903760680c425830e9bd87663011

Authored by wikilibras
1 parent e5da1b94
Exists in master

Ajustes na interface para o lançamento.

Showing 3 changed files with 52 additions and 22 deletions   Show diff stats
.gitignore
1 1 .*
2   -*~
3 2 !.gitignore
4 3 !.gitempty
  4 +*~
5 5 *.log
6 6 *.pyc
  7 +validador.conf
  8 +validador.wsgi
7 9 settings_local.py
8 10 env/
  11 +videos/
9 12 tmp/
... ...
validador.py
... ... @@ -4,24 +4,26 @@ from werkzeug import secure_filename
4 4 import pbclient
5 5 import os
6 6 import pyutil
  7 +import requests
  8 +import tempfile
7 9  
8 10 class Validador:
9   -
  11 +
10 12 def __init__(self, configuration, template_env):
11 13 self.config = configuration
12 14 self.env = template_env
13 15 self.__setup_pb_client()
14   -
  16 +
15 17 def __setup_pb_client(self):
16   - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
  18 + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
17 19 pbclient.set('api_key', self.config['PYBOSSA_API_KEY'])
18   -
  20 +
19 21 def __find_project(self, app_short_name):
20 22 projects = pbclient.find_project(short_name=app_short_name)
21 23 return projects[0] if len(projects) > 0 else None
22   -
  24 +
23 25 def __setup_project(self, project):
24   - self.__create_tasks(project)
  26 + #self.__create_tasks(project)
25 27 self.__update_project_info(project)
26 28  
27 29 def __create_tasks(self, project):
... ... @@ -29,16 +31,16 @@ class Validador:
29 31 for sign in test_signs:
30 32 task = dict(sign_name=sign, submission_date=pyutil.get_date_now())
31 33 pbclient.create_task(project.id, task)
32   -
33   - def __update_project_info(self, project):
  34 +
  35 + def __update_project_info(self, project):
34 36 template = self.env.get_template('template.html')
35 37 project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'])
36 38 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png"
37 39 project.info['sched'] = "incremental"
  40 + project.info['published'] = True
38 41 project.allow_anonymous_contributors = False
39   - #project.published = True
40 42 pbclient.update_project(project)
41   -
  43 +
42 44 def create_project(self):
43 45 app_short_name = self.config['PYBOSSA_APP_SHORT_NAME']
44 46 project = self.__find_project(app_short_name)
... ... @@ -50,30 +52,30 @@ class Validador:
50 52 if (project):
51 53 self.__setup_project(project)
52 54 result_msg = "The project " + app_short_name + " was created."
53   - else:
  55 + else:
54 56 result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details."
55 57 pyutil.log(result_msg)
56   - return result_msg
  58 + return result_msg
57 59  
58   - def update_project(self):
  60 + def update_project(self):
59 61 app_short_name = self.config['PYBOSSA_APP_SHORT_NAME']
60 62 project = self.__find_project(app_short_name)
61 63 self.__update_project_info(project)
62 64 result_msg = "The project " + app_short_name + " was updated."
63 65 pyutil.log(result_msg)
64 66 return result_msg
65   -
  67 +
66 68 def __find_task(self, project_id, task_id):
67 69 tasks = pbclient.find_tasks(project_id, id=task_id)
68 70 return tasks[0] if len(tasks) > 0 else None
69   -
  71 +
70 72 def __find_taskruns(self, project_id, task_id):
71 73 return pbclient.find_taskruns(project_id, id=task_id)
72   -
  74 +
73 75 def __number_of_taskruns(self, project_id, task_id):
74 76 taskruns = self.__find_taskruns(project_id, task_id)
75 77 return len(taskruns)
76   -
  78 +
77 79 def __close_task(self, project_id, task_id):
78 80 pyutil.log("Closing the task with ID=" + str(task_id) + ".")
79 81 task = self.__find_task(project_id, task_id)
... ... @@ -81,19 +83,44 @@ class Validador:
81 83 task.n_answers = number_of_taskruns + 1
82 84 pbclient.update_task(task)
83 85 return "The task with ID=" + str(task_id) + " was closed."
84   -
  86 +
  87 + def get_file(self, url, filename):
  88 + r = requests.get(url, stream = True)
  89 + if (r.status_code == 200):
  90 + with open(filename, 'wb') as f:
  91 + for chunk in r.iter_content(chunk_size = 1024):
  92 + if chunk:
  93 + f.write(chunk)
  94 + return True
  95 + return False
  96 +
85 97 def finish_task(self):
86 98 task_id = request.form['task_id']
87 99 project_id = request.form['project_id']
  100 + sign_name = request.form['sign_name']
  101 + api_host = self.config['API_HOST']
  102 + api_dbhost = self.config['API_DB_HOST']
88 103 number_of_approval = int(request.form['number_of_approval'])
89 104 number_of_avatar_disapproval = int(request.form['number_of_avatar_disapproval'])
90 105 number_of_ref_disapproval = int(request.form['number_of_ref_disapproval'])
91 106 agreement_number = self.config['AGREEMENT_NUMBER']
92 107 result_msg = ""
93 108 code = 200
94   - if (number_of_approval >= agreement_number or number_of_avatar_disapproval >= agreement_number or number_of_ref_disapproval >= agreement_number):
95   - result_msg = self.__close_task(project_id, task_id)
  109 + selo = None
  110 + if (number_of_approval >= agreement_number):
  111 + selo = 2
  112 + result_msg = "selo was changed to 2 - especialista"
  113 + elif(number_of_avatar_disapproval >= agreement_number):
  114 + selo = 4
  115 + result_msg = "selo was changed to 4 - invalido_especialista"
  116 + elif(number_of_ref_disapproval >= agreement_number):
  117 + selo = 6
  118 + result_msg = "selo was changed to 6 - invalido_animadores"
96 119 else:
97 120 result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet."
  121 + if (selo != None):
  122 + values = { "nome": sign_name, "selo": selo, "wikilibras": True, "overwrite": True }
  123 + r = requests.post(("%s/gsinal" % (api_dbhost)), data = values)
  124 + result_msg = self.__close_task(project_id, task_id)
98 125 pyutil.log(result_msg)
99 126 return make_response(result_msg, code)
... ...
view/template.html
... ... @@ -11,7 +11,7 @@
11 11 tarefas disponíveis! </span> <br />
12 12 <div class="alert-actions">
13 13 <a class="btn small" href="/">Voltar</a> <a class="btn small"
14   - href="/project">ou, olhar outros projetos.</a>
  14 + href="/pybossa/project">ou, olhar outros projetos.</a>
15 15 </div>
16 16 </div>
17 17 </div>
... ...