예제 #1
0
    def _to_python(self,value,state):
        #raise Exception('%s'%value)
        import time
        c.schedules_amt = len(value)

        oschedules=[]
        for val in value:
            val['h']['fr'] = h_fr = self.parse_time(val['h']['fr'])
            val['h']['to'] = h_to = self.parse_time(val['h']['to'])
            
            if not h_fr: raise formencode.Invalid(_(u'שעה תחתונה לא חוקית - %s')%val['h']['fr'],value,state)
            if not h_to: raise formencode.Invalid(_(u'שעה עליוה חוקית - %s')%val['h']['to'],value,state)
            if h_to<=h_fr: raise formencode.Invalid(_(u'טווח שעות אינו חוקי'),val,state)
            try:
                for d in val['d']: 
                    if int(d) not in range(1,8): raise formencode.Invalid(_(u'יום אינו חוקי %s')%d,value,state)
            except KeyError:
                raise formencode.Invalid(_(u'לא בחרת אף יום'),value,state)

            #check if schedule crosses with other schedules for this
            sc = Schedule()
            myweekdays=[]
            for dn in val['d']:
                myweekdays.append(ScheduleWeekday())
                myweekdays[-1].weekday = int(dn)
            sc.weekdays = myweekdays
            hr = ScheduleHour()
            hr.time_from = h_fr
            hr.time_to = h_to
            sc.hours = [hr]

            for sc2 in oschedules:
                if sc.overlaps(sc2):
                    state.schedule_valid=False
                    raise formencode.Invalid(_(u'שעות אלו כבר תפוסות בלו"ז שלך.'),value,state)
            oschedules.append(sc)

            #raise Exception('%s'%val)
            state.schedule_valid=True
        return value
예제 #2
0
    def noval_signup(self,id=None):
        log.info('in signup method')
        poly_data = request.params.get('poly_data')
        existing_area = request.params.get('existing_area')
        existing_marker = request.params.get('existing_marker')
        
        if type(self).update_mode:
            #raise Exception('getting activity %s , %s'%(id,request.params))
            act = meta.Session.query(Activity).get(id)
            if not act.user_id==c.user_id: raise Exception('security violation trying to update someone elses s***e')
        else:
            act = Activity()
        act.user = meta.Session.query(User).get(c.user_id)
        act.activity_type=type(self).activity_type
        #raise Exception('act user is %s'%act.user)
        if c.inserted_area:
            act.area = a = c.inserted_area
        elif existing_area:
            log.info('about to commit - existing area is %s'%existing_area)
            act.area_id = existing_area
        elif act.activity_type=='courier':
            raise Exception('no area set to be inserted with this activity!')
        if c.inserted_marker:
            act.marker = im = c.inserted_marker
        elif existing_marker:
            #act.marker = im = meta.Session.query(Area).get(existing_marker)
            act.marker_id = existing_marker
        elif act.activity_type=='business':
            raise Exception('no location set to be inserted with this activity')


        #raise Exception('about to insert activity with area %s (area_id %s) , user %s and activity type "%s"'%(act.area,act.area_id,act.user,act.activity_type))
        self.add_extra_fields(act)

        if type(self).update_mode: 
            [meta.Session.delete(sch) for sch in act.schedules]
        else:
            meta.Session.add(act)
        meta.Session.commit()
        if 'schedule' in self.form_result:
            for sch in self.form_result['schedule']:
                scho = Schedule()
                scho.activity = act
                meta.Session.add(scho)
                sch_h = ScheduleHour()
                sch_h.schedule = scho
                sch_h.time_from = (sch['h']['fr'])
                #raise Exception(type(sch['h']['fr']))
                sch_h.time_to = (sch['h']['to'])
                meta.Session.add(sch_h)
                for dn in sch['d']:
                    sch_d = ScheduleWeekday()
                    sch_d.schedule = scho
                    sch_d.weekday = dn
                    meta.Session.add(sch_d)
        
        meta.Session.commit()
        if type(self).update_mode:
            return redirect(url.current(controller=act.activity_type,id=act.id,justadded=False))
        else:
            return redirect(url.current(controller=act.activity_type,action='matches_map',id=act.id,justadded=True))