From 1bbfb4a44d42aca151f60a614ebeffbd44ef6e4d Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 27 Nov 2013 13:35:55 +0200 Subject: A bunch of fixes --- apps/docs/admin.py | 2 +- apps/issues/models.py | 8 ++++++ apps/issues/views.py | 77 +++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 74 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/docs/admin.py b/apps/docs/admin.py index 4902ccc..8ab5731 100644 --- a/apps/docs/admin.py +++ b/apps/docs/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from docs.models import Article, Image +from apps.docs.models import Article, Image admin.site.register(Article) admin.site.register(Image) diff --git a/apps/issues/models.py b/apps/issues/models.py index f2e162d..2306199 100644 --- a/apps/issues/models.py +++ b/apps/issues/models.py @@ -7,6 +7,7 @@ from apps.checkin.models import ServiceOrder class Issue(models.Model): sp = models.ForeignKey(ServiceProvider) + keywords = models.TextField(default='') description = models.CharField(max_length=256, default=_('No power')) def __unicode__(self): @@ -19,8 +20,15 @@ class Issue(models.Model): class Question(models.Model): issue = models.ForeignKey(Issue) question = models.CharField(max_length=256) + description = models.TextField(default='') required = models.BooleanField(default=True) + def next(self): + return Question.objects.get(issue=self.issue, pk__gt=self.pk) + + def prev(self): + return Question.objects.get(issue=self.issue, pk__lt=self.pk) + def __unicode__(self): return self.question diff --git a/apps/issues/views.py b/apps/issues/views.py index 374c74e..6bc6d75 100644 --- a/apps/issues/views.py +++ b/apps/issues/views.py @@ -1,20 +1,37 @@ from django import forms from gsxws import products -from django.shortcuts import render +from django.shortcuts import render, redirect from django.views.generic.list import ListView +from django.utils.translation import ugettext as _ from django.views.generic.edit import FormView, CreateView, UpdateView from apps.core.views import DefaultEditView, DefaultListView from apps.issues.models import Issue, Question, Choice +class WarrantyForm(forms.Form): + sn = forms.CharField( + required=False, + initial='DGKFL06JDHJP', + label=_('Serial number') + ) + + +class IssueForm(forms.Form): + description = forms.CharField( + required=False, + widget=forms.Textarea() + ) + attachment = forms.FileField(required=False) + + 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() + fname = forms.CharField(label=_('First name'), initial='Filipp') + lname = forms.CharField(label=_('Last name'), initial='Lepalaan') + email = forms.EmailField(label=_('Email'), initial='filipp@fps.ee') + phone = forms.CharField(label=_('Phone number'), initial='451202717') + address = forms.CharField(label=_('Address'), initial='Kustaankatu 2 C 96') + city = forms.CharField(label=_('City'), initial='Helsinki') + postal_code = forms.CharField(label=_('Postal code'), initial='00500') class IssueListView(DefaultListView): @@ -32,28 +49,64 @@ class IssueEditView(DefaultEditView): def welcome(request): + form = WarrantyForm() return render(request, "issues/welcome.html", locals()) +def details(request, device=None): + form = IssueForm() + + if request.method == "POST": + request.session['details'] = request.POST.get('details') + return redirect(list_issues) + + return render(request, "issues/details.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()) + + if idx is None: + question = questions[0] + request.session['choices'] = [] + else: + choice = Choice.objects.get(pk=idx) + current = questions.get(choice=idx) + current.choice = choice + request.session['choices'].append(current) + try: + question = current.next() + except Question.DoesNotExist: + return redirect(customer) + + dump = request.session.get('choices') + return render(request, "issues/question.html", locals()) def choose_device(request, device=None): models = products.models() - return render(request, "issues/device.html", locals()) + tpl = "issues/%s.html" % (device or 'device') + return render(request, tpl, locals()) def warranty(request): return render(request, "issues/warranty.html", locals()) +def thanks(request): + return render(request, "issues/thanks.html", locals()) + + def customer(request): form = CustomerForm() if request.method == "POST": form = CustomerForm(request.POST) + if form.is_valid(): + return redirect(thanks) return render(request, "issues/customer.html", locals()) + + +def restart(request): + request.session = None + return redirect(welcome) -- cgit v1.2.3