diff --git a/.gitignore b/.gitignore index 0d20b64..5a7a41f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.pyc +.DS_Store +db.sqlite3 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..232d8d8 --- /dev/null +++ b/dwitter/dwitter/settings.py @@ -0,0 +1,105 @@ +""" +Django settings for dwitter project. + +Generated by 'django-admin startproject' using Django 1.8.5. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'q-d=!b%9ialb@4zx!u$!&*qro_v4y9ur--w2(ecx_n2fkrn#!%' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'website', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'dwitter.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'dwitter.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.8/howto/static-files/ + +STATIC_URL = '/static/' + +AUTH_USER_MODEL = 'website.User' diff --git a/dwitter/dwitter/urls.py b/dwitter/dwitter/urls.py new file mode 100644 index 0000000..e66bfdc --- /dev/null +++ b/dwitter/dwitter/urls.py @@ -0,0 +1,22 @@ +"""dwitter URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.8/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Add an import: from blog import urls as blog_urls + 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) +""" +from django.conf.urls import include, url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', include(admin.site.urls)), + url(r'^$', 'website.views.timeline'), +] diff --git a/dwitter/dwitter/wsgi.py b/dwitter/dwitter/wsgi.py new file mode 100644 index 0000000..58ad2e3 --- /dev/null +++ b/dwitter/dwitter/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for dwitter project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dwitter.settings") + +application = get_wsgi_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) diff --git a/dwitter/website/__init__.py b/dwitter/website/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dwitter/website/admin.py b/dwitter/website/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/dwitter/website/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/dwitter/website/migrations/0001_initial.py b/dwitter/website/migrations/0001_initial.py new file mode 100644 index 0000000..20bbbdc --- /dev/null +++ b/dwitter/website/migrations/0001_initial.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.contrib.auth.models +import django.utils.timezone +from django.conf import settings +import django.core.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0006_require_contenttypes_0002'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(null=True, verbose_name='last login', blank=True)), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, max_length=30, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username')), + ('first_name', models.CharField(max_length=30, verbose_name='first name', blank=True)), + ('last_name', models.CharField(max_length=30, verbose_name='last name', blank=True)), + ('email', models.EmailField(max_length=254, verbose_name='email address', blank=True)), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Permission', blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions')), + ], + options={ + 'abstract': False, + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + migrations.CreateModel( + name='Tweet', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('message', models.TextField(max_length=140, blank=True)), + ('timestamp', models.DateTimeField(auto_now_add=True)), + ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/dwitter/website/migrations/__init__.py b/dwitter/website/migrations/__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..cbc8590 --- /dev/null +++ b/dwitter/website/models.py @@ -0,0 +1,15 @@ +from django.db import models +from django.contrib.auth.models import AbstractUser + + +class User(AbstractUser): + pass + + +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 diff --git a/dwitter/website/templates/website/base.html b/dwitter/website/templates/website/base.html new file mode 100644 index 0000000..ef0d5db --- /dev/null +++ b/dwitter/website/templates/website/base.html @@ -0,0 +1,123 @@ + + +
+ +This is an opensource didactic project for learning Django step-by-step.
+