from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User


class Fund(models.Model):
    class Meta:
        permissions = (
            ("apply_only", "可以提交申请"),
            ("student_approve", "学代通道"),
            ("teacher_approve", "老师通道"),
        )
    username = models.CharField(max_length=30)
    name = models.CharField(max_length=100)
    apply_date = models.DateTimeField('申请日期', default=timezone.now)
    activity_date = models.DateField('活动日期', default=timezone.now)#, default=timezone.now
    plan_file = models.FileField(upload_to='%y/%m/%d/plan_file')
    charger = models.CharField(max_length=20)
    charger_tel = models.CharField(max_length=30)
    activity_member = models.CharField(max_length=500)
    last_time = models.CharField(max_length=100)
    note = models.CharField(max_length=500)
    is_viewed_by_student = models.BooleanField(default=False)
    is_viewed_by_teacher = models.BooleanField(default=False)
    is_objected = models.BooleanField(default=False)
    paycheck_file = models.FileField(upload_to='%y/%m/%d/paycheck_file',blank = True)
    pc_stat = (
            ("not_uploaded", "等待提交结算表"),
            ("applied", "已提交结算表，等待审核"),
            ("stucon_approved", "学代已审核结算表"),
            ("stucon_disapproved", "结算表未通过学代审核"),
            ("teacher_approved", "老师已审核结算表"),
            ("teacher_disapproved", "结算表未通过老师审核"),
        )
    paycheck_status = models.CharField(max_length=30,choices=pc_stat,default="not_uploaded")

    def __str__(self):
        return self.name

    def fund_status(self):
        if not self.is_objected:
            if self.is_viewed_by_student:
                if self.is_viewed_by_teacher:
                    return u"申请成功"
                else:
                    return u"等待老师审批"
            else:
                return u"等待学代审批"
        else:
            if self.is_viewed_by_student:
                if self.is_viewed_by_teacher:
                    return u"团委书记否决"
                else:
                    return u"学代否决"

    def paycheck_to_display(self):
        if self.paycheck_status != "not_uploaded":
            return True
        else:
            return False


@@ -1164,16 +1164,17 @@
 oaded%22, 
+u
 %22%E7%AD%89%E5%BE%85%E6%8F%90%E4%BA%A4%E7%BB%93%E7%AE%97%E8%A1%A8
@@ -1201,16 +1201,17 @@
 plied%22, 
+u
 %22%E5%B7%B2%E6%8F%90%E4%BA%A4%E7%BB%93%E7%AE%97%E8%A1%A8%EF%BC%8C
@@ -1250,16 +1250,17 @@
 roved%22, 
+u
 %22%E5%AD%A6%E4%BB%A3%E5%B7%B2%E5%AE%A1%E6%A0%B8%E7%BB%93%E7%AE%97
@@ -1295,24 +1295,25 @@
 sapproved%22, 
+u
 %22%E7%BB%93%E7%AE%97%E8%A1%A8%E6%9C%AA%E9%80%9A%E8%BF%87%E5%AD%A6%E4%BB%A3%E5%AE%A1%E6%A0%B8%22
@@ -1348,16 +1348,17 @@
 roved%22, 
+u
 %22%E8%80%81%E5%B8%88%E5%B7%B2%E5%AE%A1%E6%A0%B8%E7%BB%93%E7%AE%97
@@ -1398,16 +1398,17 @@
 roved%22, 
+u
 %22%E7%BB%93%E7%AE%97%E8%A1%A8%E6%9C%AA%E9%80%9A%E8%BF%87%E8%80%81

change to chinese description