Commits

Anonymous committed 0f6d9dc

First commit from example for barcamp mallaca

Comments (0)

Files changed (21)

example/__init__.py

Empty file added.

example/__init__.pyc

Binary file added.

example/exampleapp/__init__.py

Empty file added.

example/exampleapp/__init__.pyc

Binary file added.

example/exampleapp/admin.py

+from django.contrib import admin
+from models import *
+admin.site.register(Example)

example/exampleapp/admin.pyc

Binary file added.

example/exampleapp/models.py

+from django.db import models
+
+# Create your models here.
+class Example(models.Model):
+    name = models.TextField()
+    score = models.IntegerField()

example/exampleapp/models.pyc

Binary file added.

example/exampleapp/tests.py

+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+

example/exampleapp/urls.py

+from django.conf.urls.defaults import *
+from views import *
+urlpatterns = patterns('',
+             (r'^$',example_view),
+             (r'^login/$',example_login),
+             (r'^register/$',example_register),
+             (r'^logout/$',example_logout),
+             (r'^like/(\d+)/$',example_like),
+             (r'^hate/(\d+)/$',example_hate),
+             )

example/exampleapp/urls.pyc

Binary file added.

example/exampleapp/views.py

+from django.contrib.auth.decorators import login_required
+from django.contrib.auth import authenticate,login,logout
+from django.contrib.auth.models import User
+from django.http import HttpResponse
+from django.http import HttpResponseRedirect
+from django.shortcuts import render_to_response
+# Create your views here.
+from models import *
+
+@login_required
+def example_view(request):
+    if request.method == 'POST':
+        data = Example(name = request.POST.get('posting'),score = 0)
+        data.save()
+    res = Example.objects.all() 
+    return render_to_response('example/template.html',{'res':res})
+    
+def example_register(request):
+    if request.method == 'POST':
+        username = request.POST.get('username')
+        password = request.POST.get('password')
+        email = request.POST.get('email')
+        user = User.objects.create_user(username,email,password)
+        user.save()
+        return HttpResponseRedirect('/example/login/')
+    else:
+        return render_to_response('example/register.html',{})
+        
+def example_login(request):
+    if request.method == 'POST': 
+        username_ = request.POST.get('username')
+        password_ = request.POST.get('password')
+        user = authenticate(username = username_,password = password_)
+        if user is not None:
+            if user.is_active:
+                login(request,user)
+                return HttpResponseRedirect('/example/')
+            else:
+                return HttpResponseRedirect('/example/login/')
+        else:
+            return HttpResponseRedirect('/example/login/')
+    else:
+        return render_to_response('example/login.html',{})
+
+
+def example_logout(request):
+    logout(request)
+    return HttpResponseRedirect('/example/login/')
+
+@login_required
+def example_like(request,id):
+    data = Example.objects.get(id=id)
+    data.score = data.score + 1
+    data.save()
+    return HttpResponseRedirect('/example/')
+
+@login_required
+def example_hate(request,id):
+    data = Example.objects.get(id=id)
+    data.score = data.score - 1
+    data.save()
+    return HttpResponseRedirect('/example/')

example/exampleapp/views.pyc

Binary file added.

example/manage.py

+#!/usr/bin/python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)

example/settings.py

+# Django settings for example project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = 'exampledb'             # Or path to database file if using sqlite3.
+DATABASE_USER = 'root'             # Not used with sqlite3.
+DATABASE_PASSWORD = 'root'         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# 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.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'fw^_ba8_vr2kz_#ml0p+_bu*^e=hb78&g_fcug+r71&xl3154&'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+#     'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+ROOT_URLCONF = 'example.urls'
+
+TEMPLATE_DIRS = (
+    # 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.
+    "/home/sweemeng/barcampmelaka/example/templates/",
+)
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.admin',
+    'exampleapp',
+)
+
+LOGIN_URL = '/example/login/'
+LOGOUT_URL = '/example/login/'

example/settings.pyc

Binary file added.

example/templates/example/login.html

+<html>
+<head>
+</head>
+<body>
+<form action='/example/login/' method='post'>
+<br/><label>username:</label><input type='text' name='username'/>
+<br/><label>password:</label><input type='password' name='password'/>
+<br/><input type='submit' value='submit'/>
+</form>
+
+</body>
+</html>

example/templates/example/register.html

+<html>
+<head>
+</head>
+<body>
+Registration page
+<form action='/example/register/' method='post'>
+<br/><label>username:</label><input type='text' name='username'/>
+<br/><label>password:</label><input type='password' name='password'/>
+<br/><label>email:</label><input type='text' name='email'/>
+<br/><input type='submit' value='submit'/>
+</form>
+
+</body>
+</html>

example/templates/example/template.html

+<html>
+<head>
+</head>
+<body>
+<br/><a href='/example/logout/'>logout</a>
+<form method='post' action='/example/'>
+Fill in your status
+<br/><textarea name='posting'></textarea>
+<br/><input type='submit' value='submit'/>
+</form>
+<br/>
+{% for d in res %}
+    {{d.name}} {{d.score}}
+    <br/>
+    <a href="/example/like/{{d.id}}/">like</a> <a
+    href="/example/hate/{{d.id}}/">hate</a>
+    <br/>
+{% endfor %}
+</body>
+</html>
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^example/',include('exampleapp.urls')),
+    # Example:
+    # (r'^example/', include('example.foo.urls')),
+
+    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
+    # to INSTALLED_APPS to enable admin documentation:
+    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+    # Uncomment the next line to enable the admin:
+     (r'^admin/', include(admin.site.urls)),
+#     (r'^admin/(.*)', admin.site.root),
+)

example/urls.pyc

Binary file added.