Example #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
Example #2
0
 def program_layer_save_layer_text(self,  visiting_group_id='', booking_day_id='',  bucket_time='', layer_text_id='',  text='',  title=''):
     is_new = (layer_text_id=='')
     
     if is_new:
         id = genUID(type='program_layer_text')
         
         #...if slot_id is none, we need to figure out slot_id of bucket_time OR we simply save bucket_time
         
         layer_text = dict(type='program_layer_text',  subtype='layer_text',  state=0,  booking_day_id=booking_day_id, bucket_time=bucket_time )
         #...populate sheets and computed sheets?
         
         layer_text['text'] = text
         layer_text['title'] = title
         layer_text['visiting_group_id'] = visiting_group_id
         holly_couch[id] = layer_text
     else:
         layer_text = common_couch.getLayerText(holly_couch, layer_text_id)
         
         
         layer_text['text'] = text
         layer_text['title'] = title
         holly_couch[layer_text['_id']] = layer_text
         # TODO call it bucket text or layer text ?
         
     visiting_group =  common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     layer_text['layer_title']=visiting_group['name']
     layer_text['layer_colour'] = "#fff"
     return dict(layer_text=layer_text) 
Example #3
0
    def edit_group_data(self, visiting_group_id='', subtype='', **kwargs):
#        visiting_group_x = holly_couch[visiting_group_id]
        tmpl_context.form = create_edit_vodb_group_form
        
        is_new = ((None == visiting_group_id) or ('' == visiting_group_id))
        if is_new:
            properties_template = dict()
            
            if subtype == 'program':
                properties_template = program_visiting_group_properties_template
                
            if subtype == 'staff':
                properties_template = staff_visiting_group_properties_template
                
            if subtype =='course':
                properties_template = course_visiting_group_properties_template
                
            visiting_group = DataContainer(name='',  id=None, _id=None,   info='',  visiting_group_properties=properties_template,  subtype=subtype,  contact_person='',  contact_person_email='',  contact_person_phone='',  boknr='')
        
        else:
            visiting_group_c = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
            for k in ['vodb_contact_name', 'vodb_contact_email', 'vodb_contact_phone', 'vodb_contact_address']:
                if not visiting_group_c.has_key(k):
                    visiting_group_c[k] = ''
            if not visiting_group_c.has_key('subtype'):
                visiting_group_c['subtype'] = 'program'
            visiting_group = makeVODBGroupObjectOfVGDictionary(visiting_group_c)
        
        
#        #...add data if it doesent exist
#        if not visiting_group_x.has_key('vodb_status'):
#            visiting_group_x['vodb_status'] = 0
         
        return dict(vodb_group=visiting_group, reFormatDate=reFormatDate, bokn_status_map=workflow_map, is_new=is_new)
Example #4
0
 def edit_layers(self, visiting_group_id):
     vgroup = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     vgroup_layers = vgroup.get('layers',  list())
     
     #...make map of layers from list of layers, keyed on id
     vgroup_layers_map = dict()
     for tmp_vgroup_layer in vgroup_layers:
         vgroup_layers_map[tmp_vgroup_layer['layer_id']] = tmp_vgroup_layer
     
     #...get all visiting group that possibly could be mapped
     vgroups_in_daterange = getVisitingGroupsInDatePeriod(holly_couch,  vgroup['from_date'],  vgroup['to_date'])
     
     #...build data struct for dojo spreadsheet / grid
     grid_items= list()
     for tmp_vgroup_row in vgroups_in_daterange:
         tmp_vgroup = tmp_vgroup_row.doc
         if tmp_vgroup['_id'] != vgroup['_id']:
             if tmp_vgroup['_id'] in vgroup_layers_map.keys():
                 grid_items.append(dict(layer_id=tmp_vgroup['_id'],  name=tmp_vgroup['name'],  connect=True, colour=vgroup_layers_map[tmp_vgroup['_id']]['colour'] )) # change colours
             else:
                 grid_items.append(dict(layer_id=tmp_vgroup['_id'],  name=tmp_vgroup['name'],  connect=False, colour="#fff" ))
     
     grid_data = dict(identifier='layer_id', items=grid_items)
     layer_data = json.dumps(grid_data)
     return dict(visiting_group=vgroup,  layer_data=layer_data,  reFormatDate=reFormatDate)
