25 from google.appengine.api.labs import taskqueue |
25 from google.appengine.api.labs import taskqueue |
26 from google.appengine.ext import db |
26 from google.appengine.ext import db |
27 |
27 |
28 from django.http import HttpResponse |
28 from django.http import HttpResponse |
29 |
29 |
|
30 from soc.logic.models.mentor import logic as mentor_logic |
30 from soc.logic.models.program import logic as program_logic |
31 from soc.logic.models.program import logic as program_logic |
|
32 from soc.logic.models.org_admin import logic as org_admin_logic |
31 from soc.logic.models.organization import logic as org_logic |
33 from soc.logic.models.organization import logic as org_logic |
32 from soc.tasks.helper import decorators |
34 from soc.tasks.helper import decorators |
33 from soc.tasks.helper import error_handler |
35 from soc.tasks.helper import error_handler |
34 |
36 |
35 |
37 |
52 new_task.add() |
54 new_task.add() |
53 |
55 |
54 return True |
56 return True |
55 |
57 |
56 |
58 |
57 |
|
58 @decorators.iterative_task(program_logic) |
59 @decorators.iterative_task(program_logic) |
59 def runProgramConversionUpdate(request, entities, context, *args, **kwargs): |
60 def runProgramConversionUpdate(request, entities, context, *args, **kwargs): |
60 """Appengine Task that converts Programs into GSoCPrograms. |
61 """AppEngine Task that converts Programs into GSoCPrograms. |
61 |
62 |
62 Args: |
63 Args: |
63 request: Django Request object |
64 request: Django Request object |
64 entities: list of Program entities to convert |
65 entities: list of Program entities to convert |
65 context: the context of this task |
66 context: the context of this task |
93 return |
94 return |
94 |
95 |
95 |
96 |
96 @decorators.iterative_task(org_logic) |
97 @decorators.iterative_task(org_logic) |
97 def runOrgConversionUpdate(request, entities, context, *args, **kwargs): |
98 def runOrgConversionUpdate(request, entities, context, *args, **kwargs): |
98 """Appengine Task that converts Organizations into GSoCOrganizations. |
99 """AppEngine Task that converts Organizations into GSoCOrganizations. |
99 |
100 |
100 Args: |
101 Args: |
101 request: Django Request object |
102 request: Django Request object |
102 entities: list of Organization entities to convert |
103 entities: list of Organization entities to convert |
103 context: the context of this task |
104 context: the context of this task |
134 # store all the new GSoCOrganizations |
135 # store all the new GSoCOrganizations |
135 db.put(gsoc_orgs) |
136 db.put(gsoc_orgs) |
136 |
137 |
137 # task completed, return |
138 # task completed, return |
138 return |
139 return |
|
140 |
|
141 |
|
142 @decorators.iterative_task(org_admin_logic) |
|
143 def runOrgAdminConversionUpdate(request, entities, context, *args, **kwargs): |
|
144 """AppEngine Task that converts OrgAdmins into GSoCOrgAdmins. |
|
145 |
|
146 Args: |
|
147 request: Django Request object |
|
148 entities: list of OrgAdmin entities to convert |
|
149 context: the context of this task |
|
150 """ |
|
151 |
|
152 from soc.modules.gsoc.models.org_admin import GSoCOrgAdmin |
|
153 |
|
154 return _runOrgRoleConversionUpdate(entities, org_admin_logic, GSoCOrgAdmin) |
|
155 |
|
156 |
|
157 @decorators.iterative_task(mentor_logic) |
|
158 def runMentorConversionUpdate(request, entities, context, *args, **kwargs): |
|
159 """AppEngine Task that converts Mentors into GSoCMentors. |
|
160 |
|
161 Args: |
|
162 request: Django Request object |
|
163 entities: list of Mentor entities to convert |
|
164 context: the context of this task |
|
165 """ |
|
166 |
|
167 from soc.modules.gsoc.models.mentor import GSoCMentor |
|
168 |
|
169 return _runOrgRoleConversionUpdate(entities, mentor_logic, GSoCMentor) |
|
170 |
|
171 |
|
172 def _runOrgRoleConversionUpdate(entities, from_role_logic, to_role_model): |
|
173 """AppEngine Task that converts a normal Organization Role into a |
|
174 GSoCOrganization Role. |
|
175 |
|
176 Args: |
|
177 entities: Role entities to convert |
|
178 from_role_logic: the Role Logic instance where to convert from |
|
179 to_role_model: the role Model class where to convert to |
|
180 """ |
|
181 |
|
182 from soc.modules.gsoc.logic.models.organization import logic as \ |
|
183 gsoc_org_logic |
|
184 from soc.modules.gsoc.logic.models.program import logic as gsoc_program_logic |
|
185 |
|
186 # get all the properties that are part of each Organization's Role |
|
187 role_model = from_role_logic.getModel() |
|
188 role_properties = role_model.properties().keys() |
|
189 |
|
190 # use this to store all the new Roles |
|
191 gsoc_roles = [] |
|
192 |
|
193 for entity in entities: |
|
194 gsoc_properties = {} |
|
195 |
|
196 for role_property in role_properties: |
|
197 # copy over all the information from the Organization entity |
|
198 gsoc_properties[role_property] = getattr(entity, role_property) |
|
199 |
|
200 # get the Program key belonging to the old Role |
|
201 program_key = entity.program.key().id_or_name() |
|
202 # get the new GSoCProgram and set it for the Role |
|
203 gsoc_program = gsoc_program_logic.getFromKeyName(program_key) |
|
204 gsoc_properties['program'] = gsoc_program |
|
205 |
|
206 # get the Organization key belonging to the old Role |
|
207 org_key = entity.scope.key().id_or_name() |
|
208 # get the new GSoCOrganization and set it as scope for the Role |
|
209 gsoc_org = gsoc_org_logic.getFromKeyName(org_key) |
|
210 gsoc_properties['scope'] = gsoc_org |
|
211 |
|
212 # create the new GSoC Role entity and prepare it to be stored |
|
213 gsoc_role_entity = to_role_model(key_name=entity.key().name(), |
|
214 **gsoc_properties) |
|
215 gsoc_roles.append(gsoc_role_entity) |
|
216 |
|
217 # store all the new GSoC Roles |
|
218 db.put(gsoc_roles) |
|
219 |
|
220 # task completed, return |
|
221 return |
|
222 |