Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
cadc3ba
Create django project
jorgebastida Apr 22, 2012
ce1497a
Create first view
jorgebastida Apr 22, 2012
40ac624
Create first template
jorgebastida Apr 22, 2012
2ebf5f4
Use template tags
jorgebastida Apr 22, 2012
82a67e4
Use filters
jorgebastida Apr 22, 2012
c222b41
Fix tweets list
jorgebastida Apr 22, 2012
89a94f4
Merge branch 'step-02-firsttemplate' into step-03-tags
jorgebastida Apr 22, 2012
c83ca9e
Merge branch 'step-03-tags' into step-04-filters
jorgebastida Apr 22, 2012
a8ee04e
Inherit from base.html
jorgebastida Apr 22, 2012
790f873
Create Tweet model
Apr 22, 2012
648d1f3
Add 'ago' to the template
jorgebastida Apr 22, 2012
cf25b0d
Merge branch 'step-04-filters' into step-05-inheritance
jorgebastida Apr 22, 2012
9a414cd
Merge branch 'step-05-inheritance' into step-06-firstmodel
Apr 22, 2012
a0e55b0
Add bootstrap to base.html
jorgebastida Apr 22, 2012
f9232df
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 22, 2012
5819b63
Add textarea styles
jorgebastida Apr 22, 2012
a0bfe1d
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 22, 2012
3a247b7
Add styles to blockquote
jorgebastida Apr 23, 2012
1be38aa
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 23, 2012
621b5dc
Fix timeline links and remove users one
jorgebastida Apr 29, 2012
76d4fee
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 29, 2012
5a691a9
Fix timeline link
jorgebastida Apr 29, 2012
11a1e14
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 29, 2012
25f4bc4
Add useful information to the sidebar
jorgebastida Apr 29, 2012
3d4940d
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 29, 2012
a569b23
Add a separator
jorgebastida Apr 29, 2012
b515c59
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Apr 29, 2012
8b02367
Add .DS_Store to .gitignore
jorgebastida May 6, 2012
e33d1cb
Merge branch 'step-00-startproject' into step-01-views
jorgebastida May 6, 2012
96673a9
Merge branch 'step-01-views' into step-02-templates
jorgebastida May 6, 2012
88f6bde
Merge branch 'step-02-templates' into step-03-tags
jorgebastida May 6, 2012
a80b42f
Merge branch 'step-03-tags' into step-04-filters
jorgebastida May 6, 2012
48f51e0
Merge branch 'step-04-filters' into step-05-inheritance
jorgebastida May 6, 2012
a726c46
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida May 6, 2012
8495273
Merge branch 'master' into step-00-startproject
jaimeirurzun Sep 29, 2013
d225a3b
Merge branch 'step-00-startproject' into step-01-views
jaimeirurzun Sep 29, 2013
9b55ddf
Merge branch 'step-01-views' into step-02-templates
jaimeirurzun Sep 29, 2013
c1637c7
Merge branch 'step-02-templates' into step-03-tags
jaimeirurzun Sep 29, 2013
afe0b6f
Merge branch 'step-03-tags' into step-04-filters
jaimeirurzun Sep 29, 2013
cf207e9
Merge branch 'step-04-filters' into step-05-inheritance
jaimeirurzun Sep 29, 2013
44aa83f
Merge branch 'step-05-inheritance' into step-06-models
jaimeirurzun Sep 29, 2013
8668f32
Fix link to bootstrap's css
jaimeirurzun Oct 9, 2013
7ab0e11
Merge branch 'step-05-inheritance' into step-06-models
jaimeirurzun Oct 9, 2013
49be31f
Merge branch 'master' into step-00-startproject
jorgebastida Oct 11, 2015
690d0d8
Merge branch 'step-00-startproject' into step-01-views
jorgebastida Oct 11, 2015
cbeca04
Merge branch 'step-01-views' into step-02-templates
jorgebastida Oct 11, 2015
123b4e0
Merge branch 'step-02-templates' into step-03-tags
jorgebastida Oct 11, 2015
409ca4f
Merge branch 'step-03-tags' into step-04-filters
jorgebastida Oct 11, 2015
03d4fcc
Merge branch 'step-04-filters' into step-05-inheritance
jorgebastida Oct 11, 2015
46b3652
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Oct 11, 2015
a29b9a0
Update base project to django 1.8
jorgebastida Oct 11, 2015
f210516
Update to django 1.8
jorgebastida Oct 11, 2015
fd38e28
Merge branch 'step-01-views' into step-02-templates
jorgebastida Oct 11, 2015
caec107
Merge branch 'step-02-templates' into step-03-tags
jorgebastida Oct 11, 2015
da4bfd7
Merge branch 'step-03-tags' into step-04-filters
jorgebastida Oct 11, 2015
8edbc8f
Merge branch 'step-04-filters' into step-05-inheritance
jorgebastida Oct 11, 2015
47bb5e4
Update to django 1.8
jorgebastida Oct 11, 2015
866dc72
Update to django 1.8
jorgebastida Oct 11, 2015
687dd27
Update to django 1.8
jorgebastida Oct 11, 2015
7f26eb0
Merge branch 'step-02-templates' into step-03-tags
jorgebastida Oct 11, 2015
e87d44a
Merge branch 'step-03-tags' into step-04-filters
jorgebastida Oct 11, 2015
37bb840
Merge branch 'step-04-filters' into step-05-inheritance
jorgebastida Oct 11, 2015
c3a2b90
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Oct 11, 2015
59a4476
Update base template to django 1.8
jorgebastida Oct 11, 2015
a83af6d
Merge branch 'step-05-inheritance' into step-06-models
jorgebastida Oct 11, 2015
1b9cc55
Add initial migrations for Tweet
jorgebastida Oct 11, 2015
f66728c
Add custom user
jorgebastida Oct 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.pyc
.DS_Store
db.sqlite3
Empty file added dwitter/dwitter/__init__.py
Empty file.
105 changes: 105 additions & 0 deletions dwitter/dwitter/settings.py
Original file line number Diff line number Diff line change
@@ -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'
22 changes: 22 additions & 0 deletions dwitter/dwitter/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
]
16 changes: 16 additions & 0 deletions dwitter/dwitter/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions dwitter/manage.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file added dwitter/website/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions dwitter/website/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
53 changes: 53 additions & 0 deletions dwitter/website/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
Empty file.
15 changes: 15 additions & 0 deletions dwitter/website/models.py
Original file line number Diff line number Diff line change
@@ -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
123 changes: 123 additions & 0 deletions dwitter/website/templates/website/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>dwitter</title>
<meta name="description" content="">
<meta name="author" content="enjoydjango.com">

