Commits

Anonymous committed 35799a6

error messages for each field

Comments (0)

Files changed (6)

 # -*- coding: utf-8 -*-
 from django import forms
+from django.forms.util import ErrorList
 from django.contrib.formtools.preview import FormPreview,AUTO_ID
 from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
 from django.template.context import RequestContext
 
 import re
+import datetime
 
 from djcube.models import DtbCustomer
 
     def post_post(self, request):
         "Validates the POST data. If valid, calls done(). Else, redisplays form."
         f = self.form(request.POST, auto_id=AUTO_ID)
+        
         reedit = False 
         if request.POST.has_key('action') and request.POST['action'] in self.reedit_action: 
             reedit = True
 
 
 class SignupForm(forms.ModelForm):
+    email_confirm = forms.CharField(widget=forms.widgets.Input)
+    password = forms.CharField(widget=forms.PasswordInput )
+    password_confirm = forms.CharField(widget=forms.PasswordInput )
+
+    def is_valid(self):
+        valid = super(SignupForm,self).is_valid()
+        if self.data[u'password'] != self.data[u'password_confirm']  :
+            self._errors[u'password_confirm'] = ErrorList([u'パスワードが一致しません'])
+            valid = False
+
+        if self.data[u'email'] != self.data[u'email_confirm'] :
+            self._errors[u'email_confirm'] = ErrorList([u'メールアドレスが一致しません'])
+            valid = False
+        return valid 
+
     class Meta:
         model = DtbCustomer
-
+        exclude = ['create_date','update_date','secret_key','status','del_flg',]
 
 class SignupFormPreview(EditableFormPreview):
     preview_template = 'djcube/signup_preview.html'
         # Do something with the cleaned_data, then redirect
         # to a "success" page.
         params = cleaned_data.copy()
+        del params['email_confirm']
+        del params['password_confirm']
         params.update(self.kwargs)
         m  =  self.form._meta.model(**params)
         m.register()
         m.save()
