Mercurial > moin > extensions
annotate data/plugin/parser/text_x_fullcalendar.py @ 653:127da830be6c
updated copyright
author  Reimar Bauer <rb.proj AT googlemail DOT com> 

date  Tue, 19 Apr 2016 16:29:54 +0200 
parents  f3676743483d 
children 
rev  line source 

630
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

1 # * coding: iso88591 * 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

2 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

3 MoinMoin  fullcalendar 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

4 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

5 This parser is used to visualize icals date entries by fullcalendar 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

6 http://www.fullcalendar.io 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

7 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

8 You may want to add to your wikiconfig.py something like 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

9 html_head = ''' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

10 <link rel="stylesheet" type="text/css" charset="utf8" href="%(url_prefix_static)s/fullcalendar/fullcalendar.css"> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

11 <link rel="stylesheet" type="text/css" charset="utf8" media="print" href="%(url_prefix_static)s/fullcalendar/fullcalendar.print.css"> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

12 <script src='%(url_prefix_static)s/fullcalendar/lib/moment.min.js'></script> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

13 <script src='%(url_prefix_static)s/fullcalendar/lib/jquery.min.js'></script> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

14 <script src='%(url_prefix_static)s/fullcalendar/fullcalendar.min.js'></script> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

15 ''' % {"url_prefix_static": url_prefix_static} 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

16 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

17 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

18 Usage: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

19 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

20 #format fullcalendar maxwidth=400px, week_numbers=1, left=today 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

21 
653
127da830be6c
updated copyright
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
630
diff
changeset

22 @copyright: 20142016 by MoinMoin:ReimarBauer 
630
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

23 @license: GNU GPL, see COPYING for details. 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

24 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

25 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

26 try: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

27 import icalendar 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

28 except ImportError: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

29 icalendar = None 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

30 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

31 import os 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

32 import json 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

33 import datetime 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

34 from MoinMoin import config, wikiutil 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

35 from MoinMoin.action import AttachFile 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

36 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

37 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

38 def fullcalendar_settings(attachfile=u'default.ics', editable=0, default_date=u'', 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

39 week_numbers=0, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

40 left=u'prev,next,today', right=u'month,agendaWeek,agendaDay', 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

41 title=u'title', 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

42 maxwidth=u'900px'): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

43 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

44 dummy function to initialize all default parameters for fullcalendar. 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

45 The parameters are checked for wrong input. 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

46 @param attachfile: name of attachmet to read ical data from and convert to json 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

47 @param editable: default false 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

48 @param default_date: default current day 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

49 @param week_numbers: default false, determines if week numbers should be displayed on the calendar. 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

50 @param left: default: 'prev,next,today' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

51 prev: button for moving the calendar back one month/week/day, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

52 next: button for moving the calendar forward one month/week/day 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

53 today: button for moving the calendar to the current month/week/day 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

54 @param right: default: month,agendaWeek,agendaDay' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

55 month: view month 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

56 agendaWeek: view week 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

57 agendaDay: view day 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

58 @param title: default title,text containing the current month/week/day 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

59 @param maxwidth: width used default 900px 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

60 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

61 return locals() 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

62 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

63 Dependencies = ["page"] 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

64 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

65 class Parser: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

66 """ fullcalendar parser """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

67 extensions = '*.ics' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

68 def __init__(self, raw, request, **kw): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

69 self.pagename = request.page.page_name 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

70 self.raw = raw.strip('\n') 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

71 self.request = request 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

72 self.formatter = request.formatter 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

73 self.form = None 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

74 self.ical_data = None 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

75 self.json_data = u"" 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

76 self.attachfile = u"default.ical" 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

77 self.editable = 0 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

78 self.default_date = u'' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

79 self.week_numbers = 0 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

80 self.left = u'prev,next,today' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

81 self.right = u'month,agendaWeek,agendaDay' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

82 self.title = u'title' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

83 self.maxwidth = u'900px' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

84 self._ = request.getText 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

85 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

86 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

87 args = kw.get('format_args', '') 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

88 self.init_settings = False 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