Example #5
0
    def edit_visiting_group(self,  visiting_group_id=None, subtype='',  **kw):
        tmpl_context.form = create_edit_visiting_group_form

        is_new = ((None == visiting_group_id) or ('' == visiting_group_id))
        if is_new:
            log.info('edit new visiting group')
            properties_template = dict()

            if subtype == 'program':
                properties_template = program_visiting_group_properties_template

            if subtype == 'staff':
                properties_template = staff_visiting_group_properties_template

            if subtype =='course':
                properties_template = course_visiting_group_properties_template

            visiting_group = dict(name='',  id=None, _id=None,   info='',  visiting_group_properties=properties_template,  subtype=subtype,  contact_person='',  contact_person_email='',  contact_person_phone='',  boknr='')

        else:
            log.info('looking up existing visiting group %s' % str(visiting_group_id))
            visiting_group_c = common_couch.getVisitingGroup(holly_couch, visiting_group_id)
            if not visiting_group_c.has_key('subtype'):
                visiting_group_c['subtype'] = 'program'
            visiting_group = makeVisitingGroupObjectOfVGDictionary(visiting_group_c)

        return dict(visiting_group=visiting_group, is_new=is_new) # bokn_status_map=bokn_status_options,  is_new=is_new
Example #6
0
 def program_layer_get_layer_text(self,  layer_text_id=''):
     layer_text = common_couch.getLayerText(holly_couch, layer_text_id)
     visiting_group =  common_couch.getVisitingGroup(holly_couch,  layer_text['visiting_group_id'])
     
     layer_text['layer_title']=visiting_group['name']
     layer_text['layer_colour'] = "#fff"
     layer_text['layer_text_id'] = layer_text['_id']
     return dict(layer_text=layer_text)
Example #7
0
    def delete_tag(self, id, tag):
        vgroup = common_couch.getVisitingGroup(holly_couch,  id)
        old_tags = vgroup.get('tags',[])
        new_tags = [t for t in old_tags if t.strip() != tag.strip()]
        vgroup['tags'] = new_tags
        holly_couch[id] = vgroup
        remember_tag_change(holly_couch, old_tags=old_tags, new_tags=new_tags, visiting_group_id=id, visiting_group_name=vgroup['name'], changed_by=getLoggedInUserId(request))

        return dict(tags=new_tags)
Example #8
0
 def copy_vodb_contact_info(self, visiting_group_id=None):
     visiting_group_o = common_couch.getVisitingGroup(holly_couch,  visiting_group_id) 
     
     if visiting_group_o.get('contact_person', '')  == '': 
         visiting_group_o['contact_person'] = visiting_group_o.get('vodb_contact_name', '')
     if visiting_group_o.get('contact_person_email', '') == '':
         visiting_group_o['contact_person_email'] = visiting_group_o.get('vodb_contact_email', '')
     if visiting_group_o.get('contact_person_phone', '') == '':
         visiting_group_o['contact_person_phone'] = visiting_group_o.get('vodb_contact_phone', '')
     holly_couch[visiting_group_id] = visiting_group_o
     raise redirect(request.referrer)
Example #9
0
 def add_tags(self, id, tags):
     vgroup = common_couch.getVisitingGroup(holly_couch,  id)
     old_tags = vgroup.get('tags',[])
     remember_old_tags = [t for t in old_tags]
     new_tags = [t.strip() for t in tags.split(',')]
     for t in new_tags:
         if t not in old_tags:
             old_tags.append(t)
     vgroup['tags'] = old_tags
     holly_couch[id] = vgroup
     remember_tag_change(holly_couch, old_tags=remember_old_tags, new_tags=old_tags, visiting_group_id=id, visiting_group_name=vgroup['name'], changed_by=getLoggedInUserId(request))
     
     return dict(tags=old_tags)