-#        print "***",str(type(ret)),dir(ret)
         return HttpResponseRedirect('/')
 #
 
     )
 
 MAILMAG_FLAG_CHOICE = (
-    (1,'HTMLメール'),
-    (2,'テキストメール'),
-    (3,'希望しない'),
+    ('1','HTMLメール'),
+    ('2','テキストメール'),
+    ('3','希望しない'),
     )
 
 STATUS_CHOICE = (
-    (1,'仮会員'), 
-    (2,'本会員'),
+    ('1','仮会員'), 
+    ('2','本会員'),
     )
 
 SEX_CHOICE = (
-    (1,'男性'),
-    (2,'女性'),
+    ('1','男性'),
+    ('2','女性'),
     )
 
 JOB_CHOICE = (
 class DtbCustomer(models.Model):
     # EC-CUBE required field
     customer_id = models.AutoField(primary_key=True)
-    name01 = models.TextField(help_text=u'お名前:姓')
-    name02 = models.TextField(help_text=u'お名前:名')
-    kana01 = models.TextField(help_text=u'お名前(フリガナ):セイ')
-    kana02 = models.TextField(help_text=u'お名前(フリガナ):メイ')
-    zip01 = models.TextField(help_text=u'郵便番号:〒',blank=True)
-    zip02 = models.TextField(help_text=u'郵便番号:ー',blank=True)
+    name01 = models.CharField(help_text=u'お名前:姓',max_length=30)
+    name02 = models.CharField(help_text=u'お名前:名',max_length=30)
+    kana01 = models.CharField(help_text=u'お名前(フリガナ):セイ',max_length=30)
+    kana02 = models.CharField(help_text=u'お名前(フリガナ):メイ',max_length=30)
+    zip01 = models.CharField(help_text=u'郵便番号:〒',blank=True,max_length=3)
+    zip02 = models.CharField(help_text=u'郵便番号:ー',blank=True,max_length=4)
     pref = models.IntegerField(help_text=u'住所:都道府県',null=True, blank=True,choices=PREFECTURE_CHOICE)
-    addr01 = models.TextField(help_text=u'住所:市町村名',blank=True)
-    addr02 = models.TextField(help_text=u'住所:番地・ビル名',blank=True)
-    email = models.TextField(help_text=u'メールアドレス')
-    email_mobile = models.TextField(help_text=u'メールアドレス:携帯',blank=True)
-    tel01 = models.TextField(help_text=u'電話',blank=True)
-    tel02 = models.TextField(help_text=u'電話:-',blank=True)
-    tel03 = models.TextField(help_text=u'電話:-',blank=True)
-    fax01 = models.TextField(help_text=u'FAX:' ,blank=True)
-    fax02 = models.TextField(help_text=u'FAX:-',blank=True)
-    fax03 = models.TextField(help_text=u'FAX:-',blank=True)
+    addr01 = models.CharField(help_text=u'住所:市町村名',blank=True,max_length=50)
+    addr02 = models.CharField(help_text=u'住所:番地・ビル名',blank=True,max_length=50)
+    email = models.CharField(help_text=u'メールアドレス',max_length=50)
+    email_mobile = models.CharField(help_text=u'メールアドレス:携帯',blank=True,max_length=50)
+    tel01 = models.CharField(help_text=u'電話',blank=True,max_length=4)
+    tel02 = models.CharField(help_text=u'電話:-',blank=True,max_length=4)
+    tel03 = models.CharField(help_text=u'電話:-',blank=True,max_length=4)
+    fax01 = models.CharField(help_text=u'FAX:' ,blank=True,max_length=4)
+    fax02 = models.CharField(help_text=u'FAX:-',blank=True,max_length=4)
+    fax03 = models.CharField(help_text=u'FAX:-',blank=True,max_length=4)
     sex = models.IntegerField(help_text=u'性別',null=True, blank=True,choices=SEX_CHOICE)
     job = models.IntegerField(help_text=u'職業',null=True, blank=True,choices=JOB_CHOICE)
     birth = models.DateTimeField(help_text=u'生年月日',null=True, blank=True)
-    password = models.TextField(help_text=u'パスワード',blank=True)
+    password = models.CharField(help_text=u'パスワード',blank=True,max_length=50)
     reminder = models.IntegerField(help_text=u'パスワードを忘れた時のヒント:質問',null=True, blank=True)
     reminder_answer = models.TextField(help_text=u'パスワードを忘れた時のヒント:答え',blank=True)
-    secret_key = models.CharField(help_text=u'シークレットキー',unique=True, max_length=150)
+    secret_key = models.CharField(help_text=u'シークレットキー',unique=True, blank=False,max_length=150)
     first_buy_date = models.DateTimeField(help_text=u'',null=True, blank=True)      #NULLでよい
     last_buy_date = models.DateTimeField(help_text=u'',null=True, blank=True)       #NULLでよい
     buy_times = models.DecimalField(help_text=u'',null=True, max_digits=11, decimal_places=0, blank=True)   # 0 でよい

djcube/models.pyc

Binary file modified.

djcube/templates/base.html

+<html>
+
+<style type=text/css>
+    #formtools_tel01 { width:50px;}
+    #formtools_tel02 { width:50px;}
+    #formtools_tel03 { width:50px;}
+    input:focus { border: 1px solid #974343; background-color: #fee8eb;}
+</style>
+
+<body>
+
+{% block content %}
+{% endblock %}
+
+</body>
+</html>

djcube/templates/djcube/signup.html

+{% extends "base.html" %}
+
+{% block content %}
+
+{% if form.errors %}<h1>Please correct the following errors</h1>{% else %}<h1>Submit</h1>{% endif %}
+
+<form action="" method="post">
+姓 {{ form.name01 }} 名 {{ form.name02 }}               <br/>
+セイ {{ form.kana01 }} メイ {{ form.kana02 }}           <br/>
+住所 郵便 {{ form.zip01 }} - {{ form.zip02 }} 都道府県 {{ form.pref }} <br/> 
+市区町村 {{ form.addr01 }} 通り/建物 {{ form.addr02 }} <br/>
+<br>
+メール   {{ form.email }}  確認 {{ form.email_confirm }}           {{form.email.errors}}  {{form.email_confirm.errors }}      <br/>
+パスワード {{ form.password}} 確認 {{ form.password_confirm}}      {{form.password.errors}}       {{form.password_confirm.errors}}       <br/>
+<br>
+電話 {{ form.tel01 }} - {{ form.tel02 }} - {{ form.tel03 }} <br/>
+性別 {{ form.sex }} <br/>
+職業 {{ form.job }} <br/>
+<br>
+
+メールニュース {{ form.mailmaga_flg }} <br/>
+
+
+<input type="hidden" name="{{ stage_field }}" value="1" />
+<p><input type="submit" value="Preview" /></p>
+</form>
+
+{% endblock %}

djcube/templates/djcube/signup_preview.html

+{% extends "base.html" %}
+
+{% block content %}
+
+<h1>Preview your submission</h1>
+
+<table>
+{% for field in form %}
+<tr>
+<th>{{ field.label }}:</th>
+<td>{{ field.datalabel}}  </td>
+</tr>
+{% endfor %}
+
+</table>
+
+{{ form.pref.label}} {{ form.pref.data }}
+
+
+<p>Security hash: {{ hash_value }}</p>
+
+<form action="" method="post">
+{% for field in form %}{{ field.as_hidden }}
+{% endfor %}
+<input type="hidden" name="{{ stage_field }}" value="2" />
+<input type="hidden" name="{{ hash_field }}" value="{{ hash_value }}" />
+<p><input type="submit" name="action"  value="Submit" /> <input type="submit" name="action" value="ReEdit" /></p>
+</form>
+
+
+{% endblock %}