<link href="https://rawgithub.com/twbs/bootstrap/v2.3.2/docs/assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px;
padding-bottom: 40px;
}
h1{
margin-bottom:20px;
}
blockquote p {
font-size:50px;
line-height:50px;
text-align:;
}
blockquote small {
font-size:20px;
line-height:20px;
margin-top:5px;
}
.tweets{
margin:0px;
list-style-type: none;
}
.tweets strong{
display: block;
}
.tweets em{
font-style:italic;
}
.tweets li{
border-bottom:1px dotted #ddd;
margin-bottom:10px;
padding-bottom:10px;
}
.container textarea{
width:100%;
height:100px;
}
</style>

</head>

<body>

<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/">dwitter</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="/">Timeline</a></li>
</ul>
</div>
</div>
</div>
</div>

<div class="container">

<div class="row">
<div class="span8">
{% block content %}{% endblock %}
</div>
<div class="span4">
{% block sidebar %}{% endblock %}
<hr/>
<h4>Welcome to dwitter!</h4>
<p>This is an opensource didactic project for learning <a href="https://www.djangoproject.com/">Django</a> step-by-step.</p>
<h5>Resources</h5>
<ul>
<li><a href="https://github.com/enjoydjango/dwitter">Github Repository</a></li>
<li><a href="https://docs.djangoproject.com/en/1.8/">Django 1.8 docs</a></li>
<li><a href="http://rogerdudler.github.com/git-guide/">Git - the simple guide</a></li>
</ul>

