membership model changes.
authorgniibe <gniibe@fsij.org>
Mon, 3 Aug 2009 04:05:54 +0000 (13:05 +0900)
committergniibe <gniibe@fsij.org>
Mon, 3 Aug 2009 04:05:54 +0000 (13:05 +0900)
+migrate+/20090731_membership.sql
+migrate+/20090801_membership.sql [new file with mode: 0644]
.hgignore
ChangeLog
membership/admin.py
membership/models.py
membership/views.py
settings.py
templates/membership/member_payment.html
templates/membership/payment_list.html

index 0957c6a..208e1ae 100644 (file)
@@ -1,22 +1,25 @@
-#  In the class Member,
-#  
-#  -    member_type = models.ForeignKey(MemberType)
-#  +    member_type = models.CharField(max_length=1, choices=MEMBER_TYPE)
-#  
-#  In the class Member, same changes as class Member.
-#  
-#  And the class MemberType will not be used any more.
-#  # member_type
-#  # 1: member
-#  # 2: student member
-#  # 3: associate member (corporate member)
-#  class MemberType(models.Model):
-#      name = models.CharField(max_length=10)
-#      def __unicode__(self):
-#          return self.name
-#  """
-#  
-#  
+/*
+
+In the class Member,
+
+-    member_type = models.ForeignKey(MemberType)
++    member_type = models.CharField(max_length=1, choices=MEMBER_TYPE)
+
+In the class Member, same changes as class Member.
+
+And the class MemberType will not be used any more.
+# member_type
+# 1: member
+# 2: student member
+# 3: associate member (corporate member)
+class MemberType(models.Model):
+    name = models.CharField(max_length=10)
+    def __unicode__(self):
+        return self.name
+"""
+
+
+*/
 alter table "membership_member" rename to "membership_member20090730";
 create table "membership_member" (
     "id" integer NOT NULL PRIMARY KEY,
@@ -73,7 +76,6 @@ insert into "membership_memberpayment" (id, member_id, date,
        contribution, t_i_id from "membership_memberpayment20090730"
     where member_type_id = 3;
 
-drop table "membership_membertype";
-drop table "membership_memberpayment20090730"
-;
-drop table "membership_member20090730";
+-- drop table "membership_membertype";
+-- drop table "membership_memberpayment20090730";
+-- drop table "membership_member20090730";
diff --git a/+migrate+/20090801_membership.sql b/+migrate+/20090801_membership.sql
new file mode 100644 (file)
index 0000000..4d915b7
--- /dev/null
@@ -0,0 +1,60 @@
+BEGIN TRANSACTION;
+/*
+ *
+ */
+create table membership_member_new (
+    "id" integer NOT NULL PRIMARY KEY,
+    "user_id" integer NULL UNIQUE REFERENCES "auth_user" ("id"),
+    "member_id" varchar(10) NOT NULL,
+    "member_type" varchar(1) NOT NULL,
+    "name_in_alphabet" varchar(50) NOT NULL,
+    "first_name" varchar(30) NOT NULL,
+    "last_name" varchar(30) NOT NULL,
+    "email" varchar(75) NOT NULL,
+    "date_joined" date NULL,
+    "date_quit" date NULL,
+    "advance_payment" integer NOT NULL
+);
+insert into membership_member_new (
+       id, user_id, member_id, member_type, name_in_alphabet,
+       first_name, last_name, email,
+       date_joined, date_quit, advance_payment)
+    select membership_member.id, user_id, member_id, member_type, name_in_alphabet,
+       case when first_name is NULL then '' else first_name end,
+       case when last_name is NULL then '' else last_name end,
+       case when email is NULL then '' else email end,
+       membership_member.date_joined, date_quit, advance_payment
+    from membership_member left outer join auth_user
+    on membership_member.user_id = auth_user.id;
+
+alter table membership_member rename to membership_member20090801;
+alter table membership_member_new rename to membership_member;
+-- drop table membership_memberfee;
+
+create table membership_memberpayment_new (
+    "id" integer NOT NULL PRIMARY KEY,
+    "member_id" integer NOT NULL REFERENCES "membership_member" ("id"),
+    "date" date NOT NULL,
+    "fee_year" integer NOT NULL,
+    "member_type" varchar(1) NOT NULL,
+    "contribution" integer NOT NULL,
+    "le_id" integer NULL UNIQUE
+);
+insert into membership_memberpayment_new (
+       id, member_id, date, fee_year, member_type, contribution, le_id)
+    select id, member_id, date,
+       case when fee_id = 1 then 9999
+                   when fee_id = 2 then 2002
+                   when fee_id = 3 then 2003
+                   when fee_id = 4 then 2004
+                   when fee_id = 5 then 2005
+                   when fee_id = 6 then 2006
+                   when fee_id = 7 then 2007
+                   when fee_id = 8 then 2008
+                   when fee_id = 9 then 2009 end, member_type, contribution, t_i_id
+    from membership_memberpayment;
+
+alter table membership_memberpayment rename to membership_memberpayment20090801;
+alter table membership_memberpayment_new rename to membership_memberpayment;
+-- drop table membership_memberpayment20090801
+COMMIT;
index 532c2d4..207c1bf 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -4,3 +4,4 @@ syntax: glob
 *.pyc
 *~
 attic
+settings_private.py
index d552571..3932841 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2009-08-03  NIIBE Yutaka  <gniibe@fsij.org>
+
+       * membership/views.py (member_payment): Follow the type change of
+       fee_year for fee_list.
+       (add_member_payment): Likewise.
+       (register_member_email): Save to member.email too.
+       (payment_list): Bug fix.  Field name is 'date'.
+
+       * templates/membership/member_payment.html: Likewise.
+
+       * settings.py: Import SECRET_KEY from settings_private.py.
+
+       * membership/admin.py (MemberFee): Removed.
+
+2009-08-01  NIIBE Yutaka  <gniibe@fsij.org>
+
+       * +migrate+/20090801_membership.sql: New file.
+
+       * membership/models.py (MemberPayment): Rename fee to fee_year.
+       Make fee_year IntegerField (was: ForeignKey to MemberFee).
+       Rename t_i to le.
+       (MemberFee): Removed.
+       (Member): Added fields of first_name, last_name, and email.
+
 2009-07-31  NIIBE Yutaka  <gniibe@fsij.org>
 
        * membership/views.py (member_payment, manage_register_member):
@@ -6,6 +30,8 @@
        * templates/membership/valid_member_list.html: Likewise.
 
        * +migrate+: New directory.
+       * +migrate+/20090731_membership.sql: New file.
+       * +migrate+/20090731_gc_table.sql: New file.
 
        * membership/admin.py: Remove MemberType.
 
index 175b0cc..1c96ea2 100644 (file)
@@ -1,8 +1,7 @@
 from django.contrib import admin
-from fsij.membership.models import Member, CorporateMember, MemberAddress, MemberPayment, MemberFee
+from fsij.membership.models import Member, CorporateMember, MemberAddress, MemberPayment
 
 admin.site.register(Member)
 admin.site.register(CorporateMember)
 admin.site.register(MemberAddress)
 admin.site.register(MemberPayment)
-admin.site.register(MemberFee)
index 1207e11..ca59eeb 100644 (file)
@@ -3,6 +3,7 @@
 from django.db import models
 from django.contrib.auth.models import User
 from fsij.accounting.models import LedgerEntry
+from django.utils.translation import ugettext_lazy as _
 
 MEMBER_TYPE = ( ('M', u'正会員'), ('S', u'学生会員'), ('A', u'賛助会員'), )
 
@@ -11,13 +12,16 @@ class Member(models.Model):
     member_id = models.CharField(max_length=10)
     member_type = models.CharField(max_length=1, choices=MEMBER_TYPE)
     name_in_alphabet = models.CharField(max_length=50, blank=True)
+    first_name = models.CharField(max_length=30)
+    last_name = models.CharField(max_length=30)
+    email = models.EmailField(_('e-mail address'), blank=True)
     date_joined = models.DateField('date joined', blank=True, null=True)
     date_quit = models.DateField('date quit', blank=True, null=True)
     advance_payment = models.IntegerField()
-    def __unicode__(self):
-        return self.member_id + "/" + self.name()
     class Meta:
         permissions = (("can_manage", "Can manage members"),)
+    def __unicode__(self):
+        return self.member_id + "/" + self.name()
     def name(self):
         if self.member_type == 'A':
             try:
@@ -27,7 +31,7 @@ class Member(models.Model):
             if corp:
                 return corp.corporate_name
         elif self.user:
-            return self.user.last_name + " " + self.user.first_name
+            return self.last_name + " " + self.first_name
         return self.name_in_alphabet
 
 class CorporateMember(models.Model):
@@ -50,28 +54,21 @@ class MemberAddress(models.Model):
     def __unicode__(self):
         return self.zip_code
 
-# MemberFee -- Object which stands for member's fee
-# Instance example: admission_fee, 2002 member's fee, ...
-# Secretariat creates one for each year
-class MemberFee(models.Model):
-    year = models.IntegerField()
-    def __unicode__(self):
-        if self.year == 9999:
-            return "Admission"
-        else:
-            return "%04d" % self.year
-
 class MemberPayment(models.Model):
     member = models.ForeignKey(Member)
     date = models.DateField()
-    fee = models.ForeignKey(MemberFee)
+    fee_year = models.IntegerField() # 9999 means Admission fee
     # member type as of payment time
     member_type = models.CharField(max_length=1, choices=MEMBER_TYPE)
     # contribution as of payment time, valid if member_type == 'A'
     contribution = models.IntegerField() # Kuchi-Suu in Japanese
-    t_i = models.ForeignKey(LedgerEntry, unique=True, blank=True, null=True)
+    le = models.ForeignKey(LedgerEntry, unique=True, blank=True, null=True)
     def __unicode__(self):
-        return self.member.__unicode__() + "/" + self.fee.__unicode__()
+        if fee_year == 9999:
+            payment_fee_str = u'入会金'
+        else:
+            payment_fee_str = "%04d" % self.fee
+        return self.member.__unicode__() + "/" + payment_fee_str
 
 def get_valid_member(year):
     list_2 = MemberPayment.objects.filter(date__year = (year - 2)).order_by('member').values('member').distinct()
index e2f5b63..1670c6e 100644 (file)
@@ -3,7 +3,7 @@ from django.contrib.auth.decorators import login_required, user_passes_test
 from fsij.membership.models import *
 from django.http import HttpResponseRedirect
 from django.core.urlresolvers import reverse
-from fsij.settings import LOGIN_URL
+from fsij.settings import LOGIN_URL, FY_START_MONTH
 import datetime, time, re
 
 def member_index(request, member):
@@ -42,6 +42,8 @@ def register_member_email(request, member):
             'email': email,
             'errors': errors,}
         return HttpResponseRedirect(request.POST['original_path'])
+    member.email = email
+    member.save()
     member.user.email = email
     member.user.save()
     return HttpResponseRedirect(request.POST['original_path'])
@@ -120,14 +122,21 @@ def register_member_address(request, member):
 
 def member_payment(request, member, manage=False):
     try:
-        payments = member.memberpayment_set.order_by('-fee', '-date')
+        payments = member.memberpayment_set.order_by('-fee_year', '-date')
     except (MemberPayment.DoesNotExist):
         payments = None
     if manage:
-        fee_list = MemberFee.objects.filter(year__gte = (member.date_joined.year - 1))
-        if member.member_type == 'A':
-            fee_list = fee_list.exclude(year = 9999)
-        fee_list_in_payments = map(lambda (p): p.fee, member.memberpayment_set.all())
+        start_year = member.date_joined.year
+        if member.date_joined.month < FY_START_MONTH:
+            start_year = start_year - 1
+        end_today = datetime.date.today()
+        end_year = end_today.year
+        if end_today.month < FY_START_MONTH:
+            end_year = end_year - 1
+        fee_list = range(start_year, end_year + 1)
+        if member.member_type != 'A':
+            fee_list.append(9999) # Admission fee
+        fee_list_in_payments = map(lambda (p): p.fee_year, member.memberpayment_set.all())
         fee_list = filter(lambda (f): not f in fee_list_in_payments, fee_list)
     else:
         fee_list = None
@@ -148,7 +157,7 @@ def add_member_payment(request, member):
     p = MemberPayment(member = member,
                       date = datetime.date(*time.strptime(request.POST['date'], '%Y-%m-%d')[:3]),
                       member_type = request.POST['member_type'],
-                      fee = MemberFee.objects.get(year = request.POST['fee']),
+                      fee_year = request.POST['fee_year'],
                       contribution = request.POST['contribution'])
     p.save()
     return HttpResponseRedirect(reverse('fsij.membership.views.manage_member_payment', args=(member.member_id,)))
@@ -299,7 +308,7 @@ def member_list(request):
 
 @user_passes_test(lambda u: u.has_perm('membership.can_manage'), LOGIN_URL)
 def payment_list(request):
-    payments = MemberPayment.objects.all().order_by('date_payment')
+    payments = MemberPayment.objects.all().order_by('date')
     return render_to_response('membership/payment_list.html',
                               {'payments': payments,
                                })
index ea8d3e1..dd899dc 100644 (file)
@@ -51,7 +51,7 @@ MEDIA_URL = ''
 ADMIN_MEDIA_PREFIX = '/media/'
 
 # Make this unique, and don't share it with anybody.
-SECRET_KEY = 'el6y09xy$cbsee0p4y13h_)@6*pxh8(*r8+hg!_qpy(q%pxfnb'
+# SECRET_KEY = ''
 
 # List of callables that know how to import templates from various sources.
 TEMPLATE_LOADERS = (
@@ -98,3 +98,9 @@ AUTH_PROFILE_MODULE = "membership.Member"
 
 SESSION_ENGINE = "django.contrib.sessions.backends.file"
 # SESSION_FILE_PATH = "/tmp/django-fsij"
+
+# Constants for the organization
+FY_START_MONTH = 6
+FY_ESTABLISHED = 2002
+
+from settings_private import SECRET_KEY
index ddd0208..8b0f281 100644 (file)
@@ -23,7 +23,7 @@ parent.list.location.reload()
 <tr bgcolor={% cycle lightcyan,white %}>
 <form action="delete/{{ p.id }}/" method="post">
 <td>{{ p.date }}</td>
-<td>{% ifequal p.fee.year 9999 %}入会金{% else %}{{ p.fee.year }}年度{% endifequal%}
+<td>{% ifequal p.fee_year 9999 %}入会金{% else %}{{ p.fee_year }}年度{% endifequal%}
 {% ifnotequal p.member_type member.member_type %}
 [ {{ p.get_member_type_display }} ]
 {% endifnotequal %}
@@ -39,9 +39,9 @@ parent.list.location.reload()
 <tr>
 <td><input type="text" name="date" value=""/></td>
 <td>
-<select name="fee">
-{% for fee in fee_list%}
-<option value="{{ fee.year }}">{% ifequal fee.year 9999 %}入会金{% else %}{{ fee.year }}年度{% endifequal %}</option>
+<select name="fee_year">
+{% for fee_year in fee_list%}
+<option value="{{ fee_year }}">{% ifequal fee_year 9999 %}入会金{% else %}{{ fee_year }}年度{% endifequal %}</option>
 {% endfor %}
 </select>
 {% ifequal member.member_type 'A' %}
@@ -65,7 +65,7 @@ parent.list.location.reload()
 <tr><th>日付</th><th>内容</th></tr>
 {% for p in payments %}
 <tr bgcolor={% cycle lightcyan,white %}><td>{{ p.date }}</td>
-<td>{% ifequal p.fee.year 9999 %}入会金{% else %}{{ p.fee.year }}年度{% endifequal %}
+<td>{% ifequal p.fee_year 9999 %}入会金{% else %}{{ p.fee_year }}年度{% endifequal %}
 {% ifnotequal p.member_type member.member_type %}
 [ {{ p.get_member_type_display }} ]
 {% endifnotequal %}
index bd38b14..7647988 100644 (file)
 {% for p in payments %}
 <form action="/{{ p.id }}/" method="POST">
 <tr>
-  <td>{{ p.date_payment }}</td>
+  <td>{{ p.date }}</td>
   <td><a href="../{{ p.member.member_id }}/" title="{{ p.member.user.last_name }} {{ p.member.user.first_name }}" target="edit">{{ p.member.member_id }}</a></td>
-  <td>{{ p.amount }}</td>
-  <td>{{ p.payment_for }}</td>
+  <td>{{ p.fee_year }}</td>
+  <td>{{ p.member_type }}</td>
 <td>
 <input type="submit" value="Submit" />
 <input type="hidden" value="{{ original_path }}" name="original_path" />