From cadc3ba992ce3fdf920797ca5d66e29c55452ad8 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 15:50:30 +0100 Subject: [PATCH 01/23] Create django project --- dwitter/dwitter/__init__.py | 0 dwitter/dwitter/settings.py | 154 ++++++++++++++++++++++++++++++++++++ dwitter/dwitter/urls.py | 17 ++++ dwitter/dwitter/wsgi.py | 28 +++++++ dwitter/manage.py | 10 +++ 5 files changed, 209 insertions(+) create mode 100644 dwitter/dwitter/__init__.py create mode 100644 dwitter/dwitter/settings.py create mode 100644 dwitter/dwitter/urls.py create mode 100644 dwitter/dwitter/wsgi.py create mode 100644 dwitter/manage.py diff --git a/dwitter/dwitter/__init__.py b/dwitter/dwitter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dwitter/dwitter/settings.py b/dwitter/dwitter/settings.py new file mode 100644 index 0000000..de935be --- /dev/null +++ b/dwitter/dwitter/settings.py @@ -0,0 +1,154 @@ +# Django settings for dwitter project. + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) + +MANAGERS = ADMINS + +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. + '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. + } +} + +# 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. +# On Unix systems, a value of None will cause Django to use the same +# timezone as the operating system. +# 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 + +# If you set this to False, Django will not format dates, numbers and +# calendars according to the current locale. +USE_L10N = True + +# If you set this to False, Django will not use timezone-aware datetimes. +USE_TZ = True + +# Absolute filesystem path to the directory that will hold user-uploaded files. +# Example: "/home/media/media.lawrence.com/media/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash. +# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" +MEDIA_URL = '' + +# Absolute path to the directory static files should be collected to. +# Don't put anything in this directory yourself; store your static files +# in apps' "static/" subdirectories and in STATICFILES_DIRS. +# Example: "/home/media/media.lawrence.com/static/" +STATIC_ROOT = '' + +# URL prefix for static files. +# Example: "http://media.lawrence.com/static/" +STATIC_URL = '/static/' + +# Additional locations of static files +STATICFILES_DIRS = ( + # Put strings here, like "/home/html/static" or "C:/www/django/static". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +# List of finder classes that know how to find static files in +# various locations. +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +# 'django.contrib.staticfiles.finders.DefaultStorageFinder', +) + +# Make this unique, and don't share it with anybody. +SECRET_KEY = ')n!rr8y*u+q^9chlo%cr0koj1k1jz_21#g%+u)k&(*1diqi16h' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +# 'django.template.loaders.eggs.Loader', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + # Uncomment the next line for simple clickjacking protection: + # 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) + +ROOT_URLCONF = 'dwitter.urls' + +# Python dotted path to the WSGI application used by Django's runserver. +WSGI_APPLICATION = 'dwitter.wsgi.application' + +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. +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles', + # Uncomment the next line to enable the admin: + # 'django.contrib.admin', + # Uncomment the next line to enable admin documentation: + # 'django.contrib.admindocs', +) + +# A sample logging configuration. The only tangible logging +# performed by this configuration is to send an email to +# the site admins on every HTTP 500 error when DEBUG=False. +# See http://docs.djangoproject.com/en/dev/topics/logging for +# more details on how to customize your logging configuration. +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, + }, + } +} diff --git a/dwitter/dwitter/urls.py b/dwitter/dwitter/urls.py new file mode 100644 index 0000000..c09b3c8 --- /dev/null +++ b/dwitter/dwitter/urls.py @@ -0,0 +1,17 @@ +from django.conf.urls import patterns, include, url + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'dwitter.views.home', name='home'), + # url(r'^dwitter/', include('dwitter.foo.urls')), + + # Uncomment the admin/doc line below to enable admin documentation: + # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + # url(r'^admin/', include(admin.site.urls)), +) diff --git a/dwitter/dwitter/wsgi.py b/dwitter/dwitter/wsgi.py new file mode 100644 index 0000000..a886a71 --- /dev/null +++ b/dwitter/dwitter/wsgi.py @@ -0,0 +1,28 @@ +""" +WSGI config for dwitter project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dwitter.settings") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application) diff --git a/dwitter/manage.py b/dwitter/manage.py new file mode 100644 index 0000000..73db9b0 --- /dev/null +++ b/dwitter/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dwitter.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) From ce1497a6b1f67a0431355cd410d57dc76d1d71de Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 15:59:44 +0100 Subject: [PATCH 02/23] Create first view --- dwitter/dwitter/settings.py | 1 + dwitter/dwitter/urls.py | 1 + dwitter/website/__init__.py | 0 dwitter/website/models.py | 3 +++ dwitter/website/tests.py | 16 ++++++++++++++++ dwitter/website/views.py | 5 +++++ 6 files changed, 26 insertions(+) create mode 100644 dwitter/website/__init__.py create mode 100644 dwitter/website/models.py create mode 100644 dwitter/website/tests.py create mode 100644 dwitter/website/views.py diff --git a/dwitter/dwitter/settings.py b/dwitter/dwitter/settings.py index de935be..d605313 100644 --- a/dwitter/dwitter/settings.py +++ b/dwitter/dwitter/settings.py @@ -122,6 +122,7 @@ # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', + 'website', ) # A sample logging configuration. The only tangible logging diff --git a/dwitter/dwitter/urls.py b/dwitter/dwitter/urls.py index c09b3c8..811bf48 100644 --- a/dwitter/dwitter/urls.py +++ b/dwitter/dwitter/urls.py @@ -14,4 +14,5 @@ # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), + url(r'^$', 'website.views.timeline'), ) diff --git a/dwitter/website/__init__.py b/dwitter/website/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dwitter/website/models.py b/dwitter/website/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/dwitter/website/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/dwitter/website/tests.py b/dwitter/website/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/dwitter/website/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this 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.assertEqual(1 + 1, 2) diff --git a/dwitter/website/views.py b/dwitter/website/views.py new file mode 100644 index 0000000..583868e --- /dev/null +++ b/dwitter/website/views.py @@ -0,0 +1,5 @@ +from django.http import HttpResponse + + +def timeline(request): + return HttpResponse('Welcome to dwitter!') From 40ac62400ea3615a2cf0b64584b4e4f4328efe9b Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 16:24:58 +0100 Subject: [PATCH 03/23] Create first template --- dwitter/website/templates/website/index.html | 8 ++++++++ dwitter/website/views.py | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 dwitter/website/templates/website/index.html diff --git a/dwitter/website/templates/website/index.html b/dwitter/website/templates/website/index.html new file mode 100644 index 0000000..024c38a --- /dev/null +++ b/dwitter/website/templates/website/index.html @@ -0,0 +1,8 @@ + + + + +{{ tweets }} + + + diff --git a/dwitter/website/views.py b/dwitter/website/views.py index 583868e..8bb6698 100644 --- a/dwitter/website/views.py +++ b/dwitter/website/views.py @@ -1,5 +1,14 @@ -from django.http import HttpResponse +from datetime import datetime + +from django.shortcuts import render + + +tweets = [ + {'user_name':'jorgebastida', 'message': 'Hello world!', 'timestamp': datetime.now()}, + {'user_name':'jaimeirurzun', 'message': 'I like ponies :D', 'timestamp': datetime.now()}, + {'user_name':'jorgebastida', 'message': 'Django rulezzzzz', 'timestamp': datetime.now()} +] def timeline(request): - return HttpResponse('Welcome to dwitter!') + return render(request, 'website/index.html', {'tweets': tweets}) From 2ebf5f49d6361742d59d06e03d61975b768ec340 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 17:07:03 +0100 Subject: [PATCH 04/23] Use template tags --- dwitter/website/templates/website/index.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dwitter/website/templates/website/index.html b/dwitter/website/templates/website/index.html index 024c38a..012a484 100644 --- a/dwitter/website/templates/website/index.html +++ b/dwitter/website/templates/website/index.html @@ -2,7 +2,13 @@ -{{ tweets }} +
    +{% for tweet in tweets %} +
  • {{ tweet.user_name }}: {{ tweet.message }} ({{ tweet.timestamp }})
  • +{% empty %} + No tweets in this timeline! +{% endfor %} +
