PATCH improving Code Readability
zoom / date related code
Index: ganttcalendar/ticketcalendar.py =================================================================== --- ganttcalendar/ticketcalendar.py (revision 816) +++ ganttcalendar/ticketcalendar.py (working copy) @@ -73,26 +73,25 @@ year = req.args.get('year') month = req.args.get('month') day = req.args.get('day') or '1' - weekly_view = int(req.args.get('weekly') or '0') + weekly_view = int(req.args.get('weekly') or self.show_weekly_view) show_my_ticket = req.args.get('show_my_ticket') show_closed_ticket = req.args.get('show_closed_ticket') selected_milestone = req.args.get('selected_milestone') - if year and month: - cday = date(int(year),int(month),int(day)) - else: - cday = date.today() - show_closed_ticket = 'on' - weekly_view = int(self.show_weekly_view) - # first_day= 0: sunday (default) 1: monday 2: tuesday 3: wednesday 4: thursday 5: friday 6: saturday first_day = self.config['ganttcalendar'].getint('first_day', default=0) weekdays = [6, 0, 1, 2, 3, 4, 5] first_wkday = weekdays[first_day % 7] # first_wkday= 0: monday 1: tuesday 2: wednesday 3: thursday 4: friday 5: saturday 6: sunday (default) - dateFormat = str(self.config['ganttcalendar'].get('format', default='%Y/%m/%d') or '%Y/%m/%d') + dateFormat = str(self.config['ganttcalendar'].get('format', default='%Y/%m/%d')) or '%Y/%m/%d' + if year and month: + cday = date(int(year),int(month),int(day)) + else: + cday = date.today() + show_closed_ticket = 'on' + first, last = self.calendarRange(cday.year, cday.month, first_wkday) if weekly_view: Index: ganttcalendar/ticketgantt.py =================================================================== --- ganttcalendar/ticketgantt.py (revision 816) +++ ganttcalendar/ticketgantt.py (working copy) @@ -43,7 +43,7 @@ first_day = IntOption('ganttcalendar', 'first_day', '0', """Begin of week: 0 == Sunday, 1 == Monday (default: 0)""") show_ticket_summary = BoolOption('ganttcalendar', 'show_ticket_summary', 'false', """Show ticket summary at gantchart bar. (default: false)""") - normal_mode = IntOption('ganttcalendar', 'default_zoom_mode', '3', """Default zoom mode in gantchar. (default: 3)""") + default_zoom_mode = IntOption('ganttcalendar', 'default_zoom_mode', '3', """Default zoom mode in gantchar. (default: 3)""") format = Option('ganttcalendar', 'format', '%Y/%m/%d', """Date format for due assign and due finish""") substitutions = ['$USER'] @@ -189,8 +189,8 @@ req.perm.assert_permission('TICKET_VIEW') req.perm.require('TICKET_VIEW') self.log.debug("process_request " + str(globals().get('__file__'))) - ymonth = req.args.get('month') - yyear = req.args.get('year') + year = req.args.get('year') + month = req.args.get('month') baseday = req.args.get('baseday') selected_milestone = req.args.get('selected_milestone') selected_component = req.args.get('selected_component') @@ -211,16 +211,16 @@ break if not has_complete: add_warning(req, _("'complete' field is not defined. Please define it.")) - normal_mode = req.args.get('normal') - current_mode = req.args.get('zoom') - zoom_modes = [1, 2, 3, 4, 5, 6] # zoom modes - if normal_mode == None: - normal_mode = self.config['ganttcalendar'].getint('default_zoom_mode', default=3) - current_mode = normal_mode = zoom_modes[normal_mode % 6 -1] - else: - current_mode = zoom_modes[int(current_mode) % 6 -1] + + default_zoom_mode = req.args.get('normal') or self.default_zoom_mode + current_zoom_mode = req.args.get('zoom') or default_zoom_mode + + zoom_modes = [1, 2, 3, 4, 5, 6] # zoom modes + default_zoom_mode = zoom_modes[int(default_zoom_mode) % 6 -1] + current_zoom_mode = zoom_modes[int(current_zoom_mode) % 6 -1] + zoom_months = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6} # zoom mode: months term - months_term = zoom_months[current_mode] + months_term = zoom_months[current_zoom_mode] # first_day= 0: sunday (default) 1: monday 2: tuesday 3: wednesday 4: thursday 5: friday 6: saturday first_day = self.config['ganttcalendar'].getint('first_day', default=0) @@ -228,7 +228,7 @@ first_wkday = weekdays[first_day % 7] # first_wkday= 0: monday 1: tuesday 2: wednesday 3: thursday 4: friday 5: saturday 6: sunday (default) - dateFormat = str(self.config['ganttcalendar'].get('format', default='%Y/%m/%d') or '%Y/%m/%d') + dateFormat = str(self.config['ganttcalendar'].get('format', default='%Y/%m/%d')) or '%Y/%m/%d' if baseday != None: t = time.strptime(baseday, dateFormat) @@ -236,30 +236,24 @@ else: baseday = date.today() show_ticket_status = 'on' - show_ticket_summary = self.config['ganttcalendar'].getbool('show_ticket_summary', default='false') - if show_ticket_summary: - show_ticket_summary = 'on' - else: - show_ticket_summary = None + show_ticket_summary = self.show_ticket_summary and 'on' or None if show_ticket_summary: ticket_margin = 12 else: ticket_margin = 0 - cday = date.today() - if not (not ymonth or not yyear): - cday = date(int(yyear),int(ymonth),1) + if year and month: + cday = date(int(year),int(month),1) + else: + cday = date.today() - # cal next month - nmonth = cday.replace(day=1).__add__(timedelta(days=32)).replace(day=1) - - # cal previous month - pmonth = cday.replace(day=1).__add__(timedelta(days=-1)).replace(day=1) - first_date= cday.replace(day=1) days_term= (first_date.__add__(timedelta(months_term*32)).replace(day=1)-first_date).days + prev = first_date.__add__(timedelta(days=-1)).replace(day=1) + next = first_date.__add__(timedelta(days=32)).replace(day=1) + # process ticket db = self.env.get_db_cnx() cursor = db.cursor(); @@ -645,7 +639,7 @@ except: pass - data = {'baseday': baseday, 'current':cday, 'prev':pmonth, 'next':nmonth, 'month_tbl': month_tbl} + data = {'baseday': baseday, 'current':cday, 'prev':prev, 'next':next, 'month_tbl': month_tbl} data.update({'show_my_ticket': show_my_ticket, 'show_closed_ticket': show_closed_ticket, 'sorted_field': sorted_field}) data.update({'show_ticket_summary': show_ticket_summary, 'show_ticket_status': show_ticket_status, 'ti_mrgn': ticket_margin}) data.update({'selected_milestone':selected_milestone,'selected_component': selected_component}) @@ -653,7 +647,7 @@ data.update({'sum_estimatedhours':sum_estimatedhours, 'sum_totalhours':sum_totalhours}) data.update({'holidays':holidays,'first_date':first_date,'days_term':days_term}) data.update({'calendar':calendar}) - data.update({'dateFormat': dateFormat ,'first_wkday':first_wkday,'normal':normal_mode,'zoom':current_mode, '_':_}) + data.update({'dateFormat': dateFormat ,'first_wkday':first_wkday,'normal':default_zoom_mode,'zoom':current_zoom_mode, '_':_}) data.update({'fields':fields_data, 'clauses':clauses_data, 'modes': self.get_modes()}) ### display_html Index: ganttcalendar/ticketvalidator.py =================================================================== --- ganttcalendar/ticketvalidator.py (revision 816) +++ ganttcalendar/ticketvalidator.py (working copy) @@ -32,10 +32,10 @@ # due_assign, due_close field - dueDate = {'due_assign':None, 'due_close':None} - format = self.config['ganttcalendar'].get('format', default='%Y/%m/%d') or '%Y/%m/%d' - dateFormat = format.replace('%Y', 'YYYY', 1).replace('%y', 'YY', 1) \ - .replace('%m', 'MM', 1).replace('%d', 'DD', 1) + dueDate = {'due_assign':None, 'due_close':None} + format = str(self.config['ganttcalendar'].get('format', default='%Y/%m/%d')) or '%Y/%m/%d' + format_hint = format.replace('%Y', 'YYYY', 1).replace('%y', 'YY', 1) \ + .replace('%m', 'MM', 1).replace('%d', 'DD', 1) for field in ('due_assign', 'due_close'): due = ticket.values.get(field) @@ -43,11 +43,11 @@ try: t = time.strptime(due, format) dueDate[field] = date( t[0],t[1],t[2]) - ticket.values[field] = format_date( dueDate[field], str(format)) + ticket.values[field] = format_date( dueDate[field], format) except( TracError, ValueError, TypeError): dueDate[field] = None label = self.config['ticket-custom'].get(field+'.label', default='') - errors.append(( u"%s(%s)" % (label, field), _("'%s' is invalid date format. Please input format as %s.") % (due, dateFormat) )) + errors.append(( u"%s(%s)" % (label, field), _("'%s' is invalid date format. Please input format as %s.") % (due, format_hint) )) if (dueDate['due_assign'] and dueDate['due_close']) \ and (dueDate['due_assign'] > dueDate['due_close']):
merge by r817.
zoom / date related code