def upcoming(self): """Show an overview of all booking days""" today_date_str = datetime.date.today().strftime('%Y-%m-%d') end_date_str = (datetime.date.today()+datetime.timedelta(5)).strftime('%Y-%m-%d') #today_date_str = '2017-06-10' #end_date_str = '2017-06-20' booking_days = getBookingDays(holly_couch, from_date=today_date_str, to_date=end_date_str) log.debug(str(booking_days)) print '####', booking_days vgroups = getVisitingGroupsInDatePeriod(holly_couch, today_date_str, end_date_str) # TODO: fix view later. get_visiting_groups(from_date=today_date_str, to_date=end_date_str) group_info = dict() bdays = list() for tmp in booking_days: b_day = tmp.doc tmp_date_today_str = b_day['date'] bdays.append(b_day) group_info[tmp_date_today_str] = dict(arrives=[v.doc for v in vgroups if v.doc.get('from_date','') == tmp_date_today_str], leaves=[v.doc for v in vgroups if v.doc.get('to_date','') == tmp_date_today_str], stays=[v.doc for v in vgroups if v.doc.get('to_date','') > tmp_date_today_str and v.doc.get('from_date','') < tmp_date_today_str]) return dict(booking_days=bdays, group_info=group_info, makeDate=getDateObject)
def sannah(self): # ...get all booking days in the future today = datetime.date.today().strftime("%Y-%m-%d") all_booking_days = [b.doc for b in getBookingDays(holly_couch, from_date=today)] # ...get all utelunch bookings utelunch_bookings = getAllUtelunchBookings(holly_couch) # ...make dict mapping booking day id (key) to bookings utelunch_dict = dict() for ub in utelunch_bookings: tmp_booking_list = utelunch_dict.get(ub.key, list()) tmp_booking_list.append(ub.doc) utelunch_dict[ub.key] = tmp_booking_list log.info(utelunch_dict) return dict(booking_days=all_booking_days, utelunches=utelunch_dict)
def view_bookings_of_visiting_group(self, visiting_group, visiting_group_id, name, bookings, hide_comment=0, show_group=0, render_time=''): #...now group all bookings in a dict mapping activity_id:content clustered_bookings = {} booking_day_map = dict() booking_day_slot_map = dict() for bd in getBookingDays(holly_couch): booking_day_map[bd.doc['_id']] = bd.doc #...this is very time consuming, better list all slot map and build a map #booking_day_slot_map[bd.doc['_id']] = getSchemaSlotActivityMap(holly_couch, bd.doc, subtype='program') activities = dict() used_activities_keys = dict() for x in getAllActivities(holly_couch): activities[x.key[1]] = x.doc for b in bookings: # TODO: There will be quite a few multiples if we search on both id and name! if hide_comment==1: hide_cache_content_in_booking(b) #tmp = b['cache_content'] #i = tmp.find('//') #if i > 0: # b['cache_content'] = b['cache_content'][:i] key = str(b['activity_id'])+':'+b['content'] if None == b.get('booking_day_id', None): key = 'N'+key #...we need to do this transfer because we need to add booking_day.date and slot time. #...HERE WE MUST NOW ONCE AGAIN GET SLOT FROM BOOKING DAY ID AND SLOT ID... booking_day_id = None slot_id = '' slot_o = None tmp_booking_day = None used_activities_keys[b['activity_id']] = 1 used_activities_keys[activities[b['activity_id']]['activity_group_id']] = 1 if b.has_key('booking_day_id'): booking_day_id = b['booking_day_id'] if '' != booking_day_id: tmp_booking_day = booking_day_map[booking_day_id] slot_id = b['slot_id'] tmp_slot_map = self.getSlotMapOfBookingDay(booking_day_slot_map, tmp_booking_day) slot_o = tmp_slot_map[slot_id] b2 = DataContainer(booking_state=b['booking_state'], cache_content=b['cache_content'], content=b['content'] , activity=activities[b['activity_id']], id=b['_id'], booking_day=tmp_booking_day , slot_id=slot_id , slot=slot_o, booking_day_id=booking_day_id, valid_from=b.get('valid_from',''), valid_to=b.get('valid_to',''), requested_date=b.get('requested_date','')) if clustered_bookings.has_key(key): bl = clustered_bookings[key] bl.append(b2) else: bl = list() bl.append(b2) clustered_bookings[key] = bl clustered_bookings_list = clustered_bookings.values() clustered_bookings_list.sort(self.fn_cmp_booking_date_list) for bl in clustered_bookings_list: bl.sort(self.fn_cmp_booking_timestamps) if True: #show_group==1: booking_info_notes = [n.doc for n in getBookingInfoNotesOfUsedActivities(holly_couch, used_activities_keys.keys())] else: booking_info_notes = [] return dict(clustered_bookings=clustered_bookings_list, name=name, workflow_map=workflow_map, visiting_group_id=visiting_group_id, getRenderContent=getRenderContent, formatDate=reFormatDate, booking_info_notes=booking_info_notes, render_time=render_time, visiting_group=visiting_group, bokn_status_map=bokn_status_map, notes = [n.doc for n in getNotesForTarget(holly_couch, visiting_group_id)], show_group=show_group)
def program_layer_get_days_helper(self, visiting_group_id ): visiting_group = common_couch.getVisitingGroup(holly_couch, visiting_group_id) ####date_range = dateRange(visiting_group['from_date'], visiting_group['to_date']) #...create temporary mapping title-> id, in the future, this should be based on time rather on the title (which can be dangerous) time_id_mapping = self.getTimeIdMapping() booking_days = [bd.doc for bd in getBookingDays(holly_couch, visiting_group['from_date'], visiting_group['to_date'])] schema_id_map = dict() for b in booking_days: schema_id_map[b['day_schema_id']] = b #...now, if we have too many day schema ids, we have a problem... # TODO dangerous below, we can have diffreent schemas for different days first_booking_day=booking_days[0] schema_id = first_booking_day['day_schema_id'] schema_doc = holly_couch[schema_id] schema = schema_doc['schema'] #...if we assume the same layout for every slot row, we can get first row in schema and use it as template any_slot_row_in_schema = schema[schema.keys()[0]][1:] # skip first part, now we have four time-slots that can be used #...it would be best if we now could clean out the slot_id from the mapping generalized_slot_row = [] layer_times = [] #...will change its parameters self.fillInGeneralizedSlotRow(time_id_mapping, any_slot_row_in_schema, generalized_slot_row, layer_times) ####datetime_map = [] #...iterate through schema and find FM EM etc # iterate through schema and find the slot_id maping. layer_days = [] for d in booking_days: tmp_item = dict(booking_day_id=d['_id'], date=d['date']) layer_days.append(tmp_item) #... program_layers = visiting_group.get('layers', []) #...I need to build this mapping from booking_day_id:slot_id:layer_id to datetime bucket # so iterate through all schema rows and look at time, slot_id_time_map = {} for tmp_schema_id in schema_id_map.keys(): tmp_schema_doc = holly_couch[tmp_schema_id] tmp_schema = tmp_schema_doc['schema'] for tmp_activity_id, tmp_activity_row in tmp_schema.items(): for tmp_slot in tmp_activity_row[1:]: tmp_time = tmp_slot['title'] slot_id_time_map[tmp_slot['slot_id']] = time_id_mapping[tmp_time] # TODO return activity title map activity_title_map = getActivityTitleMap(holly_couch) return dict(layer_time=layer_times, layer_days=layer_days, slot_id_time_map=slot_id_time_map, visiting_group_id=visiting_group_id, activity_title_map=activity_title_map, program_layers=program_layers)
def overview(self): """Show an overview of all booking days""" today = datetime.date.today().strftime('%Y-%m-%d') return dict(booking_days=[b.doc for b in getBookingDays(holly_couch, from_date=today)], makeDate=getDateObject)