Exemple #1
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            UF_FORM = form.cleaned_data
            username = UF_FORM['user']
            password = UF_FORM['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return redirect('/eos')
                else:
                    return HttpResponse('Lockes account')
            else:
                return HttpResponse('Unknown user')
        else:
            return redirect('/eos/login')

    else:
        logger.info("Empty login form prepared from %s for user from %s, "
                    "session id %s" % (whoami(), get_client_ip(request), get_session_key(request)))
        form = LoginForm()
        return render_to_response("login.html", {'form': form, 'MEDIA_URL' : MEDIA_URL},
            context_instance=RequestContext(request))
Exemple #2
0
def eos_main(request):

    if request.method == 'POST':
        form = EosForm(request.POST, request.FILES)
        if form.is_valid():
            UF_FORM = form.cleaned_data
#        if 'X-Progress-ID' in request.GET:
#            request.session['X-Progress-ID'] = request.GET['X-Progress-ID']
            logger.info("Starting file  %s proccessing in %s for user from %s" % (request.FILES['xls_file'].name,
                                                                                  whoami(), get_client_ip(request)))
            fileattr = handle_xls_file(request.FILES['xls_file'], get_session_key(request) + '_' +
                                                                  request.FILES['xls_file'].name)
            if not fileattr == None:
                request.session['xlsfilepath'] = fileattr['filename']
                logger.info("Sucsessfully handeled file  %s in %s" % (request.FILES['xls_file'].name, whoami()))
                if UF_FORM['file_type'] == 'super_plan':
                    tarfile = prepare_global_plan(fileattr['filename'])
                    fsock = open(tarfile,"r")
                    response = HttpResponse(fsock, mimetype='application/zip')
                    response['Content-Disposition'] = 'attachment; filename=multiple_plans.zip'
#                    return HttpResponse('super_plan')
                    return response
                else:
                    request.session['eos_data'] = load_eos_from_xls_new(fileattr['filename'])
                    logger.error(request.session['eos_data'])
                    return redirect('/eos')
            else:
                logger.info("File type %s is not good, reported from %s" % (request.FILES['xls_file'].name, whoami()))
                return HttpResponse('Bad file type or file corrupted')

    else:
        logger.info("Empty upload form prepared from %s for user from %s, "
                "session id %s" % (whoami(), get_client_ip(request), get_session_key(request)))
        form = EosForm()
#        return render_to_response('confupload_form.html', {'form': form, 'MEDIA_URL' : MEDIA_URL},
#            context_instance=RequestContext(request))
        return render_to_response("new_start.html", {'form': form, 'MEDIA_URL' : MEDIA_URL,
                                                     'username' : request.user},
            context_instance=RequestContext(request))