Esempio n. 1
0
File: views.py Progetto: CN-P5/PiBox
def register_view(request):  
    pisettings_instance = globaldata.getclient()
    if pisettings_instance.enable_register != True:
        return HttpResponse("You are not be allowed to register") 
    form = PiRegisterForm(request.POST or None)
    if form.is_valid():
        first_name=form.cleaned_data['first_name']
        last_name=form.cleaned_data['last_name']      
        email = form.cleaned_data['email'] 
        password=form.cleaned_data['password1']        
        try:
            user = PiUser.objects.create_user(email, email, password)    
            if user is not None:  
                user.first_name =  first_name
                user.last_name = last_name
                user.is_staff = True  
                user.save()  
                user = authenticate(username=email, password=password)
                login(request, user)    
                ret = 'Ok'
                t = get_template('register_return.html')
                c = RequestContext(request,locals())
                return HttpResponse(t.render(c))
        except:  
            ret = 'Fail'
            t = get_template('register_return.html')
            c = RequestContext(request,locals())
            return HttpResponse(t.render(c))
    else:
        t = get_template('register.html')
        c = RequestContext(request,locals())
        return HttpResponse(t.render(c))  
Esempio n. 2
0
File: views.py Progetto: CN-P5/PiBox
def dashboard(request, title='dashboard', belong=None):
    pisettings_instance = globaldata.getclient()
    user_count = PiUser.objects.count()   
    device_count = Device.objects.count()   
    if(client.socket_test(pisettings_instance.ip,  pisettings_instance.port)):
        connection = "True"
    else:
        connection = "False"

    applist = globaldata.pci_list.applist()
    app_num = len(applist)
    media_root = settings.MEDIA_ROOT
    DEVICE = Device.objects.all()
    try:
        home_instance = Home.objects.get(id =1)
        home_exist = True
    except:
        home_exist = False

    #logfile
    pihome_log_file = open(globaldata.BASE_DIR + '/log/pihome.log', 'r')
    pihome_log_lines = pihome_log_file.readlines()
    pihome_log = utils.lineslimit(pihome_log_lines, 100)
    cpp_log_file = open(globaldata.BASE_DIR + '/log/pihome.log', 'r')
    cpp_log_lines = cpp_log_file.readlines()
    cpp_log = utils.lineslimit(cpp_log_lines, 100)

    t = get_template('dashboard/dashboard.html')
    c = RequestContext(request,locals())
    return HttpResponse(t.render(c))
Esempio n. 3
0
File: views.py Progetto: zppan/PiBox
def register_view(request):
    pisettings_instance = globaldata.getclient()
    if pisettings_instance.enable_register != True:
        return HttpResponse("You are not be allowed to register")
    form = PiRegisterForm(request.POST or None)
    if form.is_valid():
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        password = form.cleaned_data['password1']
        try:
            user = PiUser.objects.create_user(email, email, password)
            if user is not None:
                user.first_name = first_name
                user.last_name = last_name
                user.is_staff = True
                user.save()
                user = authenticate(username=email, password=password)
                login(request, user)
                ret = 'Ok'
                t = get_template('register_return.html')
                c = RequestContext(request, locals())
                return HttpResponse(t.render(c))
        except:
            ret = 'Fail'
            t = get_template('register_return.html')
            c = RequestContext(request, locals())
            return HttpResponse(t.render(c))
    else:
        t = get_template('register.html')
        c = RequestContext(request, locals())
        return HttpResponse(t.render(c))
Esempio n. 4
0
File: views.py Progetto: zppan/PiBox
def dashboard(request, title='dashboard', belong=None):
    pisettings_instance = globaldata.getclient()
    user_count = PiUser.objects.count()
    device_count = Device.objects.count()
    if (client.socket_test(pisettings_instance.ip, pisettings_instance.port)):
        connection = "True"
    else:
        connection = "False"

    applist = globaldata.pci_list.applist()
    app_num = len(applist)
    media_root = settings.MEDIA_ROOT
    DEVICE = Device.objects.all()
    try:
        home_instance = Home.objects.get(id=1)
        home_exist = True
    except:
        home_exist = False

    #logfile
    pihome_log_file = open(globaldata.BASE_DIR + '/log/pihome.log', 'r')
    pihome_log_lines = pihome_log_file.readlines()
    pihome_log = utils.lineslimit(pihome_log_lines, 100)
    cpp_log_file = open(globaldata.BASE_DIR + '/log/pihome.log', 'r')
    cpp_log_lines = cpp_log_file.readlines()
    cpp_log = utils.lineslimit(cpp_log_lines, 100)

    t = get_template('dashboard/dashboard.html')
    c = RequestContext(request, locals())
    return HttpResponse(t.render(c))
Esempio n. 5
0
def settings_general_api(request):
    pisettings_instance = globaldata.getclient()
    form = PiSettingsForm(request.POST or None, instance=pisettings_instance)
    if form.is_valid():
        form.save()
        form = PiSettingsForm(instance=pisettings_instance)
    t = get_template('settings/api_general.html')
    c = RequestContext(request, locals())
    return HttpResponse(t.render(c))
