Beispiel #1
0
def delete_body(path, d, m, env):
    parent = model.parent(path)
    if parent:
        model.delete(path)
        return "\n", parent
    else:
        raise restlite.Status, '403 Forbidden'
Beispiel #2
0
def show_unit_tasks(path, parameters, env):
    group_container = parameters['groups']
    group_path = model.parent(path)+'/'+group_container
    groups = model.load(group_path)
    person_groups = {}
    for g in groups: 
        model.traverse(group_path+'/'+g, lambda (path, task, d): collect_persons(g, path, person_groups), all_nodes=True )    
    persons = set()
    for group in person_groups.values():
        for p in group:
            persons.add(p)        
    dates, slots, s = prepare_people_tasks( persons ) 
    schedules = {}
    for i in s:
        schedules[i[0]]=i
    group_schedules = []    
    for g in person_groups.keys():        
        group_sched = [ g, len(slots)*[0.0], 0, 0, {'url': group_path+'/'+g+'/planning/'} ]
        for _, person in person_groups[g]:
            group_sched[1] = [ group_sched[1][i] + schedules[person][1][i] for i in range(0,len(slots)) ]  
            group_sched[2] += schedules[person][2]
            group_sched[3] += schedules[person][3]
        n = len(person_groups[g])*1.0    
        group_sched[1] = [ i/n for i in group_sched[1] ]
        group_sched[2] /= n
        group_sched[3] /= n
        group_schedules.append(group_sched)    
    return visualize.render(dates, slots, sorted(group_schedules), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': False }), "text/html"    
Beispiel #3
0
def save_body(path, d, m, env):
    if d['type'] == 'leaf':
        original = copy.copy(m)
        model.check(path, m)
        errors = []
        if m['to'] and m['from'] and m['to'] < m['from']:
            errors.extend(('to', 'from'))
        if (not 'load' in original
                or original['load'] == '') and (not 'effort' in original
                                                or original['effort'] == ''):
            errors.extend(('load', 'effort'))
        if len(errors) > 0:
            raise model.ParseException(original, errors)
        model.create(path)
        model.save(path, m)
        return "\n", model.parent(path)
    if d['type'] == 'list' and 'name' in m:
        name = m['name']
        name = name.replace('?', '')
        name = name.replace('/', '')
        name = name.replace('#', '')
        new_path = path + "/" + name
        if path.strip() == '':
            return "\n", path
        model.create(new_path)
        if model.describe(new_path)['type'] == 'leaf' or model.describe(
                new_path)['type'] == 'render':
            model.save(new_path, {'name': m['name']})
        return "\n", new_path
    return None, path
Beispiel #4
0
def delete_body(path, d, m, env):
    parent = model.parent(path)
    if parent:
        model.delete(path)
        return "\n", parent
    else:
        raise restlite.Status, '403 Forbidden' 
Beispiel #5
0
def save_body(path, d, m, env):
    if d['type'] == 'leaf':
        original=copy.copy(m)
        model.check(path, m)
        errors = []
        if m['to'] and m['from'] and m['to'] < m['from']:
            errors.extend( ('to','from') )
        if (not 'load' in original or original['load'] == '') and (not 'effort' in original or original['effort'] == ''):
            errors.extend( ('load', 'effort') )
        if len(errors) > 0:
            raise model.ParseException(original, errors)
        model.create(path)        
        model.save(path, m)
        return "\n", model.parent(path)
    if d['type'] == 'list' and 'name' in m:
        name = m['name']
        name = name.replace('?', '')
        name = name.replace('/', '')
        name = name.replace('#', '')
        new_path = path+"/"+name
        if path.strip() == '':
            return "\n", path
        model.create(new_path)    
        if model.describe(new_path)['type'] == 'leaf' or model.describe(new_path)['type'] == 'render':
            model.save(new_path, { 'name': m['name'] })
        return "\n", new_path
    return None, path
Beispiel #6
0
def get_body(path, d, m, env):
    parent_type = None
    parent = model.parent(path)
    qs = urlparse.parse_qs(env['QUERY_STRING'])
    refreshable = 0
    if parent:
        parent_type = model.describe(parent)['type']
    if 'cache' in d:
        refreshable = 1
    variables = { 'context': '/', 'path':path, 'parent_type': parent_type, 'qs': qs, 'refreshable': refreshable, 'url' : path+"/"}
    if d['type'] == 'leaf':
        for k,v in m.iteritems():
            if v and type(v) == datetime.date:
                m[k]=v.strftime('%d.%m.%Y')
            if type(v) == float and v == int(v):
                m[k] = int(v)            
            if v == 0 or v == 0.0:
                m[k] = ''    
        errors = ()        
        if 'e' in qs:
            errors = qs['e']
            for k in m.keys():
                if k in qs:
                    m[k] = qs[k][0]
        variables.update({ 'attributes': m, 'errors': errors })
        return str(task_template(searchList=[ variables ])), None
    else:
        variables.update( { 'list' : m, 'type':  d['type'] })
        return str(list_template(searchList=[ variables ])), None
Beispiel #7
0
def show_tasks(path, parameters, env):
    tasks = []
    model.traverse(model.parent(path), lambda p: tasks.append(p[1]))
    qs = urlparse.parse_qs(env['QUERY_STRING'])
    expand = set()
    if 'x' in qs:
        expand.update(qs['x'])
    return scheduler.render(tasks, {
        'path': path,
        'qs': qs,
        'context': '/',
        'sum': False,
        'add': model.parent(path) + '/tasks/plan/',
        'url': path + '/',
        'refreshable': True
    },
                            resolution=week,
                            expand=expand), 'text/html;charset=utf-8'
Beispiel #8
0
def show_tasks(path, parameters, env):
    tasks = []
    model.traverse( model.parent(path), lambda p : tasks.append(p[1]))
    qs = urlparse.parse_qs(env['QUERY_STRING'])
    expand=set()
    if 'x' in qs:
        expand.update(qs['x'])
    return scheduler.render(tasks, { 'path': path, 'qs' : qs, 'context' : '/', 'sum': False, 'add': model.parent(path)+'/tasks/plan/', 'url': path+'/', 'refreshable': True }, 
        resolution=week, expand=expand), 'text/html;charset=utf-8'
Beispiel #9
0
def handle(env, start_response, handler, m=None):
    path = get_path(env)
    if len(path) > 0 and not path[-1] == '/':
        start_response('302 Redirect',
                       [('Location', model.normalize(path) + "/")])
        return
    path = model.normalize(path)
    try:
        d = model.describe(path)
        qs = urlparse.parse_qs(env['QUERY_STRING'])
        if not m and 'cache' in d:
            if 'r' in qs and qs['r'][0] == '1':
                if d['cache'] == 'normal':
                    model.invalidate_cache(path)
                if d['cache'] == 'parent':
                    model.invalidate_cache(model.parent(path))
        if d and d['type'] == 'render' and env['REQUEST_METHOD'] == 'GET':
            parameters = {}
            if 'parameters' in d:
                parameters = d['parameters']
            content, mime = render_handlers[d['function']](path, parameters,
                                                           env)
            start_response('200 OK', [('Content-Type', mime),
                                      ('Content-Length', str(len(content)))])
            return content
        if not m:
            m = model.load(path)
        content, redirect = handler(path, d, m, env)
        if redirect:
            redirect = model.normalize(redirect)
            close = ''
            if 'c' in qs:
                if qs['c'][0] == '0':
                    close = '?c=1'
                if qs['c'][0] == '1':
                    close = '?c=2'
            start_response('302 Redirect',
                           [('Location', redirect + "/" + close)])
            return
        else:
            start_response('200 OK',
                           [('Content-Type', 'text/html;charset=utf-8'),
                            ('Content-Length', str(len(content)))])
            return content
    except model.NotFoundException as e:
        import traceback
        traceback.print_exc()
        raise restlite.Status, '404 Not Found'
    except model.ParseException as e:
        d = {}
        d.update({'e': e.errors})
        d.update(e.attributes)
        start_response('302 Redirect', [('Location', model.normalize(path) +
                                         "/?" + urllib.urlencode(d, True))])
        return
Beispiel #10
0
def show_unit_tasks(path, parameters, env):
    group_container = parameters['groups']
    group_path = model.parent(path) + '/' + group_container
    groups = model.load(group_path)
    person_groups = {}
    for g in groups:
        model.traverse(
            group_path + '/' + g,
            lambda (path, task, d): collect_persons(g, path, person_groups),
            all_nodes=True)
    persons = set()
    for group in person_groups.values():
        for p in group:
            persons.add(p)
    dates, slots, s = prepare_people_tasks(persons)
    schedules = {}
    for i in s:
        schedules[i[0]] = i
    group_schedules = []
    for g in person_groups.keys():
        group_sched = [
            g,
            len(slots) * [0.0], 0, 0, {
                'url': group_path + '/' + g + '/planning/'
            }
        ]
        for _, person in person_groups[g]:
            group_sched[1] = [
                group_sched[1][i] + schedules[person][1][i]
                for i in range(0, len(slots))
            ]
            group_sched[2] += schedules[person][2]
            group_sched[3] += schedules[person][3]
        n = len(person_groups[g]) * 1.0
        group_sched[1] = [i / n for i in group_sched[1]]
        group_sched[2] /= n
        group_sched[3] /= n
        group_schedules.append(group_sched)
    return visualize.render(dates,
                            slots,
                            sorted(group_schedules),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': False
                            }), "text/html"
