Commit 7f857e40144c98bfb2708b99cec0d5a813cce5bf
1 parent
96bfe4ef
Exists in
master
Ajustes na interface para o lançamento.
Showing
5 changed files
with
61 additions
and
16 deletions
Show diff stats
.gitignore
bpy_checkout.py
@@ -15,9 +15,11 @@ def main(): | @@ -15,9 +15,11 @@ def main(): | ||
15 | sys.exit(4) | 15 | sys.exit(4) |
16 | action = None | 16 | action = None |
17 | for i in bpy.data.actions: | 17 | for i in bpy.data.actions: |
18 | - if (str(i.name.upper()) == str(action_name)): | ||
19 | - action = i | ||
20 | - break | 18 | + # ignore action name |
19 | + #if (str(i.name.upper()) == str(action_name)): | ||
20 | + # pass | ||
21 | + action = i | ||
22 | + break | ||
21 | if (action == None): | 23 | if (action == None): |
22 | sys.exit(5) | 24 | sys.exit(5) |
23 | if not (action_fake_is_valid): | 25 | if not (action_fake_is_valid): |
corretor.py
1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2 | + | ||
2 | from flask import request, make_response | 3 | from flask import request, make_response |
3 | from werkzeug import secure_filename | 4 | from werkzeug import secure_filename |
4 | import pbclient | 5 | import pbclient |
5 | import os | 6 | import os |
6 | import pyutil | 7 | import pyutil |
7 | import checkout | 8 | import checkout |
9 | +import requests | ||
10 | +import shutil | ||
11 | +import tempfile | ||
8 | 12 | ||
9 | class Corretor: | 13 | class Corretor: |
10 | 14 | ||
@@ -28,7 +32,10 @@ class Corretor: | @@ -28,7 +32,10 @@ class Corretor: | ||
28 | return projects[0] if len(projects) > 0 else None | 32 | return projects[0] if len(projects) > 0 else None |
29 | 33 | ||
30 | def __setup_project(self, project): | 34 | def __setup_project(self, project): |
31 | - self.__create_tasks(project) | 35 | + self.__update_project_info(project) |
36 | + | ||
37 | + def __setup_project(self, project): | ||
38 | + #self.__create_tasks(project) | ||
32 | self.__update_project_info(project) | 39 | self.__update_project_info(project) |
33 | 40 | ||
34 | def __create_tasks(self, project): | 41 | def __create_tasks(self, project): |
@@ -42,21 +49,21 @@ class Corretor: | @@ -42,21 +49,21 @@ class Corretor: | ||
42 | 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']) | 49 | 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']) |
43 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" | 50 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
44 | project.info['sched'] = "incremental" | 51 | project.info['sched'] = "incremental" |
52 | + project.info['published'] = True | ||
45 | project.allow_anonymous_contributors = False | 53 | project.allow_anonymous_contributors = False |
46 | - #project.published = True | ||
47 | pbclient.update_project(project) | 54 | pbclient.update_project(project) |
48 | 55 | ||
49 | def __find_task(self, project_id, task_id): | 56 | def __find_task(self, project_id, task_id): |
50 | tasks = pbclient.find_tasks(project_id, id=task_id) | 57 | tasks = pbclient.find_tasks(project_id, id=task_id) |
51 | return tasks[0] if len(tasks) > 0 else None | 58 | return tasks[0] if len(tasks) > 0 else None |
52 | - | 59 | + |
53 | def __find_taskruns(self, project_id, task_id): | 60 | def __find_taskruns(self, project_id, task_id): |
54 | return pbclient.find_taskruns(project_id, id=task_id) | 61 | return pbclient.find_taskruns(project_id, id=task_id) |
55 | - | 62 | + |
56 | def __number_of_taskruns(self, project_id, task_id): | 63 | def __number_of_taskruns(self, project_id, task_id): |
57 | taskruns = self.__find_taskruns(project_id, task_id) | 64 | taskruns = self.__find_taskruns(project_id, task_id) |
58 | return len(taskruns) | 65 | return len(taskruns) |
59 | - | 66 | + |
60 | def __close_task(self, project_id, task_id): | 67 | def __close_task(self, project_id, task_id): |
61 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") | 68 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") |
62 | task = self.__find_task(project_id, task_id) | 69 | task = self.__find_task(project_id, task_id) |
@@ -66,19 +73,42 @@ class Corretor: | @@ -66,19 +73,42 @@ class Corretor: | ||
66 | return "The task with ID=" + str(task_id) + " was closed." | 73 | return "The task with ID=" + str(task_id) + " was closed." |
67 | 74 | ||
68 | def finish_task(self): | 75 | def finish_task(self): |
76 | + user_id = request.form['upload_session_id'] | ||
77 | + pyutil.log(str(user_id)) | ||
69 | task_id = request.form['task_id'] | 78 | task_id = request.form['task_id'] |
79 | + api_host = self.config['SERVER_HOST'] | ||
80 | + api_dbhost = self.config['API_DB_HOST'] | ||
81 | + sign_name = request.form['sign_name'] | ||
70 | project_id = request.form['project_id'] | 82 | project_id = request.form['project_id'] |
71 | number_of_approval = int(request.form['number_of_approval']) | 83 | number_of_approval = int(request.form['number_of_approval']) |
72 | agreement_number = self.config['AGREEMENT_NUMBER'] | 84 | agreement_number = self.config['AGREEMENT_NUMBER'] |
73 | result_msg = "" | 85 | result_msg = "" |
74 | code = 200 | 86 | code = 200 |
75 | if (number_of_approval >= agreement_number): | 87 | if (number_of_approval >= agreement_number): |
88 | + tmp_dir = tempfile.NamedTemporaryFile().name | ||
89 | + if not os.path.exists(tmp_dir): | ||
90 | + os.makedirs(tmp_dir) | ||
91 | + blend_path = os.path.join(tmp_dir, sign_name + ".blend") | ||
92 | + video_path = os.path.join(tmp_dir, sign_name + ".webm") | ||
93 | + blend_url = ('http://%s/corretor/uploads/%s/%s.blend' % (api_host, user_id, sign_name)) | ||
94 | + video_url = ('http://%s/corretor/uploads/%s/%s.webm' % (api_host, user_id, sign_name)) | ||
95 | + blend_downloaded = self.get_file(blend_url, blend_path) | ||
96 | + video_downloaded = self.get_file(video_url, video_path) | ||
97 | + if (blend_downloaded and video_downloaded): | ||
98 | + files_to_upload = [ ("video", (video_path, open(video_path,"rb"))), ("video", (blend_path, open(blend_path, "rb"))) ] | ||
99 | + values = { "nome": sign_name, "selo": 5, "wikilibras": True, "overwrite": True } | ||
100 | + r = requests.post(("%s/addsinal" % (api_dbhost)), files=files_to_upload, data=values) | ||
101 | + pyutil.log("Request: " + str(r)) | ||
102 | + pyutil.log(str(r.headers)) | ||
103 | + shutil.rmtree(tmp_dir) | ||
104 | + else: | ||
105 | + pyutil.log("files: %s or %s was not downloaded" % (blend_url, video_url)) | ||
76 | result_msg = self.__close_task(project_id, task_id) | 106 | result_msg = self.__close_task(project_id, task_id) |
77 | else: | 107 | else: |
78 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." | 108 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." |
79 | pyutil.log(result_msg) | 109 | pyutil.log(result_msg) |
80 | return make_response(result_msg, code) | 110 | return make_response(result_msg, code) |
81 | - | 111 | + |
82 | def render_video(self): | 112 | def render_video(self): |
83 | upload_session_id = request.form['upload_session_id'] | 113 | upload_session_id = request.form['upload_session_id'] |
84 | sign_name = request.form['sign_name'] | 114 | sign_name = request.form['sign_name'] |
@@ -125,6 +155,16 @@ class Corretor: | @@ -125,6 +155,16 @@ class Corretor: | ||
125 | allowed_extensions = set(['blend']) | 155 | allowed_extensions = set(['blend']) |
126 | return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions | 156 | return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions |
127 | 157 | ||
158 | + def get_file(self, url, filename): | ||
159 | + r = requests.get(url, stream = True) | ||
160 | + if (r.status_code == 200): | ||
161 | + with open(filename, 'wb') as f: | ||
162 | + for chunk in r.iter_content(chunk_size = 1024): | ||
163 | + if chunk: | ||
164 | + f.write(chunk) | ||
165 | + return True | ||
166 | + return False | ||
167 | + | ||
128 | def upload_file(self): | 168 | def upload_file(self): |
129 | upload_session_id = request.form['upload_session_id'] | 169 | upload_session_id = request.form['upload_session_id'] |
130 | sign_name = request.form['sign_name'] | 170 | sign_name = request.form['sign_name'] |
requirements.txt
view/template.html
@@ -19,13 +19,13 @@ | @@ -19,13 +19,13 @@ | ||
19 | tarefas disponíveis! </span> <br /> | 19 | tarefas disponíveis! </span> <br /> |
20 | <div class="alert-actions"> | 20 | <div class="alert-actions"> |
21 | <a class="btn small" href="/">Voltar</a> <a class="btn small" | 21 | <a class="btn small" href="/">Voltar</a> <a class="btn small" |
22 | - href="/project">ou, olhar outros projetos.</a> | 22 | + href="/pybossa/project">ou, olhar outros projetos.</a> |
23 | </div> | 23 | </div> |
24 | </div> | 24 | </div> |
25 | </div> | 25 | </div> |
26 | 26 | ||
27 | <div id="main-container" class="container"> | 27 | <div id="main-container" class="container"> |
28 | - <div id="corretor-header"> | 28 | + <!--div id="corretor-header"> |
29 | <table id="table-1" class="table-responsive borderless"> | 29 | <table id="table-1" class="table-responsive borderless"> |
30 | <thead"> | 30 | <thead"> |
31 | <tr> | 31 | <tr> |
@@ -47,7 +47,7 @@ | @@ -47,7 +47,7 @@ | ||
47 | </tbody> | 47 | </tbody> |
48 | </table> | 48 | </table> |
49 | </div> | 49 | </div> |
50 | - <div class="line-separator"></div> | 50 | + <div class="line-separator"></div--> |
51 | <div id="corretor-container" class="row body-container"> | 51 | <div id="corretor-container" class="row body-container"> |
52 | <div id="avatar-container" class="col-sm-6 video-container"> | 52 | <div id="avatar-container" class="col-sm-6 video-container"> |
53 | <div class="row"> | 53 | <div class="row"> |