Browse Source

add login, home

windows
root 12 years ago
parent
commit
41d17b79e3
  1. 3
      .gitignore
  2. BIN
      db.sqlite3
  3. 4
      home/views.py
  4. BIN
      home/views.pyc
  5. 0
      main/__init__.py
  6. 28
      main/views.py
  7. 0
      manage.py
  8. 49
      pydash/settings.py
  9. BIN
      pydash/settings.pyc
  10. 7
      pydash/urls.py
  11. BIN
      pydash/urls.pyc
  12. 49
      templates/home.html
  13. 2
      templates/login.html

3
.gitignore

@ -0,0 +1,3 @@
*.pyc
._*
db.sqlite3

BIN
db.sqlite3

4
home/views.py

@ -1,4 +1,4 @@
import socket
from main.views import *
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
@ -15,3 +15,5 @@ def index(request):
return HttpResponseRedirect('/login')
else:
return HttpResponseRedirect('/home')

BIN
home/views.pyc

0
main/__init__.py

28
main/views.py

@ -0,0 +1,28 @@
from datetime import timedelta
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.utils import simplejson
def getuptime():
"""
Get uptime
"""
if not request.user.is_authenticated():
return HttpResponseRedirect('/login')
try:
with open('/proc/uptime', 'r') as f:
uptime_seconds = float(f.readline().split()[0])
uptime_time = str(timedelta(seconds = uptime_seconds))
data = simplejson.dumps(uptime_time)
except Exception,err:
data = simplejson.dumps(str(err))
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(data)
return response

0
manage.py

49
pydash/settings.py

@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
#SITE_ID = 1
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
@ -37,11 +38,12 @@ ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
#'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
#'django.contrib.sites',
'django.contrib.staticfiles',
)
@ -58,16 +60,7 @@ ROOT_URLCONF = 'pydash.urls'
WSGI_APPLICATION = 'pydash.wsgi.application'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
@ -102,4 +95,40 @@ TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'templates'),)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static')
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

BIN
pydash/settings.pyc

7
pydash/urls.py

@ -1,4 +1,4 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import patterns, url
from django.conf import settings
#from django.contrib import admin
@ -13,4 +13,9 @@ urlpatterns = patterns('',
url(r'^$', 'home.views.index', name='index'),
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}, name='logout'),
url(r'^home/$', 'home.views.devices_list', name='devices_list'),
)
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
)

BIN
pydash/urls.pyc

49
templates/home.html

@ -0,0 +1,49 @@
{% load i18n %}{% load staticfiles %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="{% static "img/favicon.ico" %}">
<title>{% block title %}{% endblock %}</title>
<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet">
<link href="{% static "css/base.css" %}" rel="stylesheet">
{% block style %}{% endblock %}
</head>
<body>
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">pyDash</a>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
<a href="{% url 'infrastructure' %}" title="{% trans "Show all host and vm's" %}">{% trans "Infrastructure" %}</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated or user.is_authenticated %}
<li class="">
<a href="{% url 'logout' %}">{% trans "Sign out" %}</a>
</li>
{% else %}
<li class="">
<a href="{% url 'login' %}">{% trans "Sign in" %}</a>
</li>
{% endif %}
</ul>
</nav>
</div>
</div>
<div class="container">
{% block content %}{% endblock %}
</div>
<script src="{% static "js/jquery-1.10.2.js" %}"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
{% block script %}{% endblock %}
</body>
</html>

2
templates/login.html

@ -12,7 +12,7 @@
<h2 class="form-signin-heading">{% trans "Sign In" %}</h2>
<input type="text" class="form-control" name="username" placeholder="Login" autofocus>
<input type="password" class="form-control" name="password" placeholder="Password">
<input name="next" id="next" type="hidden" value="/servers/">
<input name="next" id="next" type="hidden" value="/home/">
<button class="btn btn-lg btn-success btn-block" type="submit">{% trans "Sign In" %}</button>
</form>
{% endblock %}
Loading…
Cancel
Save