Beispiel #11
0
def handle(env, start_response, handler, m=None):    
    path = get_path(env)
    if len(path) > 0 and not path[-1] == '/':
        start_response('302 Redirect', [('Location', model.normalize(path)+"/")])            
        return
    path = model.normalize(path)
    try:
        d = model.describe(path)
        qs = urlparse.parse_qs(env['QUERY_STRING'])
        if not m and 'cache' in d:
                if 'r' in qs and qs['r'][0]=='1':
                    if d['cache'] == 'normal':
                        model.invalidate_cache(path)
                    if d['cache'] == 'parent':
                        model.invalidate_cache(model.parent(path))
        if d and d['type'] == 'render' and env['REQUEST_METHOD'] == 'GET':
            parameters = {}
            if 'parameters' in d:
                parameters = d['parameters']
            content, mime = render_handlers[d['function']](path, parameters, env)            
            start_response('200 OK', [('Content-Type', mime), ('Content-Length', str(len(content)))])        
            return content        
        if not m:
            m = model.load(path)
        content, redirect = handler(path, d, m, env)
        if redirect:
            redirect = model.normalize(redirect)
            close=''
            if 'c' in qs:
                if qs['c'][0]=='0':
                    close='?c=1'
                if qs['c'][0]=='1':
                    close='?c=2'
            start_response('302 Redirect', [('Location', redirect+"/"+close)])            
            return
        else:
            start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8'), ('Content-Length', str(len(content)))])        
            return content 
    except model.NotFoundException as e:   
        import traceback
        traceback.print_exc()
        raise restlite.Status, '404 Not Found'    
    except model.ParseException as e:
        d = {}
        d.update( { 'e': e.errors } )
        d.update(e.attributes)
        start_response('302 Redirect', [('Location', model.normalize(path)+"/?"+urllib.urlencode(d, True))])
        return
