def attach_save(request, object_id = None, client_id = None): referral = get_object_or_404(Referral, pk=object_id, service__organization=request.user.get_profile().org_active) if not _access_check_referral_write(request, referral): return render_to_response('403.html', {'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request)) if request.method == 'POST': user = request.user filename = '' if 'file' in request.FILES: path = '%s/img/organization/%s' % (MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) path = '%s/img/organization/%s/attach' % (MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) try: filename = request.FILES['file'] file = str(uuid.uuid4()) + '.'+ (str(filename).split('.')[-1]) destination = open('%s/%s' % (path, file), 'w+') for chunk in filename.chunks(): destination.write(chunk) destination.close() attachs = ReferralAttach.objects.filter(referral = object_id, referral__service__organization=request.user.get_profile().org_active) attach = ReferralAttach() attach.filename = '%s' % request.FILES['file'] attach.file = '%s' % file attach.description = request.POST.get('description') attach.type = request.POST.get('doc_type') attach.only_professionals = True if request.POST.get('onlyprofessionals') == 'True' else False attach.only_psychologists = True if request.POST.get('onlypsychologists') == 'True' else False attach.referral = Referral.objects.get(pk = object_id, service__organization=request.user.get_profile().org_active) attach.save() except IOError: print "error sending file" return HttpResponseRedirect('/upload/client/%s/attach/%s/' % (client_id, object_id))
def attach_save(request, referral_id=None, object_id=None, attach_id=None): ''' object_id : Person.id referra_id : Referral.id attach_id : ReferralAttach.id ''' # html variables referral = get_object_or_404( Referral, pk=referral_id, service__organization=request.user.get_profile().org_active) types = REFERRAL_ATTACH_TYPE # update if attach_id: attach = ReferralAttach.objects.get( pk=attach_id, referral=referral_id, referral__service__organization=request.user.get_profile( ).org_active) if not _access_check_referral_write(request, referral): return render_to_response( '403.html', { 'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request)) if request.method == 'POST': user = request.user # new attach if not attach_id: filename = '' if 'file' in request.FILES: path = '%s/img/organization/%s' % ( MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) path = '%s/img/organization/%s/attach' % ( MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) try: filename = request.FILES['file'] file = str( uuid.uuid4()) + '.' + (str(filename).split('.')[-1]) destination = open('%s/%s' % (path, file), 'w+') for chunk in filename.chunks(): destination.write(chunk) destination.close() attach = ReferralAttach() attach.filename = '%s' % request.FILES['file'] attach.file = '%s' % file attach.description = request.POST.get('description') attach.type = request.POST.get('doc_type') attach.permission = request.POST.get('permission') attach.referral = Referral.objects.get( pk=referral_id, service__organization=request.user.get_profile( ).org_active) attach.save() except IOError: print "error sending file" # update else: attach.description = request.POST.get('description') attach.type = request.POST.get('doc_type') attach.permission = request.POST.get('permission') attach.save() messages.success(request, _('Documento salvo com sucesso!')) return HttpResponseRedirect('/upload/client/%s/referral/%s/' % (object_id, referral_id))
def attach_save(request, referral_id=None, object_id=None, attach_id=None): ''' object_id : Person.id referra_id : Referral.id attach_id : ReferralAttach.id ''' # html variables referral = get_object_or_404(Referral, pk=referral_id, service__organization=request.user.get_profile().org_active) types = REFERRAL_ATTACH_TYPE # update if attach_id: attach = ReferralAttach.objects.get( pk=attach_id, referral=referral_id, referral__service__organization=request.user.get_profile().org_active ) if not _access_check_referral_write(request, referral): return render_to_response('403.html', {'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request)) if request.method == 'POST': user = request.user # new attach if not attach_id : filename = '' if 'file' in request.FILES: path = '%s/img/organization/%s' % (MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) path = '%s/img/organization/%s/attach' % (MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) try: filename = request.FILES['file'] file = str(uuid.uuid4()) + '.'+ (str(filename).split('.')[-1]) destination = open('%s/%s' % (path, file), 'w+') for chunk in filename.chunks(): destination.write(chunk) destination.close() attach = ReferralAttach() attach.filename = '%s' % request.FILES['file'] attach.file = '%s' % file attach.description = request.POST.get('description') attach.type = request.POST.get('doc_type') attach.permission = request.POST.get('permission') attach.referral = Referral.objects.get(pk=referral_id, service__organization=request.user.get_profile().org_active) attach.save() except IOError: print "error sending file" # update else: attach.description = request.POST.get('description') attach.type = request.POST.get('doc_type') attach.permission = request.POST.get('permission') attach.save() messages.success(request, _('Documento salvo com sucesso!')) return HttpResponseRedirect('/upload/client/%s/referral/%s/' % (object_id, referral_id) )
def attach_save(request, object_id=None, client_id=None): referral = get_object_or_404( Referral, pk=object_id, service__organization=request.user.get_profile().org_active) if not _access_check_referral_write(request, referral): return render_to_response( '403.html', { 'object': _("Oops! You don't have access for this service!"), }, context_instance=RequestContext(request)) if request.method == 'POST': user = request.user filename = '' if 'file' in request.FILES: path = '%s/img/organization/%s' % ( MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) path = '%s/img/organization/%s/attach' % ( MEDIA_ROOT, user.get_profile().org_active.id) if not os.path.exists(path): os.mkdir(path) os.chmod(path, 0777) try: filename = request.FILES['file'] file = str(uuid.uuid4()) + '.' + (str(filename).split('.')[-1]) destination = open('%s/%s' % (path, file), 'w+') for chunk in filename.chunks(): destination.write(chunk) destination.close() attachs = ReferralAttach.objects.filter( referral=object_id, referral__service__organization=request.user.get_profile( ).org_active) attach = ReferralAttach() attach.filename = '%s' % request.FILES['file'] attach.file = '%s' % file attach.description = request.POST.get('description') attach.type = request.POST.get('doc_type') attach.only_professionals = True if request.POST.get( 'onlyprofessionals') == 'True' else False attach.only_psychologists = True if request.POST.get( 'onlypsychologists') == 'True' else False attach.referral = Referral.objects.get( pk=object_id, service__organization=request.user.get_profile( ).org_active) attach.save() except IOError: print "error sending file" return HttpResponseRedirect('/upload/client/%s/attach/%s/' % (client_id, object_id))