Skip to content

Commit 37b9088

Browse files
committed
hello world
0 parents  commit 37b9088

40 files changed

+685
-0
lines changed

.gitignore

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
eggs/
15+
lib/
16+
lib64/
17+
parts/
18+
sdist/
19+
var/
20+
*.egg-info/
21+
.installed.cfg
22+
*.egg
23+
24+
# PyInstaller
25+
# Usually these files are written by a python script from a template
26+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
27+
*.manifest
28+
*.spec
29+
30+
# Installer logs
31+
pip-log.txt
32+
pip-delete-this-directory.txt
33+
34+
# Unit test / coverage reports
35+
htmlcov/
36+
.tox/
37+
.coverage
38+
.cache
39+
nosetests.xml
40+
coverage.xml
41+
42+
# Translations
43+
*.mo
44+
*.pot
45+
46+
# Django stuff:
47+
*.log
48+
db.sqlite3
49+
50+
# Sphinx documentation
51+
docs/_build/
52+
53+
# PyBuilder
54+
target/
55+

ftp/__init__.py

Whitespace-only changes.

ftp/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

ftp/forms.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django import forms
2+
from models import Account
3+
4+
class AccountUpdateForm(forms.ModelForm):
5+
new_password = forms.CharField(required=False, widget=forms.widgets.PasswordInput)
6+
class Meta:
7+
model = Account
8+
fields = ('domain', 'path')
9+

ftp/models.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.db import models
2+
from django.utils.translation import ugettext_lazy as _
3+
from passlib.hash import sha512_crypt
4+
from kumquat.models import Domain
5+
6+
default_length = 255
7+
8+
class Account(models.Model):
9+
name = models.CharField(max_length=default_length, unique=True)
10+
password = models.CharField(max_length=default_length)
11+
domain = models.ForeignKey(Domain)
12+
path = models.CharField(max_length=default_length, default="/")
13+
14+
def set_password(self, password):
15+
self.password = sha512_crypt.encrypt(password)
16+
17+
def __unicode__(self):
18+
return self.name

ftp/templates/ftp/account_form.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
{% load bootstrap3 %}
4+
5+
{% block content %}
6+
<h1>{% trans "Add FTP Account" %}</h1>
7+
<form method="post" class="form-horizontal" role="form">
8+
{% csrf_token %}
9+
{% bootstrap_form form layout='horizontal' %}
10+
{% buttons layout='horizontal' submit='OK' %}
11+
{% endbuttons %}
12+
</form>
13+
{% endblock %}

ftp/templates/ftp/account_list.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
{% load bootstrap3 %}
4+
5+
{% block content %}
6+
<h1>{% trans "FTP Accounts" %}</h1>
7+
8+
<a href="{% url "ftp_account_add" %}" class="btn btn-success pull-right">{% bootstrap_icon "plus" %} New</a>
9+
10+
<table class="table table-striped table-condensed table-hover">
11+
<thead>
12+
<tr>
13+
<th>Name</th><th>Domain</th><th>Path</th><th>&nbsp;</th>
14+
</tr>
15+
</thead>
16+
{% for account in object_list %}
17+
<tr>
18+
<td><a href="{% url "ftp_account_update" account.id %}">{{ account.name }}</a></td>
19+
<td>{{ account.domain }}</td>
20+
<td>{{ account.path }}</td>
21+
<td>
22+
<form action="{% url "ftp_account_delete" account.id %}" method="post">
23+
{% csrf_token %}
24+
<input type="submit" value="{% trans "Delete" %}" class="btn btn-xs btn-danger"/>
25+
</form>
26+
</td>
27+
</tr>
28+
{% endfor %}
29+
</table>
30+
{% endblock %}

ftp/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

ftp/urls.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.conf.urls import patterns, url
2+
import views
3+
4+
urlpatterns = patterns('',
5+
url(r'^accounts/$', views.AccountList.as_view(), name='ftp_account_list'),
6+
url(r'^accounts/add$', views.AccountCreate.as_view(), name='ftp_account_add'),
7+
url(r'^accounts/(?P<pk>\d+)/update$', views.AccountUpdate.as_view(), name='ftp_account_update'),
8+
url(r'^accounts/(?P<pk>\d+)/delete$', views.AccountDelete.as_view(), name='ftp_account_delete'),
9+
)

ftp/views.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.core.urlresolvers import reverse_lazy
2+
from django.views.generic import ListView
3+
from django.views.generic.edit import CreateView, UpdateView, DeleteView
4+
from models import Account
5+
from forms import AccountUpdateForm
6+
7+
class AccountList(ListView):
8+
model = Account
9+
10+
class AccountCreate(CreateView):
11+
model = Account
12+
success_url = reverse_lazy('ftp_account_list')
13+
14+
def form_valid(self, form):
15+
password = form.cleaned_data.get('password')
16+
self.object = form.save(commit=False)
17+
self.object.set_password(password)
18+
self.object.save()
19+
return super(AccountCreate, self).form_valid(form)
20+
21+
22+
class AccountUpdate(UpdateView):
23+
model = Account
24+
form_class = AccountUpdateForm
25+
success_url = reverse_lazy('ftp_account_list')
26+
27+
def form_valid(self, form):
28+
new_password = form.cleaned_data.get('new_password')
29+
if new_password:
30+
self.object = form.save(commit=False)
31+
self.object.set_password(new_password)
32+
self.object.save()
33+
return super(AccountUpdate, self).form_valid(form)
34+
35+
36+
class AccountDelete(DeleteView):
37+
model = Account
38+
success_url = reverse_lazy('ftp_account_list')

kumquat/__init__.py

Whitespace-only changes.

kumquat/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