Beispiel #12
0
def show_team_tasks(path, parameters, env):
    people = model.parent(path) + '/people'
    person_list = model.load(people)
    dates, slots, s = prepare_people_tasks([(people, person)
                                            for person in person_list])
    return visualize.render(dates,
                            slots,
                            sorted(s),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': True
                            }), "text/html"
Beispiel #13
0
def get_body(path, d, m, env):
    parent_type = None
    parent = model.parent(path)
    qs = urlparse.parse_qs(env['QUERY_STRING'])
    refreshable = 0
    if parent:
        parent_type = model.describe(parent)['type']
    if 'cache' in d:
        refreshable = 1
    variables = {
        'context': '/',
        'path': path,
        'parent_type': parent_type,
        'qs': qs,
        'refreshable': refreshable,
        'url': path + "/"
    }
    if d['type'] == 'leaf':
        for k, v in m.iteritems():
            if v and type(v) == datetime.date:
                m[k] = v.strftime('%d.%m.%Y')
            if type(v) == float and v == int(v):
                m[k] = int(v)
            if v == 0 or v == 0.0:
                m[k] = ''
        errors = ()
        if 'e' in qs:
            errors = qs['e']
            for k in m.keys():
                if k in qs:
                    m[k] = qs[k][0]
        variables.update({'attributes': m, 'errors': errors})
        return str(task_template(searchList=[variables])), None
    else:
        variables.update({'list': m, 'type': d['type']})
        return str(list_template(searchList=[variables])), None
Beispiel #14
0
def show_team_tasks(path, parameters, env):    
    people = model.parent(path)+'/people'
    person_list = model.load(people)
    dates, slots, s = prepare_people_tasks(  [ ( people, person) for person in person_list ] )
    return visualize.render(dates, slots, sorted(s), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': True }), "text/html"