diff --git a/django_test/README.md b/django_test/README.md
old mode 100644
new mode 100755
diff --git a/django_test/django_test/applications/__init__.py b/django_test/django_test/applications/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_test/django_test/applications/userprofile/__init__.py b/django_test/django_test/applications/userprofile/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_test/django_test/applications/userprofile/forms.py b/django_test/django_test/applications/userprofile/forms.py
new file mode 100644
index 0000000..2aaabe0
--- /dev/null
+++ b/django_test/django_test/applications/userprofile/forms.py
@@ -0,0 +1,54 @@
+from django import forms
+from django.contrib.auth.models import User
+from django.contrib.localflavor.us.forms import USPhoneNumberField
+from django.contrib.auth import authenticate
+
+from models import Userprofile
+
+from utils.tools import USPhoneNumberMultiWidget
+
+class Userform(forms.ModelForm):
+
+
+ class Meta:
+ model = Userprofile
+ exclude = ('user',)
+
+ def __init__(self, *args, **kwargs):
+ super(Userform, self).__init__(*args, **kwargs)
+ self.fields.keyOrder = [
+ 'username',
+ 'firstname',
+ 'lastname',
+ 'email',
+ 'telephone',
+ 'password']
+
+ username = forms.CharField(min_length=5)
+ firstname = forms.CharField()
+ lastname = forms.CharField()
+ telephone = USPhoneNumberField(label="Phone", widget=USPhoneNumberMultiWidget())
+ email = forms.EmailField()
+ password = forms.CharField(max_length=32, widget=forms.PasswordInput)
+
+ def clean_username(self):
+ cd = self.cleaned_data
+ users = User.objects.filter(username__iexact=cd['username'])
+ if users.count() > 0:
+ raise forms.ValidationError("username is not unique")
+ return cd['username']
+
+
+ def save(self):
+ cd = self.cleaned_data
+ print cd['username']
+ user = User.objects.create_user(cd['username'], password=cd['password'], email=cd['email'])
+ user.save()
+ user = authenticate(username=cd['username'], password=cd['password'])
+ userprofile = Userprofile(
+ user=user,
+ telephone=cd['telephone'],
+ )
+ userprofile.save()
+ return userprofile
+
\ No newline at end of file
diff --git a/django_test/django_test/applications/userprofile/models.py b/django_test/django_test/applications/userprofile/models.py
new file mode 100644
index 0000000..603f6b4
--- /dev/null
+++ b/django_test/django_test/applications/userprofile/models.py
@@ -0,0 +1,58 @@
+try:
+ import simplejson as json
+except:
+ import json
+
+from django.db import models
+from django.contrib.auth.models import User
+
+class Userprofile(models.Model):
+
+ user = models.ForeignKey(User, related_name='profile')
+ telephone = models.CharField(max_length=15)
+
+
+
+class Todo(models.Model):
+ user = models.ForeignKey(User, related_name="todo_list")
+ list = models.TextField()
+
+ def add(self, item, status='active'):
+ list = self.get_list()
+ list.append({'value':item, 'status':status})
+ self.list = json.dumps(list)
+ self.save()
+
+ def update(self, item):
+ list = self.get_list()
+ for l in list:
+ if l.get('value') == item:
+ if l['status'] == "active":
+ l['status'] = "complete"
+ else:
+ l['status'] = "active"
+ break
+
+ self.list = json.dumps(list)
+ self.save()
+ return l['status']
+
+ def remove(self, item):
+ list = self.get_list()
+ for l in list:
+ if l.get('value') == item:
+ list.pop(list.index(l))
+ break
+
+ self.list = json.dumps(list)
+ self.save()
+
+
+ def get_list(self):
+ if self.list is None or self.list == "":
+ todos = []
+ else:
+ print self.list
+ todos = json.loads(self.list)
+ return todos
+
diff --git a/django_test/django_test/settings.py b/django_test/django_test/settings.py
old mode 100644
new mode 100755
index 3468225..503e5e9
--- a/django_test/django_test/settings.py
+++ b/django_test/django_test/settings.py
@@ -1,4 +1,10 @@
# Django settings for django_test project.
+import os
+import sys
+
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+sys.path.append('%s/applications' % BASE_DIR)
+sys.path.append('%s' % BASE_DIR)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
@@ -11,15 +17,17 @@
DATABASES = {
'default': {
- 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': '', # Or path to database file if using sqlite3.
- 'USER': '', # Not used with sqlite3.
+ 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'test',# Or path to database file if using sqlite3.
+ 'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
+ #'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
-
+AUTHENTICATION_BACKENDS = (
+ 'django.contrib.auth.backends.ModelBackend',
+ )
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
@@ -106,6 +114,7 @@
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
+ "%s/templates/"%BASE_DIR,
)
INSTALLED_APPS = (
@@ -115,6 +124,8 @@
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
+
+ 'userprofile',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
@@ -129,15 +140,10 @@
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'
}
},
diff --git a/django_test/django_test/templates/base.html b/django_test/django_test/templates/base.html
new file mode 100644
index 0000000..f7ee4fd
--- /dev/null
+++ b/django_test/django_test/templates/base.html
@@ -0,0 +1,14 @@
+
+Home >>
+{%if not user.is_authenticated%}
+login
+{%else%}
+todo >>
+logout
+{%endif%}
+
+
+
+{%block content%}
+
+{%endblock%}
diff --git a/django_test/django_test/templates/home.html b/django_test/django_test/templates/home.html
new file mode 100644
index 0000000..387d273
--- /dev/null
+++ b/django_test/django_test/templates/home.html
@@ -0,0 +1,10 @@
+{%extends 'base.html'%}
+
+{%block content%}
+youre home
+
+{%if user.is_authenticated%}
+Welcome {{user.username}}
+{%endif%}
+
+{%endblock%}
\ No newline at end of file
diff --git a/django_test/django_test/templates/login.html b/django_test/django_test/templates/login.html
new file mode 100644
index 0000000..7637a17
--- /dev/null
+++ b/django_test/django_test/templates/login.html
@@ -0,0 +1,31 @@
+
+
+
+
Your username and password didn't match. Please try again.
+ {% endif %} + + +