@@ -170,6 +170,34 class Campaign(models.Model): | |||
|
170 | 170 | |
|
171 | 171 | return parms |
|
172 | 172 | |
|
173 | def dict_to_parms(self, parms, CONF_MODELS): | |
|
174 | ||
|
175 | experiments = Experiment.objects.filter(campaign = self) | |
|
176 | configurations = Configuration.objects.filter(experiment = experiments) | |
|
177 | ||
|
178 | if configurations: | |
|
179 | for configuration in configurations: | |
|
180 | configuration.delete() | |
|
181 | ||
|
182 | if experiments: | |
|
183 | for experiment in experiments: | |
|
184 | experiment.delete() | |
|
185 | ||
|
186 | for parms_exp in parms['experiments']: | |
|
187 | location = Location.objects.get(name = parms['experiments'][parms_exp]['radar']) | |
|
188 | new_exp = Experiment( | |
|
189 | name = parms['experiments'][parms_exp]['experiment'], | |
|
190 | location = location, | |
|
191 | start_time = parms['experiments'][parms_exp]['start_time'], | |
|
192 | end_time = parms['experiments'][parms_exp]['end_time'], | |
|
193 | ) | |
|
194 | new_exp.save() | |
|
195 | new_exp.dict_to_parms(parms['experiments'][parms_exp],CONF_MODELS) | |
|
196 | new_exp.save() | |
|
197 | ||
|
198 | self.experiments.add(new_exp) | |
|
199 | self.save() | |
|
200 | ||
|
173 | 201 | def get_absolute_url(self): |
|
174 | 202 | return reverse('url_campaign', args=[str(self.id)]) |
|
175 | 203 | |
@@ -318,11 +346,6 class Experiment(models.Model): | |||
|
318 | 346 | |
|
319 | 347 | def dict_to_parms(self, parms, CONF_MODELS): |
|
320 | 348 | |
|
321 | #self.name = parameters['experiment'] | |
|
322 | #self.location = parameters['radar'] | |
|
323 | #self.start_time = parameters['start_time'] | |
|
324 | #self.end_time = parameters['end_time'] | |
|
325 | ||
|
326 | 349 | configurations = Configuration.objects.filter(experiment=self) |
|
327 | 350 | |
|
328 | 351 | if configurations: |
@@ -428,10 +428,8 def campaign_export(request, id_camp): | |||
|
428 | 428 | |
|
429 | 429 | |
|
430 | 430 | def campaign_import(request, id_camp): |
|
431 | ###------FALTA CORREGIR!!!!!-----### | |
|
431 | ||
|
432 | 432 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
433 | experiments = Experiment.objects.filter(campaign=campaign) | |
|
434 | configurations = Configuration.objects.filter(experiment=experiments) | |
|
435 | 433 | |
|
436 | 434 | if request.method == 'GET': |
|
437 | 435 | file_form = UploadFileForm() |
@@ -444,9 +442,7 def campaign_import(request, id_camp): | |||
|
444 | 442 | parms = campaign.import_from_file(request.FILES['file']) |
|
445 | 443 | |
|
446 | 444 | if parms: |
|
447 |
|
|
|
448 | parms['location'] = location.id | |
|
449 | parms['name'] = parms['experiment'] | |
|
445 | parms['name'] = parms['campaign'] | |
|
450 | 446 | |
|
451 | 447 | campaign.dict_to_parms(parms, CONF_MODELS) |
|
452 | 448 | |
@@ -455,32 +451,24 def campaign_import(request, id_camp): | |||
|
455 | 451 | form = CampaignForm(initial=parms, instance=campaign) |
|
456 | 452 | |
|
457 | 453 | kwargs = {} |
|
458 | #kwargs['id_dev'] = conf.id | |
|
459 | 454 | kwargs['form'] = form |
|
460 | 455 | kwargs['title'] = 'Campaign' |
|
461 | 456 | kwargs['suptitle'] = 'Parameters imported' |
|
462 | 457 | kwargs['button'] = 'Save' |
|
463 | 458 | kwargs['action'] = campaign.get_absolute_url_edit() |
|
464 | 459 | kwargs['previous'] = campaign.get_absolute_url() |
|
465 | ||
|
466 | ||
|
467 | ###### SIDEBAR ###### | |
|
468 | #kwargs.update(sidebar(conf=conf)) | |
|
469 | #kwargs.update(sidebar(campaign=campaign)) | |
|
470 | 460 | |
|
471 | 461 | return render(request, 'campaign_edit.html', kwargs) |
|
462 | ||
|
472 | 463 | |
|
473 | 464 | messages.error(request, "Could not import parameters from file") |
|
474 | 465 | |
|
475 | 466 | kwargs = {} |
|
476 | #kwargs['id_dev'] = conf.id | |
|
477 | 467 | kwargs['title'] = 'Campaign' |
|
478 | 468 | kwargs['form'] = file_form |
|
479 | 469 | kwargs['suptitle'] = 'Importing file' |
|
480 | 470 | kwargs['button'] = 'Import' |
|
481 | 471 | |
|
482 | #kwargs.update(sidebar(campaign=campaign)) | |
|
483 | ||
|
484 | 472 | return render(request, 'campaign_import.html', kwargs) |
|
485 | 473 | |
|
486 | 474 |
General Comments 0
You need to be logged in to leave comments.
Login now