From 82a67e4737fa60479b77ad1b26d1f3791c647c27 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 17:13:38 +0100 Subject: [PATCH 05/23] Use filters --- dwitter/website/templates/website/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwitter/website/templates/website/index.html b/dwitter/website/templates/website/index.html index 012a484..aa33f7f 100644 --- a/dwitter/website/templates/website/index.html +++ b/dwitter/website/templates/website/index.html @@ -4,7 +4,7 @@
    {% for tweet in tweets %} -
  • {{ tweet.user_name }}: {{ tweet.message }} ({{ tweet.timestamp }})
  • +
  • {{ tweet.user_name }}: {{ tweet.message|lower|capfirst|urlize }} ({{ tweet.timestamp|timesince }})
  • {% empty %} No tweets in this timeline! {% endfor %} From c222b419b782bd018430045068ebfe09915c8a84 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 17:15:50 +0100 Subject: [PATCH 06/23] Fix tweets list --- dwitter/website/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwitter/website/views.py b/dwitter/website/views.py index 8bb6698..c56a2b2 100644 --- a/dwitter/website/views.py +++ b/dwitter/website/views.py @@ -5,8 +5,8 @@ tweets = [ {'user_name':'jorgebastida', 'message': 'Hello world!', 'timestamp': datetime.now()}, - {'user_name':'jaimeirurzun', 'message': 'I like ponies :D', 'timestamp': datetime.now()}, - {'user_name':'jorgebastida', 'message': 'Django rulezzzzz', 'timestamp': datetime.now()} + {'user_name':'jaimeirurzun', 'message': 'I like ponies! http://djangopony.com', 'timestamp': datetime.now()}, + {'user_name':'jorgebastida', 'message': 'Django RULEZZZZZZ', 'timestamp': datetime.now()} ] From a8ee04e6ae368e9c9d1b81abf1b066477c423f93 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 17:23:01 +0100 Subject: [PATCH 07/23] Inherit from base.html --- dwitter/website/templates/website/base.html | 200 +++++++++++++++++++ dwitter/website/templates/website/index.html | 10 +- 2 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 dwitter/website/templates/website/base.html diff --git a/dwitter/website/templates/website/base.html b/dwitter/website/templates/website/base.html new file mode 100644 index 0000000..fc80c5c --- /dev/null +++ b/dwitter/website/templates/website/base.html @@ -0,0 +1,200 @@ + + + + {% block title %}Django{% endblock %} + + + + + +
    +
    +
    +

    +

    + {% block content %}{% endblock %} +
    +
    + Bienvenido a dwitter! +

    MenĂº

    +
      +
    • Buscar dwitters
    • +
    + {% block sidebar %}{% endblock %} +
    +
    +
    + pony powered +
    + +
    +
    +
    + + diff --git a/dwitter/website/templates/website/index.html b/dwitter/website/templates/website/index.html index aa33f7f..da291a6 100644 --- a/dwitter/website/templates/website/index.html +++ b/dwitter/website/templates/website/index.html @@ -1,6 +1,7 @@ - - - +{% extends "website/base.html" %} + + +{% block content %}
      {% for tweet in tweets %} @@ -10,5 +11,4 @@ {% endfor %}
    - - +{% endblock %} From 790f873999d7c29aa5ce5219d14cfa1b0715e098 Mon Sep 17 00:00:00 2001 From: Jaime Irurzun Date: Sun, 22 Apr 2012 17:43:26 +0100 Subject: [PATCH 08/23] Create Tweet model --- dwitter/dwitter/settings.py | 4 ++-- dwitter/website/models.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dwitter/dwitter/settings.py b/dwitter/dwitter/settings.py index d605313..6993227 100644 --- a/dwitter/dwitter/settings.py +++ b/dwitter/dwitter/settings.py @@ -11,8 +11,8 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': '', # Or path to database file if using sqlite3. + 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': 'db.sqlite', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. diff --git a/dwitter/website/models.py b/dwitter/website/models.py index 71a8362..e30a54a 100644 --- a/dwitter/website/models.py +++ b/dwitter/website/models.py @@ -1,3 +1,11 @@ from django.db import models +from django.contrib.auth.models import User -# Create your models here. + +class Tweet(models.Model): + message = models.TextField(blank=True, max_length=140) + timestamp = models.DateTimeField(auto_now_add=True) + user = models.ForeignKey(User) + + def __unicode__(self): + return self.message From 648d1f3d54f5b8827767b00f6041a78939c67d87 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 17:59:46 +0100 Subject: [PATCH 09/23] Add 'ago' to the template --- dwitter/website/templates/website/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwitter/website/templates/website/index.html b/dwitter/website/templates/website/index.html index aa33f7f..444134e 100644 --- a/dwitter/website/templates/website/index.html +++ b/dwitter/website/templates/website/index.html @@ -4,7 +4,7 @@
      {% for tweet in tweets %} -
    • {{ tweet.user_name }}: {{ tweet.message|lower|capfirst|urlize }} ({{ tweet.timestamp|timesince }})
    • +
    • {{ tweet.user_name }}: {{ tweet.message|lower|capfirst|urlize }} ({{ tweet.timestamp|timesince }} ago)
    • {% empty %} No tweets in this timeline! {% endfor %} From a0e55b088e5c8eb4e7ac93ba0eba3de78534d959 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 22 Apr 2012 21:49:51 +0100 Subject: [PATCH 10/23] Add bootstrap to base.html --- dwitter/website/templates/website/base.html | 250 +++++-------------- dwitter/website/templates/website/index.html | 6 +- 2 files changed, 67 insertions(+), 189 deletions(-) diff --git a/dwitter/website/templates/website/base.html b/dwitter/website/templates/website/base.html index fc80c5c..ddb3fe6 100644 --- a/dwitter/website/templates/website/base.html +++ b/dwitter/website/templates/website/base.html @@ -1,200 +1,78 @@ - - - - {% block title %}Django{% endblock %} - + + + + - - - - From 25f4bc4f01bf586df58987609ec248ed0acd758e Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 29 Apr 2012 18:02:06 +0100 Subject: [PATCH 15/23] Add useful information to the sidebar --- dwitter/website/templates/website/base.html | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/dwitter/website/templates/website/base.html b/dwitter/website/templates/website/base.html index 60ff493..54082d7 100644 --- a/dwitter/website/templates/website/base.html +++ b/dwitter/website/templates/website/base.html @@ -76,6 +76,38 @@
      {% block sidebar %}{% endblock %} + +

      Welcome to dwitter!

      +

      This is an opensource didactic project for learning Django step-by-step.

      +
      Resources
      + + +
      Solutions
      +
      From a569b238ec70f4a25c00faefe0278dc0affacf10 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 29 Apr 2012 18:06:51 +0100 Subject: [PATCH 16/23] Add a separator --- dwitter/website/templates/website/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwitter/website/templates/website/base.html b/dwitter/website/templates/website/base.html index 54082d7..dc6b71d 100644 --- a/dwitter/website/templates/website/base.html +++ b/dwitter/website/templates/website/base.html @@ -76,7 +76,7 @@
      {% block sidebar %}{% endblock %} - +

      Welcome to dwitter!

      This is an opensource didactic project for learning Django step-by-step.

      Resources
      From 8b023676b04b948d006babc73e3d79ffcd7ce247 Mon Sep 17 00:00:00 2001 From: Jorge Bastida Date: Sun, 6 May 2012 18:23:09 +0200 Subject: [PATCH 17/23] Add .DS_Store to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d20b64..0205d62 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +.DS_Store From 8668f32f2d34f56a341e61d0d321a8420fd80224 Mon Sep 17 00:00:00 2001 From: Jaime Irurzun Date: Wed, 9 Oct 2013 11:38:29 +0200 Subject: [PATCH 18/23] Fix link to bootstrap's css --- dwitter/website/templates/website/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwitter/website/templates/website/base.html b/dwitter/website/templates/website/base.html index dc6b71d..2192683 100644 --- a/dwitter/website/templates/website/base.html +++ b/dwitter/website/templates/website/base.html @@ -6,7 +6,7 @@ - +