Example #10
0
 def update_visiting_group_program_layers(self, visiting_group_id,  save_button=None,  layer_data=''):
     vgroup = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     vgroup_layers = vgroup.get('layers',  list())
     
     layer_json = json.loads(layer_data)
     layer_to_save = list()
     
     for tmp_layer_data in layer_json['items']:
         if tmp_layer_data['connect']:
             layer_to_save.append(dict(layer_id=tmp_layer_data['layer_id'],  colour=tmp_layer_data['colour'],  name=tmp_layer_data['name'])) 
     
     vgroup['layers'] = layer_to_save
     holly_couch[vgroup['_id']] = vgroup
     raise redirect(request.referer)
Example #11
0
 def show_visiting_group_data(self,  id=None,  **kw):
     
     properties=[]
     if None == id:
         visiting_group = DataContainer(name='',  id=None,  info='')
         
     elif id=='':
         visiting_group = DataContainer(name='',  id=None,  info='')
         
     else:
         visiting_group = common_couch.getVisitingGroup(holly_couch,  id) 
         
         properties=[p for p in visiting_group['visiting_group_properties'].values()]
         
     return dict(visiting_group=visiting_group, properties=properties)
Example #12
0
    def show_visiting_group(self, visiting_group_id=None,  **kw):

        if None == visiting_group_id:
            visiting_group = DataContainer(name='', id=None,  info='')
            bookings=[]
            notes=[]
        elif visiting_group_id=='':
            visiting_group = DataContainer(name='', id=None,  info='')
            bookings=[]
            notes=[]
        else:
            visiting_group = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)

            # TODO: there is no composite view any more showing both bookings and visiting group data
            bookings = []
            notes = [n.doc for n in getNotesForTarget(holly_couch, visiting_group_id)]
        return dict(visiting_group=visiting_group, bookings=bookings, workflow_map=workflow_map,  getRenderContent=getRenderContent, program_state_map=bokn_status_map, vodb_state_map=bokn_status_map, reFormatDate=reFormatDate, notes=notes)
Example #13
0
    def show_visiting_group_data(self, id=None, **kw):
        log.debug('show_visiting_group_data with id "%s"' % str(id))
        properties=[]
        if None == id:
            log.info('show_visiting_group_data: id is None')
            visiting_group = dict(name='', id=None, info='')

        elif '' == id:
            log.info('show_visiting_group_data: id is empty string')
            visiting_group = dict(name='', id=None, info='')

        else:
            visiting_group = common_couch.getVisitingGroup(holly_couch, id)

            properties=[p for p in visiting_group['visiting_group_properties'].values()]

        return dict(visiting_group=visiting_group, properties=properties)
Example #14
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)
Example #15
0
 def layers(self, visiting_group_id):
     vgroup = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     notes = [n.doc for n in getNotesForTarget(holly_couch, visiting_group_id)]
     return dict(visiting_group=vgroup,  notes=notes,  tags=[],  reFormatDate=reFormatDate,  program_state_map=bokn_status_map)
