diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7ed556 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.py[co] +.idea/ +*/settings.py +db.sqlite3 diff --git a/README b/README new file mode 100644 index 0000000..24069ff --- /dev/null +++ b/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. diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/admin.py b/app/admin.py new file mode 100644 index 0000000..a5405b4 --- /dev/null +++ b/app/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from app.models import Customer + +admin.site.register(Customer) \ No newline at end of file diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..f6e96ff --- /dev/null +++ b/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'] \ No newline at end of file diff --git a/app/migrations/0001_initial.py b/app/migrations/0001_initial.py new file mode 100644 index 0000000..a52fa43 --- /dev/null +++ b/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,), + ), + ] diff --git a/app/migrations/0002_auto_20150106_2223.py b/app/migrations/0002_auto_20150106_2223.py new file mode 100644 index 0000000..965481d --- /dev/null +++ b/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, + ), + ] diff --git a/app/migrations/__init__.py b/app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..543b7de --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/templates/app/detail.html b/app/templates/app/detail.html new file mode 100644 index 0000000..eb1d2c5 --- /dev/null +++ b/app/templates/app/detail.html @@ -0,0 +1,7 @@ +{% if error_message %}

{{ error_message }}

{% endif %} + +
+ {% csrf_token %} + {{ form.as_p }} + +
\ No newline at end of file diff --git a/app/templates/app/index.html b/app/templates/app/index.html new file mode 100644 index 0000000..6f67ca6 --- /dev/null +++ b/app/templates/app/index.html @@ -0,0 +1,19 @@ +{% if customers_list %} +

Active

+ + +

Inactive

+ +{% endif %} \ No newline at end of file diff --git a/app/tests.py b/app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/app/urls.py b/app/urls.py new file mode 100644 index 0000000..860318c --- /dev/null +++ b/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\d+)/', views.CustomerUpdate.as_view(), name='detail'), +) \ No newline at end of file diff --git a/app/views.py b/app/views.py new file mode 100644 index 0000000..8f2a3f4 --- /dev/null +++ b/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" \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8a50ec0 --- /dev/null +++ b/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) diff --git a/mysite/__init__.py b/mysite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mysite/urls.py b/mysite/urls.py new file mode 100644 index 0000000..b8f3516 --- /dev/null +++ b/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)), +) diff --git a/mysite/wsgi.py b/mysite/wsgi.py new file mode 100644 index 0000000..15c7d49 --- /dev/null +++ b/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()