<h5>Solutions</h5>
<ul>
<li>Step #1 - views (<a href='https://github.com/enjoydjango/dwitter/compare/step-00-startproject...step-01-views'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-01-views'>targz</a>)</li>
<li>Step #2 - templates (<a href='https://github.com/enjoydjango/dwitter/compare/step-01-views...step-02-templates'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-02-templates'>targz</a>)</li>
<li>Step #3 - tags (<a href='https://github.com/enjoydjango/dwitter/compare/step-02-templates...step-03-tags'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-03-tags'>targz</a>)</li>
<li>Step #4 - filters (<a href='https://github.com/enjoydjango/dwitter/compare/step-03-tags...step-04-filters'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-04-filters'>targz</a>)</li>
<li>Step #5 - inheritance (<a href='https://github.com/enjoydjango/dwitter/compare/step-04-filters...step-05-inheritance'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-05-inheritance'>targz</a>)</li>
<li>Step #6 - models (<a href='https://github.com/enjoydjango/dwitter/compare/step-05-inheritance...step-06-models'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-06-models'>targz</a>)</li>
<li>Step #7 - database (<a href='https://github.com/enjoydjango/dwitter/compare/step-06-models...step-07-database'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-07-database'>targz</a>)</li>
<li>Step #8 - tweetpage (<a href='https://github.com/enjoydjango/dwitter/compare/step-07-database...step-08-tweetpage'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-08-tweetpage'>targz</a>)</li>
<li>Step #9 - profile (<a href='https://github.com/enjoydjango/dwitter/compare/step-08-tweetpage...step-09-profile'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-09-profile'>targz</a>)</li>
<li>Step #10 - followers (<a href='https://github.com/enjoydjango/dwitter/compare/step-09-profile...step-10-followers'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-10-followers'>targz</a>)</li>
<li>Step #11 - admin (<a href='https://github.com/enjoydjango/dwitter/compare/step-10-followers...step-11-admin'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-11-admin'>targz</a>)</li>
<li>Step #12 - userpage (<a href='https://github.com/enjoydjango/dwitter/compare/step-11-admin...step-12-userpage'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-12-userpage'>targz</a>)</li>
<li>Step #13 - reverse (<a href='https://github.com/enjoydjango/dwitter/compare/step-12-userpage...step-13-reverse'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-13-reverse'>targz</a>)</li>
<li>Step #14 - forms (<a href='https://github.com/enjoydjango/dwitter/compare/step-13-reverse...step-14-forms'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-14-forms'>targz</a>)</li>
<li>Step #15 - userslist (<a href='https://github.com/enjoydjango/dwitter/compare/step-14-forms...step-15-userslist'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-15-userslist'>targz</a>)</li>
<li>Step #16 - login (<a href='https://github.com/enjoydjango/dwitter/compare/step-15-userslist...step-16-login'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-16-login'>targz</a>)</li>
<li>Step #17 - contextprocessors (<a href='https://github.com/enjoydjango/dwitter/compare/step-16-login...step-17-contextprocessors'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-17-contextprocessors'>targz</a>)</li>
<li>Step #18 - customfilter (<a href='https://github.com/enjoydjango/dwitter/compare/step-17-contextprocessors...step-18-customfilter'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-18-customfilter'>targz</a>)</li>
<li>Step #19 - customtag (<a href='https://github.com/enjoydjango/dwitter/compare/step-18-customfilter...step-19-customtag'>diff</a> | <a href='https://github.com/enjoydjango/dwitter/zipball/step-19-customtag'>targz</a>)</li>
</ul>
</div>
</div>

<hr>

<footer>
<p>dwitter from <a href="http://enjoydjango.com">enjoydjango.com</a></p>
</footer>

</div>

</body>
</html>
14 changes: 14 additions & 0 deletions dwitter/website/templates/website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "website/base.html" %}


{% block content %}
<h1>Timeline</h1>
<ul class="tweets">
{% for tweet in tweets %}
<li><strong>@{{ tweet.user_name }}</strong>{{ tweet.message|lower|capfirst|urlize }} <em>({{ tweet.timestamp|timesince }} ago)</em></li>
{% empty %}
No tweets in this timeline!
{% endfor %}
</ul>

{% endblock %}
3 changes: 3 additions & 0 deletions dwitter/website/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
13 changes: 13 additions & 0 deletions dwitter/website/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

from datetime import datetime
from django.shortcuts import render
from django.http import HttpResponse

tweets = [
{'user_name':'jorgebastida', 'message': 'Hello world!', '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()}
]

def timeline(request):
return render(request, 'website/index.html', {'tweets': tweets})