From 8782fbe4766dc57e517eec622879d672d6d68378 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 19 Nov 2013 16:44:56 +0200 Subject: switch --- apps/core/admin.py | 3 ++- apps/issues/admin.py | 6 ++++++ apps/issues/models.py | 6 ++++++ apps/issues/views.py | 46 +++++++++++++++++++++++++++++++++++------- motor/settings.py | 2 +- motor/urls.py | 13 +++++++++--- templates/issues/customer.html | 13 ++++++++++++ templates/issues/device.html | 7 +++++++ templates/issues/index.html | 6 +++--- templates/issues/thanks.html | 0 templates/issues/warranty.html | 28 +++++++++++++++++++++++++ templates/issues/welcome.html | 15 ++++++++++++++ 12 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 apps/issues/admin.py create mode 100644 templates/issues/customer.html create mode 100644 templates/issues/device.html create mode 100644 templates/issues/thanks.html create mode 100644 templates/issues/warranty.html create mode 100644 templates/issues/welcome.html diff --git a/apps/core/admin.py b/apps/core/admin.py index 8c38f3f..35ea185 100644 --- a/apps/core/admin.py +++ b/apps/core/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin +from apps.core.models import ServiceProvider -# Register your models here. +admin.site.register(ServiceProvider) diff --git a/apps/issues/admin.py b/apps/issues/admin.py new file mode 100644 index 0000000..5d91777 --- /dev/null +++ b/apps/issues/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from apps.issues.models import Issue, Question, Choice + +admin.site.register(Issue) +admin.site.register(Question) +admin.site.register(Choice) diff --git a/apps/issues/models.py b/apps/issues/models.py index bcded0c..f2e162d 100644 --- a/apps/issues/models.py +++ b/apps/issues/models.py @@ -21,11 +21,17 @@ class Question(models.Model): question = models.CharField(max_length=256) required = models.BooleanField(default=True) + def __unicode__(self): + return self.question + class Choice(models.Model): question = models.ForeignKey(Question) choice = models.CharField(max_length=256) + def __unicode__(self): + return self.choice + class Answer(models.Model): choice = models.ForeignKey(Choice) diff --git a/apps/issues/views.py b/apps/issues/views.py index 565bc6e..374c74e 100644 --- a/apps/issues/views.py +++ b/apps/issues/views.py @@ -1,9 +1,20 @@ -import json +from django import forms +from gsxws import products from django.shortcuts import render from django.views.generic.list import ListView from django.views.generic.edit import FormView, CreateView, UpdateView from apps.core.views import DefaultEditView, DefaultListView -from apps.issues.models import Issue +from apps.issues.models import Issue, Question, Choice + + +class CustomerForm(forms.Form): + fname = forms.CharField() + lname = forms.CharField() + email = forms.EmailField() + phone = forms.CharField() + address = forms.CharField() + city = forms.CharField() + postal_code = forms.CharField() class IssueListView(DefaultListView): @@ -20,8 +31,29 @@ class IssueEditView(DefaultEditView): model = Issue -def list_issues(request, idx=0): - fh = open('fixtures.json', 'r') - data = json.loads(fh.read()) - question = data['questions'][int(idx)] - return render(request, "issues/index.html", question) +def welcome(request): + return render(request, "issues/welcome.html", locals()) + + +def list_issues(request, idx=None): + questions = Question.objects.filter(issue__sp_id=1) + question = questions[0] + dump = {} + return render(request, "issues/index.html", locals()) + + +def choose_device(request, device=None): + models = products.models() + return render(request, "issues/device.html", locals()) + + +def warranty(request): + return render(request, "issues/warranty.html", locals()) + + +def customer(request): + form = CustomerForm() + if request.method == "POST": + form = CustomerForm(request.POST) + + return render(request, "issues/customer.html", locals()) diff --git a/motor/settings.py b/motor/settings.py index 612efee..c752b59 100644 --- a/motor/settings.py +++ b/motor/settings.py @@ -127,7 +127,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: - #'django.contrib.admin', + 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'bootstrap3', diff --git a/motor/urls.py b/motor/urls.py index 9ec4845..394a7fd 100644 --- a/motor/urls.py +++ b/motor/urls.py @@ -3,11 +3,18 @@ from django.views.generic import TemplateView from apps.core.views import * from apps.issues.views import * +from django.contrib import admin +admin.autodiscover() + urlpatterns = patterns( '', #url(r'^$', 'docs.views.index', name='docs-index'), - url(r'^$', list_issues, name='issues-index'), - url(r'^(\d+)/$', list_issues, name='issues-index'), + url(r'^$', welcome, name='issues-welcome'), + url(r'^issues/(\d+)/$', list_issues, name='issues-index'), + url(r'^issues/device/$', choose_device, name='issues-choose_device'), + url(r'^issues/device/([A-Z]+)/$', choose_device, name='issues-choose_device'), + url(r'^issues/warranty/$', warranty, name='issues-warranty'), + url(r'^issues/customer/$', customer, name='issues-customer'), url(r'^manage/$', LoginView.as_view(), name='core-login'), url(r'^manage/logout/$', logout, name='core-logout'), url(r'^manage/docs/$', ArticleListView.as_view(), name='core-list_docs'), @@ -23,6 +30,6 @@ urlpatterns = patterns( url(r'^manage/issues/add/$', IssueCreateView.as_view(), name='issues-add_issue'), url(r'^manage/issues/(?P\d+)/$', IssueEditView.as_view(), name='issues-edit_issue'), url(r'^terms/$', TemplateView.as_view(template_name="terms.html"), {'title': 'ServoApp Terms of Service'}), - #(r'^admin/', include(admin.site.urls)), + (r'^admin/', include(admin.site.urls)), #url(r'^([\w\-]+)/$', 'docs.views.view_article', name='docs-view'), ) diff --git a/templates/issues/customer.html b/templates/issues/customer.html new file mode 100644 index 0000000..a47ba32 --- /dev/null +++ b/templates/issues/customer.html @@ -0,0 +1,13 @@ +{% extends "issues/index.html" %} +{% load bootstrap3 %} +{% load i18n %} + +{% block main %} +
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + + {% endbuttons %} +
+{% endblock main %} diff --git a/templates/issues/device.html b/templates/issues/device.html new file mode 100644 index 0000000..def5b8b --- /dev/null +++ b/templates/issues/device.html @@ -0,0 +1,7 @@ +{% extends "issues/index.html" %} + +{% block main %} + {% for k, v in models.items %} + {{ v.name }} + {% endfor %} +{% endblock main %} diff --git a/templates/issues/index.html b/templates/issues/index.html index 15b341f..70a84e7 100644 --- a/templates/issues/index.html +++ b/templates/issues/index.html @@ -14,11 +14,11 @@ - +
{% block main %} -