kumquat/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.db import models
2+
from django.utils.translation import ugettext_lazy as _
3+
4+
class Domain(models.Model):
5+
name = models.CharField(max_length=255, unique=True, verbose_name=_('Name'))
6+
7+
def __unicode__(self):
8+
return self.name
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
{% load bootstrap3 %}
4+
5+
{% block content %}
6+
<h1>{% trans "Add Domain" %}</h1>
7+
<form method="post" class="form-horizontal" role="form">
8+
{% csrf_token %}
9+
{% bootstrap_form form layout='horizontal' %}
10+
{% buttons layout='horizontal' submit='OK' %}
11+
{% endbuttons %}
12+
</form>
13+
{% endblock %}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
{% load bootstrap3 %}
4+
5+
{% block content %}
6+
<h1>{% trans "Domains" %}</h1>
7+
8+
<a href="{% url "domain_add" %}" class="btn btn-success pull-right">{% bootstrap_icon "plus" %} New</a>
9+
10+
<table class="table table-striped table-condensed table-hover">
11+
<thead>
12+
<tr>
13+
<th>Name</th><th>&nbsp;</th>
14+
</tr>
15+
</thead>
16+
{% for domain in object_list %}
17+
<tr>
18+
<td>{{ domain.name }}</td>
19+
<td>
20+
<form action="{% url "domain_delete" domain.id %}" method="post">
21+
{% csrf_token %}
22+
<input type="submit" value="{% trans "Delete" %}" class="btn btn-xs btn-danger"/>
23+
</form>
24+
</td>
25+
</tr>
26+
{% endfor %}
27+
</table>
28+
{% endblock %}

kumquat/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

kumquat/urls.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.conf.urls import patterns, url
2+
import views
3+
4+
urlpatterns = patterns('',
5+
url(r'^domains/$', views.DomainList.as_view(), name='domain_list'),
6+
url(r'^domains/add$', views.DomainCreate.as_view(), name='domain_add'),
7+
url(r'^domains/(?P<pk>\d+)/delete$', views.DomainDelete.as_view(), name='domain_delete'),
8+
)

kumquat/views.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.core.urlresolvers import reverse_lazy
2+
from django.views.generic import ListView
3+
from django.views.generic.edit import CreateView, UpdateView, DeleteView
4+
from models import Domain
5+
6+
class DomainList(ListView):
7+
model = Domain
8+
9+
class DomainCreate(CreateView):
10+
model = Domain
11+
success_url = reverse_lazy('domain_list')
12+
13+
class DomainDelete(DeleteView):
14+
model = Domain
15+
success_url = reverse_lazy('domain_list')

kumquat_web/__init__.py

Whitespace-only changes.

kumquat_web/settings.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""
2+
Django settings for kumquat_web project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.6/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.6/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14+
15+
16+
# Quick-start development settings - unsuitable for production
17+
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
18+
19+
# SECURITY WARNING: keep the secret key used in production secret!
20+
SECRET_KEY = '^s7@cvx=$d)uvd75)u_p(w12zswl%**et1s2xys$wkq-sx($-d'
21+
22+
# SECURITY WARNING: don't run with debug turned on in production!
23+
DEBUG = True
24+
TEMPLATE_DEBUG = True
25+
ALLOWED_HOSTS = []
26+
27+
# Application definition
28+
29+
INSTALLED_APPS = (
30+
'django.contrib.admin',
31+
'django.contrib.auth',
32+
'django.contrib.contenttypes',
33+
'django.contrib.sessions',
34+
'django.contrib.messages',
35+
'django.contrib.staticfiles',
36+
'bootstrap3',
37+
'kumquat',
38+
'web',
39+
'mysql',
40+
'ftp',
41+
)
42+
43+
MIDDLEWARE_CLASSES = (
44+
'django.contrib.sessions.middleware.SessionMiddleware',
45+
'django.middleware.common.CommonMiddleware',
46+
'django.middleware.csrf.CsrfViewMiddleware',
47+
'django.contrib.auth.middleware.AuthenticationMiddleware',
48+
'django.contrib.messages.middleware.MessageMiddleware',
49+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
50+
)
51+
52+
ROOT_URLCONF = 'kumquat_web.urls'
53+
WSGI_APPLICATION = 'kumquat_web.wsgi.application'
54+
55+
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
56+
57+
58+
59+
# Database
60+
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
61+
62+
DATABASES = {
63+
'default': {
64+
'ENGINE': 'django.db.backends.sqlite3',
65+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
66+
},
67+
'kumquat_mysql': {
68+
'ENGINE': 'django.db.backends.mysql',
69+
'HOST': '192.168.15.238',
70+
'USER': 'root',
71+
'PASSWORD': 'qwe123',
72+
}
73+
74+
}
75+
76+
# Internationalization
77+
# https://docs.djangoproject.com/en/1.6/topics/i18n/
78+
79+
LANGUAGE_CODE = 'en-us'
80+
TIME_ZONE = 'UTC'
81+
USE_I18N = True
82+
USE_L10N = True
83+
USE_TZ = True
84+
85+
86+
# Static files (CSS, JavaScript, Images)
87+
# https://docs.djangoproject.com/en/1.6/howto/static-files/
88+
89+
STATIC_URL = '/static/'
90+
91+
92+
# mysql
93+

kumquat_web/urls.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.conf.urls import patterns, include, url
2+
3+
from django.contrib import admin
4+
admin.autodiscover()
5+
6+
urlpatterns = patterns('',
7+
url(r'^system/', include('kumquat.urls')),
8+
url(r'^ftp/', include('ftp.urls')),
9+
url(r'^mysql/', include('mysql.urls')),
10+
url(r'^admin/', include(admin.site.urls)),
11+
)

0 commit comments

Comments
 (0)