Example #1
0
    def create_living_schema(self):
        log.info("create_living_schema()")
        ensurePostRequest(request, __name__)
        ew_id = genUID(type='living_schema')
        schema = dict(type='day_schema',  subtype='room',  title='room schema 2013',  activity_group_ids=["activity_groups_ids", "roomgroup.fyrbyn", "roomgroup.vaderstracken", "roomgroup.vindarnashus","roomgroup.tunet",
        "roomgroup.skrakvik","roomgroup.tc","roomgroup.alphyddorna","roomgroup.gokboet","roomgroup.kojan"])
        all_activities = getAllActivities(holly_couch)

        #...create some living, map to all activities in ag groups house
        i=0
        z=0
        tmp_schema = dict()
        for tmp_act in list(all_activities):
            if tmp_act.has_key('activity_group_id') or True:
                if tmp_act.doc['activity_group_id'][:9] == 'roomgroup':
                    z += 1
                    tmp_id = dict(zorder=z,  id=tmp_act['id'])
                    tmp_fm = dict(time_from='00:00:00', time_to='12:00:00',  duration='12:00:00', title='FM',  slot_id='live_slot.' + str(i) )
                    i +=1
                    tmp_em = dict(time_from='12:00:00', time_to='23:59:00',  duration='12:00:00', title='EM',  slot_id='live_slot.' + str( i) )
                    #...create fm and em but nothing more
                    i+=1

                    tmp_schema[tmp_act['id']] = [tmp_id,  tmp_fm,  tmp_em]

        schema['schema'] = tmp_schema
        holly_couch[ew_id] = schema


        raise redirect(request.referer)
Example #2
0
    def view_vodb_group(self, visiting_group_id=''):
        visiting_group_o = holly_couch[visiting_group_id]
        
        #...construct the age group list. It's going to be a json document. Hard coded.
        #... if we are to partially load from database and check that we can process it, we do need to go from python to json. (and back)
        #...construct a program request template. It's going to be a json document. Hard coded.
        notes = [n.doc for n in getNotesForTarget(holly_couch, visiting_group_id)]
        
        visiting_group_o.show_vodb_live_sheet = json.dumps(dict(identifier='rid', items=visiting_group_o.get('vodb_live_computed', list())))
        visiting_group_o.show_vodb_eat_sheet = json.dumps(dict(identifier='rid', items=visiting_group_o.get('vodb_eat_computed', list())))
        visiting_group_o.show_vodb_tag_sheet = json.dumps(dict(identifier='rid', items=visiting_group_o.get('vodb_tag_computed', list())))


        #...find room_bookings
        activities = dict()
        for x in getAllActivities(holly_couch):
            activities[x.key[1]] = x.doc
            
        room_bookings = list()
        for b in getRoomBookingsOfVODBGroup(holly_couch,  visiting_group_id):
            
            #...lookup slot map
            live_schema_id = 'room_schema.2013' # TODO: Read dynamically from booking day 
            tmp_slot_row_data = list(holly_couch.view('day_schema/slot_map',  keys=[[b['slot_id'],  live_schema_id], [b['booking_end_slot_id'],  live_schema_id]]))

            start_time = tmp_slot_row_data[0].value[1]['time_from']
            end_time = tmp_slot_row_data[1].value[1]['time_to']
            b2 = DataContainer(booking_state=b['booking_state'],  cache_content=b['cache_content'],  content=b['content'] ,  activity=activities[b['activity_id']],  id=b['_id'],  booking_date=b.get('booking_date', 'Unknown'), booking_end_date=b.get('booking_end_date', 'Unknown'),  booking_day_id=b.get('booking_day_id', ''),  valid_from=b.get('valid_from',''),  valid_to=b.get('valid_to',''),  requested_date=b.get('requested_date',''),  start_time=start_time,  end_time=end_time)
            
            room_bookings.append(b2)
        
        
        tag_layout_tags = json.dumps(visiting_group_o['tags'])
        return dict(visiting_group=visiting_group_o, reFormatDate=reFormatDate, vodb_state_map=bokn_status_map, program_state_map=bokn_status_map, notes=notes, tag_layout_tags=tag_layout_tags,  room_bookings=room_bookings,  getRenderContent=getRenderContent)
Example #3
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
Example #4
0
    def create_living_schema(self):
        ew_id = genUID(type="living_schema")
        schema = dict(
            type="day_schema",
            subtype="room",
            title="room schema 2013",
            activity_group_ids=[
                "activity_groups_ids",
                "roomgroup.fyrbyn",
                "roomgroup.vaderstracken",
                "roomgroup.vindarnashus",
                "roomgroup.tunet",
                "roomgroup.skrakvik",
                "roomgroup.tc",
                "roomgroup.alphyddorna",
                "roomgroup.gokboet",
                "roomgroup.kojan",
            ],
        )
        all_activities = getAllActivities(holly_couch)

        # ...create some living, map to all activities in ag groups house
        i = 0
        z = 0
        tmp_schema = dict()
        for tmp_act in list(all_activities):
            if tmp_act.has_key("activity_group_id") or True:
                if tmp_act.doc["activity_group_id"][:9] == "roomgroup":
                    z += 1
                    tmp_id = dict(zorder=z, id=tmp_act["id"])
                    tmp_fm = dict(
                        time_from="00:00:00",
                        time_to="12:00:00",
                        duration="12:00:00",
                        title="FM",
                        slot_id="live_slot." + str(i),
                    )
                    i += 1
                    tmp_em = dict(
                        time_from="12:00:00",
                        time_to="23:59:00",
                        duration="12:00:00",
                        title="EM",
                        slot_id="live_slot." + str(i),
                    )
                    # ...create fm and em but nothing more
                    i += 1

                    tmp_schema[tmp_act["id"]] = [tmp_id, tmp_fm, tmp_em]

        schema["schema"] = tmp_schema
        holly_couch[ew_id] = schema

        raise redirect(request.referer)
Example #5
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)