def custom_export(request): # TODO: Check user user = User.objects.get(id=request.user.id) container_id = request.GET['container_id'] custom_id = request.GET['custom'] target = request.GET['target'] file_type = request.GET['file_type'] container = FinancialContainer.objects.get(id=container_id) if container.type.id==Attributes.objects.get(identifier='CONT_PORTFOLIO').id: container = PortfolioContainer.objects.get(id=container_id) else: container = SecurityContainer.objects.get(id=container_id) external = classes.my_import('external.' + custom_id) content = getattr(external, 'export_' + target)(container, getattr(external_content, 'get_' + custom_id + "_" + target)()[str(container.id)]) # TODO: handle mime-type if file_type=='excel': xlsx_mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' path = os.path.join(WORKING_PATH, custom_id + '_' + target + '_' + container.short_name + '.xlsx') content.save(path) with open(path,'rb') as f: content = f.read() response = HttpResponse(content,xlsx_mime) split_path = os.path.split(path) response['Content-Disposition'] = 'attachement; filename="' + split_path[len(split_path)-1] + '"' return response
def file_upload(request): file_name = os.path.join(WORKING_PATH,request.FILES['uploaded_file'].name) with open(file_name, 'wb+') as destination: for chunk in request.FILES['uploaded_file'].chunks(): destination.write(chunk) if request.POST.has_key('provider') and request.POST.has_key('action') and request.POST.has_key('step'): clazz = classes.my_import('external.' + request.POST['provider']) getattr(clazz, request.POST['action'] + '_' + request.POST['step'])(file_name) return HttpResponse('{"result": "OK"}',"json")
def object_type_callback(data): all_types = classes.my_import('containet.models.Attributes').objects.filter(active=True, type='object_type') for a_type in all_types: if data.has_key(a_type.identifier): context = Context({"selection": data[a_type.identifier]}) template = loader.get_template('rendition/object_type/lists/object_type_choices.html') rendition = template.render(context) # TODO Implement multi-langage outfile = os.path.join(STATICS_PATH, a_type.identifier + '_en.html') with open(outfile,'w') as o: o.write(rendition.encode('utf-8'))
def external_import(request): # TODO: Check user user = User.objects.get(id=request.user.id) external_provider = request.GET['external'] data_type = request.GET['target'] container_id = request.GET['container_id'] container_type = request.GET['container_type'] container_class = container_type + '_CLASS' # TODO: Handle error effective_class_name = Attributes.objects.get(identifier=container_class, active=True).name effective_class = classes.my_class_import(effective_class_name) container = effective_class.objects.get(id=container_id) external = classes.my_import('providers.' + external_provider) getattr(external, 'import_' + data_type)(container) return HttpResponse('{"result": true, "status_message": "Executed"}',"json")