Example #16
0
 def edit_vodb_data(self, id):
     vgroup = common_couch.getVisitingGroup(holly_couch,  id)
     return dict(visiting_group=vgroup)
    def update_visiting_group_program_request(self, program_request_info='', contact_person='', contact_person_email='', contact_person_phone='', vgroup_id='', program_request_input='', have_skippers=False, miniscout=False, ready_to_process=False, age_group_input='', saveButton='', submitButton=''):
        # TODO: once property data has changed, we somehow need to propagate that property data to all places where the properties are used BUT I dont think we really waht to propagate it unless we do some state-change,
        # we probably want to check the data before it is allowed to progress into other parts of the system.
        # TODO: We lost a lot of work, but our aim is to introduce the validation_error_messages list to contain all problems we have encountered.
        # what about making a subclassed list which can add speciealy formatted messages?
        # also, we should hav a comprehensive from-date-to-date checker
        #
        # dont forget to check for empty fm/em/evening
        # also common_couch code should be added
        #
        # make a validation_error_contect object that can be passed around and a date range checker and similar.
        # essentially we want to store section(1,2,3) property name and message. How to fix it.
        #
        #
        # 
        log.info("update_visiting_group_program_request()")
        ensurePostRequest(request, __name__)
        validation_error_messages = ValidationErrorMessages()
        
        visiting_group_id = str(vgroup_id)
        visiting_group_o = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
        
        may_change_request_data = (0  == visiting_group_o['boknstatus'])
        visiting_group_o['contact_person'] = contact_person
        visiting_group_o['contact_person_email'] = contact_person_email
        visiting_group_o['contact_person_phone'] = contact_person_phone
        

        if may_change_request_data:    
            visiting_group_o['program_request_info'] = program_request_info
            visiting_group_o['program_request_miniscout'] = miniscout
            visiting_group_o['program_request_have_skippers'] = have_skippers
            visiting_group_o['program_request_age_group'] = age_group_input
            visiting_group_o['program_request'] = program_request_input
        
            #...iterate through age_group_data, items is a list of dicts...
            age_group_data = json.loads(age_group_input)
            age_group_data_items = age_group_data['items']
        
            #...We should process the properties of the submitted form, not the other way around
        
            for tmp_age_group in age_group_data_items:
                process_property = tmp_age_group['property']
                log.debug('processing property:' + process_property )

                tmp_vgroup_property = None
                property_found = False
                property_id = None
                for tmp_vgroup_property_id,  tmp_vgroup_property in visiting_group_o['visiting_group_properties'].items():
                    if tmp_vgroup_property['property'] == process_property:
                        property_found = True
                        property_id = tmp_vgroup_property
                        log.debug('*** property %ss match found, property_id=%s' % (process_property,  property_id))
                        break
            
                if property_found:
                    log.debug('old: ' + str(process_property) + '=' + str(tmp_vgroup_property['value']))
            
                    # TODO: maybe sanitize so value must be an int?
                    tmp_vgroup_property['value'] = tmp_age_group['value']
                    
                    #...check that dates are within valid ranges
                    ok_1,  tmp_vgroup_property['from_date'] = sanitizeDate(tmp_age_group['from_date'],  default_date=tmp_vgroup_property['from_date']  )
                    if not ok_1:
                        validation_error_messages.report('properties',  u'Från-datum som tillhör åldersgrupp %s har fel format.' % tmp_vgroup_property['property'], problematic_value=tmp_age_group['from_date'], explanation_key='date_format' )
                    ok_2,  tmp_vgroup_property['to_date'] = sanitizeDate(tmp_age_group['to_date'],  default_date=tmp_vgroup_property['to_date'] )
                    if not ok_2:
                        validation_error_messages.report('properties',  u'Till-datum som tillhör åldersgrupp %s har fel format.' % tmp_vgroup_property['property'], problematic_value=tmp_age_group['to_date'], explanation_key='date_format' )
                    ok_3 = (tmp_vgroup_property['to_date']  >=  tmp_vgroup_property['from_date'] )
                    if not ok_3:
                        validation_error_messages.report('properties',  u'Till-datum kan inte inträffa före från-datum, se datumen i åldersgruppen %s.' % tmp_vgroup_property['property'], problematic_value=tmp_age_group['from_date']  + ' - ' + tmp_age_group['from_date'], explanation_key='date_order' )
                    ok_4 = tmp_vgroup_property['from_date'] >= visiting_group_o['from_date']
                    if not ok_4:
                        validation_error_messages.report('properties',  u'Från-datum %s som tillhör åldersgrupp %s kan inte inträffa före från-datum %s för din grupp.' % (tmp_vgroup_property['from_date'],  tmp_vgroup_property['property'], visiting_group_o['from_date']), problematic_value=tmp_vgroup_property['from_date'],  explanation_key='date_range') 
                    ok_5 = tmp_vgroup_property['to_date'] <= visiting_group_o['to_date']
                    if not ok_5:
                        validation_error_messages.report('properties',  u'Till-datum %s som tillhör åldersgrupp %s kan inte inträffa efter från-datum %s för din grupp.' % (tmp_vgroup_property['to_date'],  tmp_vgroup_property['property'], visiting_group_o['to_date']), problematic_value=tmp_vgroup_property['to_date'],  explanation_key='date_range') 
                    
                    
                    
                    log.debug('new: ' + process_property + '=' + str(tmp_age_group['value']))
                    #visiting_group_o['visiting_group_properties'][property_id] = tmp_vgroup_property
                else: # property not found, new property
                    log.debug('property not found, what do we do?')
                
                    if 0 == tmp_age_group['value']:
                        log.debug('never mind, value is zero')
                    else:
                        #...we need to add an entry in the dict, first we need to know the lowest key number
                        lowest_key_number = 0
                        for tmp_key in visiting_group_o['visiting_group_properties'].keys():
                            if tmp_key > lowest_key_number:
                                lowest_key_number = int(tmp_key)
                        lowest_key_number +=1
                        
                        # TODO: Date sanitation here too
                        ok_6,  new_from_date = sanitizeDate(tmp_age_group['from_date'],  default_date=visiting_group_o['from_date'] )
                        if not ok_6:
                            validation_error_messages.report('properties',  u'Från-datum som tillhör åldersgrupp %s har fel format.' % tmp_vgroup_property['property'], problematic_value=tmp_age_group['from_date'], explanation_key='date_format' )
                        ok_7,  new_to_date = sanitizeDate(tmp_age_group['to_date'],  default_date=visiting_group_o['to_date'] )
                        if not ok_7:
                            validation_error_messages.report('properties',  u'Till-datum som tillhör åldersgrupp %s har fel format.' % tmp_vgroup_property['property'], problematic_value=tmp_age_group['to_date'], explanation_key='date_format' )
                            
                        ok_8 = (new_from_date <= new_to_date)
                        if not ok_8:
                            validation_error_messages.report('properties',  u'Till-datum kan inte inträffa före från-datum, se datumen i åldersgruppen %s.' % tmp_vgroup_property['property'], problematic_value=tmp_age_group['from_date']  + ' - ' + tmp_age_group['from_date'], explanation_key='date_order' )
                        ok_9 = tmp_age_group['from_date'] >= visiting_group_o['from_date']
                        if not ok_9:
                            validation_error_messages.report('properties',  u'Från-datum %s som tillhör åldersgrupp %s kan inte inträffa före från-datum %s för din grupp.' % (tmp_vgroup_property['from_date'],  tmp_vgroup_property['property'], visiting_group_o['from_date']), problematic_value=tmp_vgroup_property['from_date'],  explanation_key='date_range') 
                        ok_10 = tmp_age_group['to_date'] <= visiting_group_o['to_date']
                        if not ok_10:
                            validation_error_messages.report('properties',  u'Till-datum %s som tillhör åldersgrupp %s kan inte inträffa efter från-datum %s för din grupp.' % (tmp_vgroup_property['to_date'],  tmp_vgroup_property['property'], visiting_group_o['to_date']), problematic_value=tmp_vgroup_property['to_date'],  explanation_key='date_range') 
                    
                        new_property_row = {u'description': tmp_age_group['age_group'], u'value': tmp_age_group['value'], u'from_date': new_from_date, u'to_date': new_to_date, u'property': tmp_age_group['property'], u'unit': tmp_age_group['unit']}
                        x = visiting_group_o['visiting_group_properties']
                        x[str(lowest_key_number)] = new_property_row
                        visiting_group_o['visiting_group_properties'] = x
            
            visiting_group_o['validation_error_messages'] = validation_error_messages
            visiting_group_o['validation_error_explanations'] = validation_error_messages.explanations
            holly_couch[visiting_group_o['_id']] = visiting_group_o
        
        # TODO: We should have a two step process: first construct all bookings (make a list) and if it all is successfull and no validation errors, thats when we actually write them to the db.
        
        # for the program request , iterate through it
        if may_change_request_data and not validation_error_messages.hasErrors():
            if 'True' == ready_to_process:
                program_request_list = json.loads(program_request_input)
                for tmp_request in program_request_list['items']:
                    log.debug('found request...' + str(tmp_request))
                    request_for_age_groups = [x[4:] for x in ['age_sma','age_spar','age_uppt','age_aven','age_utm','age_rov','age_led'] if tmp_request[x]]
                    
                    if len(request_for_age_groups) > 0:
                        
                        #...TODO: sanitize requested_date and make sure it is in range
                        ok_r1, requested_date = sanitizeDate(tmp_request['requested_date'][:10],  default_date='')
                        if not ok_r1:
                            validation_error_messages.report('booking request',  u'Det angivna önskade datumet %s har fel format.' % tmp_request['requested_date'], problematic_value=tmp_request['requested_date'],  explanation_key='date_format')
                        if not ((requested_date >= visiting_group_o['from_date']) and (requested_date <= visiting_group_o['to_date'])):
                            validation_error_messages.report('booking request',  u'Det efterfrågade datumet %s är inte mellan din grupps från- och till- datum.' % tmp_request['requested_date'], problematic_value=tmp_request['requested_date'],  explanation_key='date_range')
                        # TODO: reuse the parsing of the date
                        requested_date_o = time.strptime(requested_date, "%Y-%m-%d" )
                        requested_time = tmp_request['requested_time']
                        requested_activity_id = tmp_request['requested_activity']
                        
                        no_activity_selected = ('' == requested_activity_id)
                        
                        # TODO: what if there is no requested activity?
                        # TODO: how do users choose not to which anything after they have made a request? I think we actually will need a NULL request and this is where we among other things check the null request.
                        
                        booking_day_o = getBookingDayOfDate(holly_couch, requested_date)
                        log.debug(booking_day_o)
                        day_schema_id = booking_day_o['day_schema_id']
                        
                        #...TODO day shema will probably always be the same so just query once per schema
                        schema_o = common_couch.getDaySchema(holly_couch,  day_schema_id)                        
                        
                        #...given fm/em/evening, look up the matching slot_id. Probably the schema will be needed (and maybe index 0,1,2,3...)
                        tmp_activity_row = schema_o['schema'][requested_activity_id]
                        
                        #...look through the list, lets say we have a time and we need the slot id matching that time
                        #   then the reasonable way is too look through all list entries being dicts and return slot id when time match found
                        activity_selection_map = dict()
                        activity_selection_map['activity.30'] = u'Storbåt'
                        
                        time_selection_lookup = dict(FM='10:00:00', EM='15:00:00', EVENING='20:00:00')
                        
                        #...EVENING should be called Kväll
                        #   It should be possible to book just 'any' water program
                        #   these maps with id-text transaltion should maybe be available in the templating engine
                        #   dont forget to give the date formatter to the templating engine
                        
                        time_selection_translator = dict(EVENING=u'kväll')
                        if validation_error_messages.hasErrors():
                            holly_couch[visiting_group_o['_id']] = visiting_group_o
                            raise redirect(request.referrer)
                            
                        for tmp_slot_info in tmp_activity_row[1:]:
                            if (tmp_slot_info['time_from'] < time_selection_lookup[requested_time]) and (tmp_slot_info['time_to'] > time_selection_lookup[requested_time]):
                                match_slot_id = tmp_slot_info['slot_id']
                                log.debug('match for slot_id: ' + match_slot_id)
                                
                                # lets create a booking!
                                # TODO: refactor the creation of a new booking
                                new_booking = dict(type='booking',  valid_from='',  valid_to='',  requested_date=requested_date, slot_id=match_slot_id, booking_day_id=booking_day_o['_id'],  subtype='program')
                                new_booking['visiting_group_id'] = str(vgroup_id)
                                new_booking['valid_from'] = visiting_group_o['from_date']
                                new_booking['valid_to'] = visiting_group_o['to_date']
                                new_booking['reuested_date'] = requested_date
                                new_booking['visiting_group_name'] = visiting_group_o['name']
                                new_booking['last_changed_by_id'] = getLoggedInUserId(request)
                                
                                activity_o = common_couch.getActivity(holly_couch, requested_activity_id)
                                
                                # TODO: the line below gts the properties wrong
                                content = u'%s (önskar %s %d/%d %s) %s' % ( ' '.join(['$$%s'%a for a in request_for_age_groups ]) ,activity_selection_map.get(requested_activity_id, activity_o['title']), int(time.strftime("%d", requested_date_o)),  int(time.strftime("%m", requested_date_o)), time_selection_translator.get(requested_time, requested_time), tmp_request['note'] )                                 
                                
                                new_booking['content'] = content
                                new_booking['cache_content'] = computeCacheContent(holly_couch[visiting_group_id], content)
                                new_booking['activity_id'] = requested_activity_id
            
                                
                                new_booking['booking_state'] = activity_o['default_booking_state']                                
                                
                                slot_map  = getSchemaSlotActivityMap(holly_couch, booking_day_o, subtype='program')
                                slot = slot_map[match_slot_id]
                                new_uid = genUID(type='booking')
                                
                                #...here we create the booking
                                holly_couch[new_uid] = new_booking
                                
                                #...remember the created booking
                                
                                remember_new_booking_request(holly_couch, booking=new_booking, changed_by=getLoggedInUserId(request))
                                break
                                
                visiting_group_o['boknstatus'] = 5 # TODO: use constant
                holly_couch[visiting_group_o['_id']] = visiting_group_o
        raise redirect(request.referrer)
