Skip to content

Commit

Permalink
Initial commit. Threw together a basic site based on a Customer model…
Browse files Browse the repository at this point in the history
… and related form, along with settings for email capability. Next step is email and formatting
  • Loading branch information
jfking committed Jan 8, 2015
0 parents commit 2796188
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.py[co]
.idea/
*/settings.py
db.sqlite3
12 changes: 12 additions & 0 deletions README
@@ -0,0 +1,12 @@
Rice Bikes Processing App
=========================

This site is built for use by the employees of Rice Bikes, the student-
run bike shop at Rice University.

Users can enter the information of a customer, including email address.
When the order is submitted, the customer will receive an email from
the bike shop confirming they have been processed. When the job is
finished, the emloyees can update the status to completed, and the
customer will receive an email notifying them that they can come in
and pick up their bike.
Empty file added app/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions app/admin.py
@@ -0,0 +1,4 @@
from django.contrib import admin
from app.models import Customer

admin.site.register(Customer)
8 changes: 8 additions & 0 deletions app/forms.py
@@ -0,0 +1,8 @@
from django.forms import ModelForm
from app.models import Customer


class CustomerForm(ModelForm):
class Meta:
model = Customer
fields = ['first_name', 'last_name', 'email', 'service_description','completed', 'date_submitted']
30 changes: 30 additions & 0 deletions app/migrations/0001_initial.py
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import app.models


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Customer',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('email', models.CharField(max_length=100, validators=[app.models.validate_email])),
('service_description', models.CharField(max_length=500)),
('price', models.IntegerField(default=0)),
('completed', models.BooleanField(default=False)),
('date_submitted', models.DateTimeField(verbose_name=b'date submitted')),
],
options={
},
bases=(models.Model,),
),
]
20 changes: 20 additions & 0 deletions app/migrations/0002_auto_20150106_2223.py
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

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

operations = [
migrations.AlterField(
model_name='customer',
name='date_submitted',
field=models.DateTimeField(verbose_name='date submitted'),
preserve_default=True,
),
]
Empty file added app/migrations/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions app/models.py
@@ -0,0 +1,22 @@
from django.db import models
from django.core.exceptions import ValidationError
import re


def validate_email(email_string):
possible_match = re.match(r'[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}', email_string)
if possible_match is None:
raise ValidationError(u'%s is not a valid email address' % email_string)


class Customer(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.CharField(max_length=100, validators=[validate_email])
service_description = models.CharField(max_length=500)
price = models.IntegerField(default=0)
completed = models.BooleanField(default=False)
date_submitted = models.DateTimeField('date submitted')

def __str__(self):
return self.first_name + " " + self.last_name
7 changes: 7 additions & 0 deletions app/templates/app/detail.html
@@ -0,0 +1,7 @@
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save" />
</form>
19 changes: 19 additions & 0 deletions app/templates/app/index.html
@@ -0,0 +1,19 @@
{% if customers_list %}
<h3>Active</h3>
<ul>
{% for customer in customers_list %}
{% if customer.completed == False %}
<li><a href="{% url 'app:detail' customer.id %}">{{ customer.first_name }} {{ customer.last_name }}</a></li>
{% endif %}
{% endfor %}
</ul>

<h3>Inactive</h3>
<ul>
{% for customer in customers_list %}
{% if customer.completed == True %}
<li><a href="{% url 'app:detail' customer.id %}">{{ customer.first_name }} {{ customer.last_name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
3 changes: 3 additions & 0 deletions app/tests.py
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions app/urls.py
@@ -0,0 +1,8 @@
from django.conf.urls import patterns, url

from app import views

urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'(?P<pk>\d+)/', views.CustomerUpdate.as_view(), name='detail'),
)
28 changes: 28 additions & 0 deletions app/views.py
@@ -0,0 +1,28 @@
from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from app.models import Customer
from django.core.urlresolvers import reverse_lazy
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView
from app.forms import CustomerForm


def index(request):
print "Index view"
customers_list = Customer.objects.order_by('date_submitted')
return render(request, 'app/index.html', {'customers_list': customers_list})


def detail(request, customer_id):
customer = get_object_or_404(Customer, pk=customer_id)
form = CustomerForm(instance=customer)
return render(request, 'app/detail.html', {
'customer': customer,
'form': form,
})


class CustomerUpdate(UpdateView):
model = Customer
fields = ['first_name', 'last_name', 'email', 'service_description', 'price', 'completed', 'date_submitted']
template_name = "app/detail.html"
success_url = "/app"
10 changes: 10 additions & 0 deletions manage.py
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Empty file added mysite/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions mysite/urls.py
@@ -0,0 +1,7 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
url(r'^app/', include('app.urls', namespace="app")),
url(r'^admin/', include(admin.site.urls)),
)
14 changes: 14 additions & 0 deletions mysite/wsgi.py
@@ -0,0 +1,14 @@
"""
WSGI config for mysite 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", "mysite.settings")

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

0 comments on commit 2796188

Please sign in to comment.