{{ question }}

- {% for i in choices %} +

{{ question.question }}

+ {% for i in question.choice_set.all %} {{ i.choice }} {% endfor %}
{{ dump }}
diff --git a/templates/issues/thanks.html b/templates/issues/thanks.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/issues/warranty.html b/templates/issues/warranty.html new file mode 100644 index 0000000..b944ea5 --- /dev/null +++ b/templates/issues/warranty.html @@ -0,0 +1,28 @@ +{% extends "issues/index.html" %} +{% load i18n %} + +{% block main %} +
+
+ iMac (27-inch, Mid 2011) +
+
+

iMac (27-inch, Mid 2011)

+
+
{% trans "Warranty" %}
+
Out Of Warranty (No Coverage)
+
{% trans "Purchased" %}
+
2.6.2011, Sweden
+
{% trans "Serial Number" %}
+
DGKFL06JDHJP
+
{% trans "Configuration" %}
+
IMAC 27"/2.7QC/2X2GB/1TB/6770M
+
+
+
+ +{% endblock main %} diff --git a/templates/issues/welcome.html b/templates/issues/welcome.html new file mode 100644 index 0000000..38c0dcd --- /dev/null +++ b/templates/issues/welcome.html @@ -0,0 +1,15 @@ +{% extends "issues/index.html" %} +{% load i18n %} + +{% block main %} +
+ {% csrf_token %} +
+ + +
+ +
+{% endblock main %} -- cgit v1.2.3