Beispiel #1
0
 def layers_printable(self, visiting_group_id,  hide_comment=1):
     visiting_group = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     
     date_range = dateRange(visiting_group['from_date'], visiting_group['to_date'])
     number_of_days = len(date_range)
     width_ratio = (100.0 / (number_of_days+1))
     
     #...TODO organize bookings per layer bucket
     result = self.program_layer_get_days_helper(visiting_group_id)
     
     result['notes'] = []
     result['tags'] = []
     result['reFormatDate'] = reFormatDate
     result['visiting_group'] = visiting_group
     
     slot_id_time_id_map = result['slot_id_time_map']
     bookings = dict()
     
     layers = visiting_group.get('layers',  list())
     
     layers.append(dict(title=visiting_group['name'],  colour='#ffe',  layer_id=visiting_group_id))
     unscheduled_bookings = []
     #...code repeat for making used_activities
     activities = dict()
     used_activities_keys = dict()
     for x in getAllActivities(holly_couch):
         activities[x.key[1]] = x.doc
     
     for tmp_layer in layers:
         tmp_visiting_group = common_couch.getVisitingGroup(holly_couch,  tmp_layer['layer_id'])
         bookings_list = self.get_program_layer_bookings(tmp_visiting_group,  tmp_visiting_group['name'],  tmp_layer['colour'])
     
         for tmp_booking in bookings_list:
             tmp_booking['layer_colour'] = tmp_layer['colour']
             if '' != tmp_booking['slot_id']:
                 tmp_time_id = slot_id_time_id_map[tmp_booking['slot_id']]
                 #if hide_comment==1:
                 hide_cache_content_in_booking(tmp_booking)
                 
                 tmp_id = tmp_booking['booking_day_id'] + ':' +tmp_time_id
                 if not bookings.has_key(tmp_id):
                     bookings[tmp_id] = list()
                 bookings[tmp_id].append(tmp_booking)
             else:
                 hide_cache_content_in_booking(tmp_booking)
                 unscheduled_bookings.append(tmp_booking)
             #...fix used activities
             used_activities_keys[tmp_booking['activity_id']] = 1
             used_activities_keys[activities[tmp_booking['activity_id']]['activity_group_id']] = 1
     
     result['bookings'] = bookings
     result['width_ratio'] = width_ratio
     
     result['unscheduled_bookings'] = unscheduled_bookings
     result['booking_info_notes'] = [n.doc for n in getBookingInfoNotesOfUsedActivities(holly_couch, used_activities_keys.keys())]
     return result
Beispiel #2
0
 def program_layer_get_bookings(self, visiting_group_id,  layer_title='',  layer_colour='#fff' ):
     visiting_group = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     bookings = self.get_program_layer_bookings(visiting_group,  layer_title,  layer_colour)
     
     processed_bookings = list()
     for b in bookings:
         hide_cache_content_in_booking(b)
         processed_bookings.append(b)
     
     bucket_texts = []
     for tmp in getAllProgramLayerBucketTexts(holly_couch,  visiting_group_id):
         tmp_doc = tmp.doc
         tmp_doc['layer_title']=visiting_group['name']
         tmp_doc['layer_colour'] = '#fff'# layer_colour
         
         # TODO: check if we want to hide comments. Really. Probably more dependent on who is logged in. Like program staff or visiting group
         #self.hide_cache_content_in_booking(tmp_doc)
         bucket_texts.append(tmp_doc)
     
     return dict(bookings=processed_bookings,  bucket_texts=bucket_texts)
Beispiel #3
0
    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)