Example #18
0
 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)
Example #19
0
 def get_tags(self, id):
     vgroup = common_couch.getVisitingGroup(holly_couch,  id)
     tags = vgroup.get('tags',[])
     return dict(tags=tags)
Example #20
0
    def view_bookings_of_visiting_group_id(self, visiting_group_id=None, render_time='', hide_comment=0, show_group=0):

        bookings = [b.doc for b in getBookingsOfVisitingGroup(holly_couch, '<- MATCHES NO GROUP ->', visiting_group_id)]
        visiting_group = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
        return self.view_bookings_of_visiting_group(visiting_group, visiting_group_id, visiting_group['name'], bookings, hide_comment=hide_comment, show_group=show_group, render_time=render_time)
Example #21
0
 def program_layer_new_layer_text(self,  visiting_group_id='',  booking_day_id='',  bucket_time=''):
     layer_text = dict(type='program_layer_text',  subtype='layer_text',  status=0, booking_day_id=booking_day_id, bucket_time=bucket_time,  text='',  title='' ,  visiting_group_id=visiting_group_id)
     visiting_group =  common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     layer_text['layer_title']=visiting_group['name']
     layer_text['layer_colour'] = "#fff"
     return dict(layer_text=layer_text)
Example #22
0
 def set_vodb_state(self, visiting_group_id=None,  state=0):
     log.info("set_vodb_state()")
     ensurePostRequest(request, __name__)
     visiting_group_o = common_couch.getVisitingGroup(holly_couch,  visiting_group_id)
     self.do_set_vodb_state(holly_couch, visiting_group_id,  visiting_group_o, int(state))
     raise redirect(request.referrer)
Example #23
0
 def set_vodb_state(self, visiting_group_id=None,  state=0):
     visiting_group_o = common_couch.getVisitingGroup(holly_couch,  visiting_group_id) 
     self.do_set_vodb_state(holly_couch, visiting_group_id,  visiting_group_o, int(state))            
     raise redirect(request.referrer)