Commit a1914a88c73e903760680c425830e9bd87663011
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
validador.py
@@ -4,24 +4,26 @@ from werkzeug import secure_filename | @@ -4,24 +4,26 @@ from werkzeug import secure_filename | ||
4 | import pbclient | 4 | import pbclient |
5 | import os | 5 | import os |
6 | import pyutil | 6 | import pyutil |
7 | +import requests | ||
8 | +import tempfile | ||
7 | 9 | ||
8 | class Validador: | 10 | class Validador: |
9 | - | 11 | + |
10 | def __init__(self, configuration, template_env): | 12 | def __init__(self, configuration, template_env): |
11 | self.config = configuration | 13 | self.config = configuration |
12 | self.env = template_env | 14 | self.env = template_env |
13 | self.__setup_pb_client() | 15 | self.__setup_pb_client() |
14 | - | 16 | + |
15 | def __setup_pb_client(self): | 17 | def __setup_pb_client(self): |
16 | - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) | 18 | + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) |
17 | pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) | 19 | pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) |
18 | - | 20 | + |
19 | def __find_project(self, app_short_name): | 21 | def __find_project(self, app_short_name): |
20 | projects = pbclient.find_project(short_name=app_short_name) | 22 | projects = pbclient.find_project(short_name=app_short_name) |
21 | return projects[0] if len(projects) > 0 else None | 23 | return projects[0] if len(projects) > 0 else None |
22 | - | 24 | + |
23 | def __setup_project(self, project): | 25 | def __setup_project(self, project): |
24 | - self.__create_tasks(project) | 26 | + #self.__create_tasks(project) |
25 | self.__update_project_info(project) | 27 | self.__update_project_info(project) |
26 | 28 | ||
27 | def __create_tasks(self, project): | 29 | def __create_tasks(self, project): |
@@ -29,16 +31,16 @@ class Validador: | @@ -29,16 +31,16 @@ class Validador: | ||
29 | for sign in test_signs: | 31 | for sign in test_signs: |
30 | task = dict(sign_name=sign, submission_date=pyutil.get_date_now()) | 32 | task = dict(sign_name=sign, submission_date=pyutil.get_date_now()) |
31 | pbclient.create_task(project.id, task) | 33 | pbclient.create_task(project.id, task) |
32 | - | ||
33 | - def __update_project_info(self, project): | 34 | + |
35 | + def __update_project_info(self, project): | ||
34 | template = self.env.get_template('template.html') | 36 | template = self.env.get_template('template.html') |
35 | 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']) | 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 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" | 38 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
37 | project.info['sched'] = "incremental" | 39 | project.info['sched'] = "incremental" |
40 | + project.info['published'] = True | ||
38 | project.allow_anonymous_contributors = False | 41 | project.allow_anonymous_contributors = False |
39 | - #project.published = True | ||
40 | pbclient.update_project(project) | 42 | pbclient.update_project(project) |
41 | - | 43 | + |
42 | def create_project(self): | 44 | def create_project(self): |
43 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] | 45 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] |
44 | project = self.__find_project(app_short_name) | 46 | project = self.__find_project(app_short_name) |
@@ -50,30 +52,30 @@ class Validador: | @@ -50,30 +52,30 @@ class Validador: | ||
50 | if (project): | 52 | if (project): |
51 | self.__setup_project(project) | 53 | self.__setup_project(project) |
52 | result_msg = "The project " + app_short_name + " was created." | 54 | result_msg = "The project " + app_short_name + " was created." |
53 | - else: | 55 | + else: |
54 | result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details." | 56 | result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details." |
55 | pyutil.log(result_msg) | 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 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] | 61 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] |
60 | project = self.__find_project(app_short_name) | 62 | project = self.__find_project(app_short_name) |
61 | self.__update_project_info(project) | 63 | self.__update_project_info(project) |
62 | result_msg = "The project " + app_short_name + " was updated." | 64 | result_msg = "The project " + app_short_name + " was updated." |
63 | pyutil.log(result_msg) | 65 | pyutil.log(result_msg) |
64 | return result_msg | 66 | return result_msg |
65 | - | 67 | + |
66 | def __find_task(self, project_id, task_id): | 68 | def __find_task(self, project_id, task_id): |
67 | tasks = pbclient.find_tasks(project_id, id=task_id) | 69 | tasks = pbclient.find_tasks(project_id, id=task_id) |
68 | return tasks[0] if len(tasks) > 0 else None | 70 | return tasks[0] if len(tasks) > 0 else None |
69 | - | 71 | + |
70 | def __find_taskruns(self, project_id, task_id): | 72 | def __find_taskruns(self, project_id, task_id): |
71 | return pbclient.find_taskruns(project_id, id=task_id) | 73 | return pbclient.find_taskruns(project_id, id=task_id) |
72 | - | 74 | + |
73 | def __number_of_taskruns(self, project_id, task_id): | 75 | def __number_of_taskruns(self, project_id, task_id): |
74 | taskruns = self.__find_taskruns(project_id, task_id) | 76 | taskruns = self.__find_taskruns(project_id, task_id) |
75 | return len(taskruns) | 77 | return len(taskruns) |
76 | - | 78 | + |
77 | def __close_task(self, project_id, task_id): | 79 | def __close_task(self, project_id, task_id): |
78 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") | 80 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") |
79 | task = self.__find_task(project_id, task_id) | 81 | task = self.__find_task(project_id, task_id) |
@@ -81,19 +83,44 @@ class Validador: | @@ -81,19 +83,44 @@ class Validador: | ||
81 | task.n_answers = number_of_taskruns + 1 | 83 | task.n_answers = number_of_taskruns + 1 |
82 | pbclient.update_task(task) | 84 | pbclient.update_task(task) |
83 | return "The task with ID=" + str(task_id) + " was closed." | 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 | def finish_task(self): | 97 | def finish_task(self): |
86 | task_id = request.form['task_id'] | 98 | task_id = request.form['task_id'] |
87 | project_id = request.form['project_id'] | 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 | number_of_approval = int(request.form['number_of_approval']) | 103 | number_of_approval = int(request.form['number_of_approval']) |
89 | number_of_avatar_disapproval = int(request.form['number_of_avatar_disapproval']) | 104 | number_of_avatar_disapproval = int(request.form['number_of_avatar_disapproval']) |
90 | number_of_ref_disapproval = int(request.form['number_of_ref_disapproval']) | 105 | number_of_ref_disapproval = int(request.form['number_of_ref_disapproval']) |
91 | agreement_number = self.config['AGREEMENT_NUMBER'] | 106 | agreement_number = self.config['AGREEMENT_NUMBER'] |
92 | result_msg = "" | 107 | result_msg = "" |
93 | code = 200 | 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 | else: | 119 | else: |
97 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." | 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 | pyutil.log(result_msg) | 125 | pyutil.log(result_msg) |
99 | return make_response(result_msg, code) | 126 | return make_response(result_msg, code) |
view/template.html
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | tarefas disponíveis! </span> <br /> | 11 | tarefas disponíveis! </span> <br /> |
12 | <div class="alert-actions"> | 12 | <div class="alert-actions"> |
13 | <a class="btn small" href="/">Voltar</a> <a class="btn small" | 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 | </div> | 15 | </div> |
16 | </div> | 16 | </div> |
17 | </div> | 17 | </div> |