wiki.zope.jp
Calendar.py
   
RecentChanges WikiHelp WikiPractice JumpSearch


# --------------------------------------------------------------------------- # オリジナル http://www.zope.org/Members/jimbag/ZCalendar by jimbag@kw.igs.net # # 修正 日本Zopeユーザー会 http://wiki.zope.jp/ZCalendar # # 変更履歴 # 2002/02/15 spumoni 日本語化挑戦 # 2002/02/16 bababababass さんの修正を導入 # ---------------------------------------------------------------------------

__doc__ = """ZCalendar Product""" __version__ = 0.1

from Globals import HTMLFile from Globals import MessageDialog from Globals import Persistent

import OFS.SimpleItem import Acquisition import AccessControl.Role

from time import time, gmtime, localtime, mktime, asctime, ctime

_days = ['日','月','火','水','木','金','土'] _months = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'] _mdays = [31,28,31,30,31,30,31,31,30,31,30,31]

# --------------------------------------------------------------------------- manage_addCalendarForm = HTMLFile( calAdd, globals())

# --------------------------------------------------------------------------- def manage_addCalendar( self, id, title='', REQUEST=None): """ add a calendar """ self._setObject(id,Calendar(id,title)) if REQUEST is not None: return self.manage_main( self, REQUEST )

# =========================================================================== class Calendar( OFS.SimpleItem.Item, Persistent, Acquisition.Implicit, AccessControl.Role.RoleManager ): """ ZCalendar Product """ meta_type = "ZCalendar"

manage_options = ( {label : Edit, 'action': manage_main }, {label : View, 'action': '' }, {label : Security, 'action': manage_access }, )

__ac_permissions__ = ( (View management screens, (manage_tabs,manage_main)), (Change permissions, (manage_access,)), (Change Calendar, (manage_edit,)), (View Calendar, ('',)), )

# ---------------------------------------------------------------- def __init__( self, id, title=''): """ init """ self.id = id self.title = title self.titlebg = "#0000FF" self.titlefg = "#FFFFFF" self.todayfg = "#FF0000" self.todaybg = "#FFFFFF" self.calfg = "#000000" self.calbg = "#FFFFFF"

# ---------------------------------------------------------------- index_html = HTMLFile(index, globals())

# ---------------------------------------------------------------- manage_main = HTMLFile(calEdit, globals())

# ---------------------------------------------------------------- def manage_edit( self, title, titlefg, titlebg, todayfg, todaybg, calfg, calbg, REQUEST=None ): """ edit the properties """ self.title = title self.titlefg = titlefg self.titlebg = titlebg self.todayfg = todayfg self.todaybg = todaybg self.calfg = calfg self.calbg = calbg if REQUEST is not None: return MessageDialog( title = Edited, message = Properties for %s changed % self.id, action = ./manage_main, )

# ---------------------------------------------------------------- def _isleap( self, year ): return year % 4 == 0 and (year % 100 <> 0 or year % 400 == 0 )

# ---------------------------------------------------------------- def _weekday( self, year, month, day ): secs = mktime((year,month+1,day,0,0,0,0,0,0)) t = localtime(secs) return t[6]

# ---------------------------------------------------------------- def _monthrange( self, year, month ): day1 = self._weekday( year, month, 1 ) ndays = _mdays[month] + (month == 1 and self._isleap(year)) return day1, ndays

# ------------------------------------------------------------------------ def _monthcalendar( self, year, month ): day1, ndays = self._monthrange( year, month ) rows = [] day = 1 - day1 if day <= -5: day=day+7 while day <= ndays+1: row = [0,0,0,0,0,0,0] for i in range(7): if 1 < day <= ndays+1: row[i] = day - 1 day = day + 1 rows.append(row) return rows

# ------------------------------------------------------------------------ def show_calendar( self, year=None, month=None ): """ return the calendar HTML """ t = localtime(time()) if year == None: year = t[0] if month == None: month = t[1]-1 cal = self._monthcalendar( year, month ) s = <table border=0 cellspacing=1 cellpadding=1 bgcolor="%s" fgcolor="%s">\n % (self.calbg, self.calfg) s = s + '' % self.titlebg s = s + <font color="%s"> % self.titlefg s = s + '%s年 %s\n' % (year, _months[month]) s = s + ' for day in _days: s = s + %s\n' % day s = s + '\n' for week in cal: s = s + '' for day in week: s = s + <td width=14% align=center if day: if day == t[2] and month == t[1]-1 and year == t[0]: s = s + bgcolor="%s"> % self.todaybg s = s + '%s' % (self.todayfg,str(day)) else: if week[0] == day: s = s + '> s = s + %s' % str(day) else: s = s + '> s = s + %s' % str(day) else: s = s + '>  s = s + s = s + \n' s = s + '\n' return s

Last edited Sun, 10 Sep 2006 13:04:23 +0900 Edit this page