Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn squawker.wsgi --log-file -
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "squawker.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Django~=1.10.2
pep8~=1.7.0
pytest~=3.0.3
pytest-django~=3.0.0
pytest-json~=0.4.0
git+https://github.com/startup-systems/splinter.git@acfac451ee3943e1e155d06249f6ed0aa851b948#egg=splinter[django]
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.5.2
Empty file added squawker/__init__.py
Empty file.
133 changes: 133 additions & 0 deletions squawker/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""
Django settings for squawker project.

Generated by 'django-admin startproject' using Django 1.10.2.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os
# add this near the top
import dj_database_url

# replace the DATABASES config
DATABASES = {
"default": dj_database_url.config(default='sqlite:///db.sqlite3'),
}

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-s!g6(rvn$^4ut1bhht+2^mq!cxwc5@jz@*-qz(-cbjx0ff0c*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'squawker_app.apps.SquawkerAppConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'squawker.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 = 'squawker.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.10/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.10/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),)
Empty file added squawker/static/.keep
Empty file.
Empty file added squawker/static/empty.txt
Empty file.
22 changes: 22 additions & 0 deletions squawker/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""squawker URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/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. Import the include() function: from django.conf.urls import url, include
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'^', include('squawker_app.urls')),
url(r'^admin/', admin.site.urls)
]
16 changes: 16 additions & 0 deletions squawker/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for squawker 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.10/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "squawker.settings")

application = get_wsgi_application()
Empty file added squawker_app/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions squawker_app/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.
5 changes: 5 additions & 0 deletions squawker_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class SquawkerAppConfig(AppConfig):
name = 'squawker_app'
27 changes: 27 additions & 0 deletions squawker_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-11-01 03:33
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Squawks',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('squawk', models.CharField(max_length=140)),
('timestamp', models.DateTimeField(auto_now_add=True)),
],
options={
'ordering': ['-timestamp'],
},
),
]
19 changes: 19 additions & 0 deletions squawker_app/migrations/0002_auto_20161101_0416.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-11-01 04:16
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('squawker_app', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='squawks',
options={},
),
]
Empty file.
9 changes: 9 additions & 0 deletions squawker_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models


class Squawks(models.Model):
squawk = models.CharField(max_length=140)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.squawk
22 changes: 22 additions & 0 deletions squawker_app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<!DOCTYPE HTML>
<html>
<head>
<title>My Squawker Site</title>
</head>

<body>
<h1>Squawkers</h1>
<form action="{% url 'squawker:add'%}" method="post">
{% csrf_token %}
<textarea name="content" maxlength="140" placeholder="max length is 140 characters"></textarea>
<input type="submit">
<h2>Start squawking</h2>
<ul>
{% for s in past_squawks %}
<li>{{s.squawk}}</li>
{% endfor %}
<ul>
</form>
</body>
</html>
3 changes: 3 additions & 0 deletions squawker_app/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.
23 changes: 23 additions & 0 deletions squawker_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""squawker URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/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. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from . import views

app_name = 'squawker'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^add/$', views.add_squawker, name='add'),
]
20 changes: 20 additions & 0 deletions squawker_app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.shortcuts import render, get_object_or_404
from django.http import Http404
from django.http import HttpResponse
from django.views.generic import RedirectView
from .models import Squawks


def index(request):
context = {'past_squawks': Squawks.objects.order_by('-id')}
return render(request, 'index.html', context)


def add_squawker(request):
q = Squawks(squawk=request.POST['content'])
if len(q.squawk) > 140:
response = HttpResponse('Please enter less than 140 characters')
response.status_code = 400
return response
q.save()
return index(request)
2 changes: 1 addition & 1 deletion tests/test_squawker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_server_side_validation(browser):
TEXT = random_string(minlength=141, maxlength=200)
create_squawk(browser, TEXT)
# TODO ignore if it's in the `value` of the `<input>`
assert browser.is_text_not_present(TEXT)
assert browser.status_code.code == 400 or browser.is_text_not_present(TEXT)


@pytest.mark.score(2.5)
Expand Down