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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
to_do/dbs
to_do/djtp_virtualenv
to_do/sockets
to_do/source/static
*.pyc
*.swp*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This test includes two parts.
all unfinished todos. Additionally, you should be able to mark a todo item
as done.

This is found in the 'to_do' directory.


2) Write a stand alone Python script that creates word clouds. To do this,
you'll first need to build the data. Write code that takes a long string and
Expand All @@ -33,3 +35,5 @@ This test includes two parts.
```

You may assume the input will only contain words and standard punctuation.

This is found in the 'word_cloud' directory.
31 changes: 31 additions & 0 deletions to_do/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Requirments for django_test project (djtp)
==========================================

### Project Directory Structure:

<pre>
/some/path/to/django_test/
logs/ - place any logs here (git ignored)
djtp_virutalenv/ - virtualenv should be installed here (git ignored)
source/ - django project lives here
socket/ - if you are using gunicorn, place its socketfile here (git ignored)
docs/ - let people know the good things you have done
dbs/ - put your local databases here (git ignored)
</pre>

### Python OS Packages:
* pip
* virtualenv

### Virtualenv Packages:
* django
* pep8
* pylint

> requirments.txt lives in docs/

### Project Dependancies:
https://github.com/twbs/bootstrap/releases/download/v3.3.2/bootstrap-3.3.2-dist.zip

> extract into 'source/static'

3 changes: 3 additions & 0 deletions to_do/docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
django
pep8
pylint
Empty file added to_do/source/ToDo/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions to_do/source/ToDo/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.
18 changes: 18 additions & 0 deletions to_do/source/ToDo/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
We need a form for created for the todos
"""
from django import forms
from .models import ToDo


class ToDoForm(forms.ModelForm):
""" Only want to set the ccs controls. """

todo = forms.CharField(widget=forms.Textarea(
attrs={'cols': 10, 'rows': 5, 'class': 'form-control'}
))

class Meta:
""" Meta options go here. """
model = ToDo
exclude = ('created', 'compleated')
25 changes: 25 additions & 0 deletions to_do/source/ToDo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='ToDo',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateField(auto_now_add=True)),
('todo', models.TextField()),
('compleated', models.DateField(auto_now=True, null=True)),
],
options={
},
bases=(models.Model,),
),
]
Empty file.
16 changes: 16 additions & 0 deletions to_do/source/ToDo/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Models for the ToDo app.
"""
from django.db import models
from django.core.urlresolvers import reverse


class ToDo(models.Model):
""" Main Model. """
created = models.DateField(auto_now_add=True, editable=False)
todo = models.TextField()
compleated = models.DateField(editable=False, null=True)

def get_absolute_url(self):
""" what is my name again? """
return reverse('todo:todo-list')
15 changes: 15 additions & 0 deletions to_do/source/ToDo/templates/ToDo/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% load staticfiles %}
<html>
<head>
<link href="{% static 'bootstrap/css/bootstrap.min.css' %}"
rel="stylesheet" media="screen">
</head>

<body>
<div class="container">
{% block content %}
{% endblock %}
</div>
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions to_do/source/ToDo/templates/ToDo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'ToDo/base.html' %}

{% block content %}
<div class="row">
<h1 class="col-xs-6">Your ToDo's</h1>
</div>

<div class="row">
<ul>
<div class="col-xs-4">
{% for todo in object_list %}
<li>{{ todo.created }}: {{ todo.todo }} : <a href={% url 'todo:todo-done' todo.id %}>done</a></li>
{% endfor %}
</div>
</ul>
</div>

<div class="row">
&nbsp;<!--wanted a filler row-->
</div>

<div class="row">
<div class="col-xs-6">
<a href="{% url 'todo:todo-add' %}">add ToDo</a>
</div>
</div>

{% endblock %}
18 changes: 18 additions & 0 deletions to_do/source/ToDo/templates/ToDo/todo_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'ToDo/base.html' %}

{% block content %}
<div class="row">
<h1 class="col-xs-6">New ToDo</h1>
</div>

<div class="row">
<form action="" method="post" class="form-horizontal">{% csrf_token %}
<div class="form-group">
<div class="col-xs-4 col-md-offset-1">
{{ form.as_p }}
<input type="submit" value="Create" />
</div>
</div>
</form>
</div>
{% endblock %}
3 changes: 3 additions & 0 deletions to_do/source/ToDo/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.
8 changes: 8 additions & 0 deletions to_do/source/ToDo/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf.urls import patterns, url
from .views import ToDoCreate, ToDoDone, ToDoList

urlpatterns = patterns('',
url(r'^$', ToDoList.as_view(), name='todo-list',),
url(r'^add$', ToDoCreate.as_view(), name='todo-add',),
url(r'^done/(?P<pk>\d+)/$', ToDoDone.as_view(), name='todo-done',),
)
40 changes: 40 additions & 0 deletions to_do/source/ToDo/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Here are the ToDo views.
I Chose to go with class based views as they are bit more difficult to
build and manage.
"""
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic import ListView
from django.core.urlresolvers import reverse_lazy, reverse
from django.http import HttpResponseRedirect
from datetime import datetime
from .models import ToDo
from .forms import ToDoForm


class ToDoCreate(CreateView):
""" Lets create a todo. """
model = ToDo
form_class = ToDoForm
success_url = reverse_lazy('todo:todo-list')


class ToDoDone(UpdateView):
""" Lets mark a todo as done. """
model = ToDo
fields = []
success_url = reverse_lazy('todo:todo-list')

def get(self, request, *args, **kwargs):
""" Over rideing 'get' to mark the todo done from a get. """
super(ToDoDone, self).get(request, *args, **kwargs)
self.object = self.get_object()
self.object.compleated = datetime.now()
self.object.save()
return HttpResponseRedirect(reverse('todo:todo-list'))


class ToDoList(ListView):
""" Lets list it out baby! """
template_name = 'ToDo/index.html'
queryset = ToDo.objects.filter(compleated__isnull=True)
10 changes: 10 additions & 0 deletions to_do/source/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", "source.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Empty file added to_do/source/source/__init__.py
Empty file.
89 changes: 89 additions & 0 deletions to_do/source/source/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
Django settings for source project.

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

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

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJ_DIR = os.path.dirname(BASE_DIR)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3@vvz2a7d0s$s!uwzxam=#r=j9bfech5@3rn(l#90tkr-yftvh'

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

TEMPLATE_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',
'django_extensions',
'ToDo',
)

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',
)

ROOT_URLCONF = 'source.urls'

WSGI_APPLICATION = 'source.wsgi.application'


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

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

# Internationalization
# https://docs.djangoproject.com/en/1.7/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.7/howto/static-files/

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

STATIC_URL = '/static/'
7 changes: 7 additions & 0 deletions to_do/source/source/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
url(r'^', include('ToDo.urls', namespace='todo')),
url(r'^admin/', include(admin.site.urls)),
)
14 changes: 14 additions & 0 deletions to_do/source/source/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
WSGI config for source 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.7/howto/deployment/wsgi/
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "source.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Loading