Esempio n. 6
0
File: api.py Progetto: CN-P5/PiBox
def settings_general_api(request):
    pisettings_instance = globaldata.getclient()
    form = PiSettingsForm(request.POST or None, instance = pisettings_instance)
    if form.is_valid():
        form.save()
        form = PiSettingsForm(instance = pisettings_instance)
    t = get_template('settings/api_general.html')
    c = RequestContext(request,locals())
    return HttpResponse(t.render(c))
Esempio n. 7
0
File: views.py Progetto: CN-P5/PiBox
def  status_default_view(request, title='default', belong=['status']):
    pisettings_instance = globaldata.getclient()

    message = { "title" : "status"}
    message['cmd'] = 'get';

    pi_ret = client.socketjson_send_recv(pisettings_instance.ip,  pisettings_instance.port, message)

    t = get_template('status/default.html')
    c = RequestContext(request,locals())
    return HttpResponse(t.render(c))
Esempio n. 8
0
File: views.py Progetto: zppan/PiBox
def status_default_view(request, title='default', belong=['status']):
    pisettings_instance = globaldata.getclient()

    message = {"title": "status"}
    message['cmd'] = 'get'

    pi_ret = client.socketjson_send_recv(pisettings_instance.ip,
                                         pisettings_instance.port, message)

    t = get_template('status/default.html')
    c = RequestContext(request, locals())
    return HttpResponse(t.render(c))
Esempio n. 9
0
def dashboard_api(request):
    pisettings_instance = globaldata.getclient()

    pi_ret = {'nas': globaldata.NasEnable}
    if (client.socket_test(pisettings_instance.ip, pisettings_instance.port)):
        pi_ret['connection'] = "TRUE"
    else:
        pi_ret['connection'] = "FALSE"
    pi_ret['app_num'] = len(globaldata.AppList)

    pi_ret['user_count'] = PiUser.objects.count()

    return HttpResponse(simplejson.dumps(pi_ret))
Esempio n. 10
0
File: api.py Progetto: CN-P5/PiBox
def dashboard_api(request):
    pisettings_instance = globaldata.getclient()

    pi_ret = {'nas': globaldata.NasEnable}
    if(client.socket_test(pisettings_instance.ip,  pisettings_instance.port)):
        pi_ret['connection'] = "TRUE"
    else:
        pi_ret['connection'] = "FALSE"
    pi_ret['app_num'] =   len(globaldata.AppList)

    pi_ret['user_count'] = PiUser.objects.count()

    return HttpResponse(simplejson.dumps(pi_ret))
Esempio n. 11
0
File: api.py Progetto: CN-P5/PiBox
def nas_api(request):
    pisettings_instance = globaldata.getclient()
      
    message = { "title" : "nas"}
    if request.method == 'GET':
        try:
            message['cmd'] =  request.GET['cmd'] ;
        except: 
            message['cmd'] =  '' ;

    pi_ret = client.socketjson_send_recv(pisettings_instance.ip,  pisettings_instance.port, message)

    return HttpResponse(simplejson.dumps(pi_ret.message))  
Esempio n. 12
0
def nas_api(request):
    pisettings_instance = globaldata.getclient()

    message = {"title": "nas"}
    if request.method == 'GET':
        try:
            message['cmd'] = request.GET['cmd']
        except:
            message['cmd'] = ''

    pi_ret = client.socketjson_send_recv(pisettings_instance.ip,
                                         pisettings_instance.port, message)

    return HttpResponse(simplejson.dumps(pi_ret.message))
Esempio n. 13
0
def register_api(request):
    pisettings_instance = globaldata.getclient()
    if pisettings_instance.enable_register != True:
        return HttpResponse("You are not be allowed to register")
    form = PiRegisterForm(request.POST or None)
    if form.is_valid():
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        password = form.cleaned_data['password1']
        user = PiUser.objects.create_user(email, email, password)
        if user is not None:
            user.first_name = first_name
            user.last_name = last_name
            user.is_staff = True
            user.save()
            return HttpResponse(simplejson.dumps({'msg': 'ok'}))
        else:
            return HttpResponse(simplejson.dumps({'msg': 'fail'}))
Esempio n. 14
0
File: api.py Progetto: CN-P5/PiBox
def register_api(request):    
    pisettings_instance = globaldata.getclient()
    if pisettings_instance.enable_register != True:
        return HttpResponse("You are not be allowed to register") 
    form = PiRegisterForm(request.POST or None)
    if form.is_valid():
        first_name=form.cleaned_data['first_name']
        last_name=form.cleaned_data['last_name']      
        email = form.cleaned_data['email'] 
        password=form.cleaned_data['password1']
        user = PiUser.objects.create_user(email, email, password)    
        if user is not None:  
            user.first_name =  first_name
            user.last_name = last_name
            user.is_staff = True  
            user.save()  
            return HttpResponse(simplejson.dumps({'msg':'ok'}))  
        else:  
            return HttpResponse(simplejson.dumps({'msg':'fail'}))