Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions _chapters/chp03/django_ecommerce/main/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,40 @@ def test_index_handles_logged_in_user(self):
'user.html', {'user': user_mock.get_by_id(1)}
)
self.assertEquals(resp.content, expected_html.content)



class User(models.Model):

name = model.CharField()
pwd = model.CharField()
birthdate = model.DateField()

def get_sign():
if birthdate.month == "Jan":
return "Capricorn"
elif birthdate.monty == "Feb"
return "Sagitarius"

def is_active_twitter_user():
# call twitter with
# is user.name a user on twitter
is_active = twitter.check_user(user.name)
return is_active


def test_get_sign()
myuser = User("jj", "pwd", "Jan")
self.assertEquals(myuser.get_sign(), "Capricorn")

myuser = User("jj", "pwd", "Feb")
self.assertEquals(myuser.get_sign(), "Sagitarius")

myuser = User("jj", "pwd", "32")
self.assertEquals(myuser.get_sign(), "Sagitarius")




--- test.py

Binary file modified _chapters/chp03/django_ecommerce/test.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-20 15:07
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='ContactForm',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('email', models.EmailField(max_length=250)),
('topic', models.CharField(max_length=200)),
('message', models.CharField(max_length=1000)),
('timestamp', models.DateTimeField(auto_now_add=True)),
],
options={
'ordering': ['-timestamp'],
},
),
]
7 changes: 2 additions & 5 deletions _chapters/chp06/django_ecommerce/contact/models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from django.db import models
import datetime


class ContactForm(models.Model):
name = models.CharField(max_length=150)
email = models.EmailField(max_length=250)
topic = models.CharField(max_length=200)
message = models.CharField(max_length=1000)
timestamp = models.DateTimeField(
auto_now_add=True, default=datetime.datetime.now
)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
def __unicode__(self):
return self.email

class Meta:
Expand Down
37 changes: 19 additions & 18 deletions _chapters/chp06/django_ecommerce/django_ecommerce/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
SITE_ROOT = os.path.dirname(PROJECT_ROOT)
STRIPE_SECRET = 'sk_test_4QBquf6d5EzsnJC1fTI2GBGm'
STRIPE_PUBLISHABLE = 'pk_test_4QBqqGvCk9gaNn3pl1cwxcAS'

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
Expand All @@ -19,12 +16,8 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db',
'USER': 'djangousr',
'PASSWORD': 'your_password_here',
'HOST': 'localhost',
'PORT': '5432',
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db'
}
}

Expand Down Expand Up @@ -88,13 +81,6 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = '!(1ty%c5a)0l0(p)kxl2igmbobx_64hqh&tv1=+s9@!@zez4o^'

# 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',
Expand All @@ -111,8 +97,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'django_ecommerce.wsgi.application'

TEMPLATE_DIRS = (os.path.join(SITE_ROOT, 'templates'),)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -157,3 +141,20 @@
},
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(SITE_ROOT, 'templates'),],
'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',
],
'debug': True,
},
},
]
13 changes: 8 additions & 5 deletions _chapters/chp06/django_ecommerce/django_ecommerce/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from payments import views
from django.contrib import admin
from main.views import index as main_index
from contact.views import contact

admin.autodiscover()

urlpatterns = patterns('',
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'main.views.index', name='home'),
url(r'^$', main_index, name='home'),
url(r'^pages/', include('django.contrib.flatpages.urls')),
url(r'^contact/', 'contact.views.contact', name='contact'),
url(r'^contact/', contact, name='contact'),

# user registration/authentication
url(r'^sign_in$', views.sign_in, name='sign_in'),
url(r'^sign_out$', views.sign_out, name='sign_out'),
url(r'^register$', views.register, name='register'),
url(r'^edit$', views.edit, name='edit'),
)
]
Loading