89 try: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

90 settings = wikiutil.invoke_extension_function(request, fullcalendar_settings, args) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

91 for key, value in settings.items(): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

92 setattr(self, key, value) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

93 # saves the state of valid input 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

94 self.init_settings = True 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

95 except ValueError, err: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

96 msg = u"fullcalendar: %s" % err.args[0] 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

97 request.write(self.formatter.text(msg)) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

98 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

99 def render(self, formatter): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

100 """ renders calendar """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

101 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

102 _ = self._ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

103 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

104 # checks if initializing of all attributes in __init__ was done 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

105 if self.init_settings: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

106 # reads in datafile if exists and converts it to json 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

107 self.ical2json() 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

108 editable = 'false' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

109 if self.editable == 1: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

110 editable = 'true' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

111 default_date = self.default_date 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

112 if default_date == u'': 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

113 default_date = datetime.datetime.now().date().isoformat() 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

114 week_numbers = 'false' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

115 if self.week_numbers == 1: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

116 week_numbers = 'true' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

117 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

118 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

119 html_text = """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

120 <script> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

121 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

122 $(document).ready(function() { 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

123 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

124 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

125 $('#calendar').fullCalendar({ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

126 header: { 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

127 left: '%(left)s', 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

128 center: '%(title)s', 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

129 right: '%(right)s' 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

130 }, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

131 defaultDate: '%(default_date)s', 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

132 editable: %(editable)s, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

133 eventLimit: true, // allow "more" link when too many events 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

134 weekNumbers: %(week_numbers)s, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

135 events: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

136 %(json)s 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

137 }); 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

138 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

139 }); 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

140 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

141 </script> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

142 <style> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

143 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

144 #calendar { 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

145 maxwidth: %(maxwidth)s; 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

146 margin: 0 auto; 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

147 } 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

148 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

149 </style> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

150 <div id='calendar'></div> 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

151 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

152 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

153 return html_text % {"left": self.left, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

154 "title": self.title, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

155 "right": self.right, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

156 "default_date": default_date, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

157 "editable": editable, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

158 "week_numbers": week_numbers, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

159 "json": self.json_data, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

160 "maxwidth": self.maxwidth, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

161 } 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

162 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

163 def get_ical_data(self): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

164 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

165 reads ical attachfile 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

166 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

167 if icalendar is None: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

168 return 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

169 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

170 if self.request.user.may.read(self.pagename) and AttachFile.exists(self.request, self.pagename, self.attachfile): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

171 ical_file = os.path.join(AttachFile.getAttachDir(self.request, self.pagename), self.attachfile).encode(config.charset) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

172 with open(ical_file, 'rb') as fhandler: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

173 self.ical_data = icalendar.Calendar.from_ical(fhandler.read()) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

174 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

175 def ical2json(self): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

176 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

177 comverts ical data to json 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

178 This routine was inspired by this blog article 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

179 http://www.thogan.com/blog/sogoicalandfullcalendar/ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

180 """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

181 self.get_ical_data() 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

182 events = [] 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

183 if self.ical_data is not None: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

184 for item in self.ical_data.walk(): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

185 if item.name == 'VEVENT': 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

186 new_event = {'editable': False, 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

187 'allDay': False} 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

188 new_event['title'] = item.get('summary') 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

189 new_event['start'] = item.get('dtstart').dt.isoformat() 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

190 new_event['end'] = item.get('dtend').dt.isoformat() 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

191 if item.get('location'): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

192 new_event['url'] = item.get('location') 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

193 events.append(new_event) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

194 self.json_data = json.dumps(events, indent=4) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

195 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

196 def format(self, formatter): 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

197 """ parser output """ 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

198 # checks if initializing of all attributes in __init__ was done 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

199 if self.init_settings: 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

200 self.request.write(self.formatter.div(1, css_class="fullcalendar")) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

201 self.request.write(self.render(formatter)) 
f3676743483d
initial version of an ical/ics data parser rendered by fullcalendar
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff
changeset

202 self.request.write(self.formatter.div(0)) 