Пример #1
0
    def admin(self, **kw):
        # view on a specific project
        grid = datagrid.track_admin_grid
        if kw.has_key('pid'):
            project_id = kw.get('pid')
            project = DBSession.query(Project).filter(Project.id == project_id).first()
            tracks = project.tracks
            kw['upload'] = True

            kw['pn'] = project.name
            track_list = [util.to_datagrid(grid, tracks, "Track Listing", len(tracks)>0)]

        else:
            if 'user_id' in kw:
                tracks = DBSession.query(Track).filter(Track.user_id == kw['user_id']).all()
            else:
                tracks = DBSession.query(Track).all()
            track_list = [util.to_datagrid(grid, tracks, "Track Listing", len(tracks)>0)]
            kw['upload'] = True

        # track list

        t = handler.help.tooltip['admin']

        # project list
        all_projects = DBSession.query(Project).all()
        project_list = [(p.id, p.name,) for p in all_projects]


        return dict(page='tracks', model='track', form_title="new track", track_list=track_list,
            project_list=project_list, shared_project_list=[], value=kw,
            tooltip=t, project_id=kw.get('pid', None), upload=kw.get('upload', None), project_name=kw.get('pn', None))
Пример #2
0
    def edit(self, *args, **kw):
        user = handler.user.get_user_in_session(request)

        # get circle id
        if request.method == 'GET':
            sequence_id = args[0]
        else :
            sequence_id = kw.get('cid')

        sequence_id=int(sequence_id)
        sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first()
        if not sequence:
            abort(404, 'Sequence with id %s not found' % sequence_id)

        if not sequence.public:
            add_user_widget = form.AddUser(action=url('/sequences/edit/%s' % sequence_id)).req()

            if request.method == 'POST':
                # add an user
                mail = kw.get('mail')
                try:
                    add_user_widget.validate({'cid' : sequence_id, 'mail' : mail})
                except twc.ValidationError as e:
                    users = ', '.join(['%s' % u.email for u in sequence.users])
                    default_tracks = ', '.join(['%s' % t.name for t in sequence.default_tracks])
                    kw['cid'] = sequence_id
                    users = sequence.users
                    for u in users:
                        u.__dict__['sid'] = sequence_id
                    widget = e.widget
                    widget.value = kw
                    return dict(page='sequences', users=users, add_user=add_user, add_user_widget=add_user_widget, default_tracks=default_tracks, au_error=True, seq_id=sequence_id)

                to_add = DBSession.query(User).filter(User.email == mail).first()
                if to_add is None:
                    to_add = handler.user.create_tmp_user(mail)
                sequence.users.append(to_add)
                DBSession.flush()

            kw['cid'] = sequence_id
            add_user_widget.value = kw

        else:
            add_user_widget = None

        users = sequence.users
        for u in users:
            u.__dict__['sid'] = sequence_id

        tracks = sequence.default_tracks
        for t in tracks:
            t.__dict__['sid'] = sequence_id

        add_user = util.to_datagrid(datagrid.sequence_user_grid, users, "Users", len(users)>0)

        def_tracks = util.to_datagrid(datagrid.sequence_default_tracks, tracks, "Default tracks", len(tracks)>0)

        return dict(page='sequences', users=users, add_user=add_user, add_user_widget=add_user_widget, default_tracks=def_tracks, au_error=False, seq_id=sequence_id)
Пример #3
0
    def index(self, *args, **kw):

        seq_form = form.NewSequenceForm(action=url('/sequences')).req()
        species = genrep.get_species()

        m = {}
        sp_to_add = []
        for sp in species:
            assemblies = genrep.get_assemblies_not_created_from_species_id(sp.id)
            if len(assemblies) > 0:
                m[sp.id] = [(ass.id, ass.name) for ass in assemblies]
                sp_to_add.append(sp)
        sp_opts =  [(sp.id, sp.species) for sp in sp_to_add]
        seq_form.child.children[1].options = sp_opts
        value = {'smapping' : json.dumps(m)}
        seq_form.value = value
        grid = datagrid.sequences_grid


        if request.method == 'GET':
            sequences = DBSession.query(Sequence).all()
            seq_grid = [util.to_datagrid(grid, sequences, "Sequences", len(sequences)>0)]

            return dict(page="sequences", widget=seq_form, grid=seq_grid)
        else :
            species_id = kw['species']
            assembly_id = kw['assembly']
            # look if the species already exist in GDV, else create it
            species = DBSession.query(Species).filter(Species.id == species_id).first()
            if not species:
                species = handler.genrep.get_species_by_id(species_id)
                current_sp = Species()
                current_sp.id = species.id
                current_sp.name = species.species
                DBSession.add(current_sp)
                DBSession.flush()
                current_sp = DBSession.query(Species).filter(Species.id == species_id).first()
                flash( '''Species created: %s'''%( current_sp ))

            # look if the assembly not already created, else create it
            if not DBSession.query(Sequence).filter(Sequence.id == assembly_id).first():
                assembly = handler.genrep.get_assembly_by_id(assembly_id)
                seq = Sequence()
                seq.id = assembly_id
                seq.name = assembly.name
                seq.species_id = species_id
                DBSession.add(seq)
                DBSession.flush()
                seq = DBSession.query(Sequence).filter(Sequence.id == assembly_id).first()
                handler.sequence.add_new_sequence(seq)
                flash( '''Sequence created: %s'''%( seq ))
            DBSession.flush()
            sequences = DBSession.query(Sequence).all()
            seq_grid = [util.to_datagrid(grid, sequences, "Sequences", len(sequences)>0)]
            return dict(page="sequences", widget=seq_form, grid=seq_grid)
Пример #4
0
    def edit(self, *args, **kw):
        user = handler.user.get_user_in_session(request)

        t = handler.help.tooltip['circledesc']

        # get circle id
        if request.method == 'GET':
            circle_id = args[0]
        else:
            circle_id = kw.get('cid')
        circle_id = int(circle_id)

        if circle_id not in [c.id for c in user.circles_owned]:
            flash('You have no right to edit this circle', 'error')
            raise redirect('/circles/')
        circle = DBSession.query(Circle).filter(Circle.id == circle_id).first()
        widget = form.AddUser(action=url('/circles/edit/%s' % circle_id)).req()

        if request.method == 'POST':
            # add user
            mail = kw.get('mail')
            try:
                widget.validate({'cid': circle_id, 'mail': mail})
            except twc.ValidationError as e:
                for u in circle.users:
                    u.__dict__['cid'] = circle_id
                wrappers = [u for u in circle.users if u.id != user.id]
                data = [util.to_datagrid(datagrid.circle_description_grid, wrappers, grid_display=len(wrappers) > 0)]
                return dict(page='circles', name=circle.name, widget=e.widget, items=data, value=kw, tooltip=t, au_error=True)
            mail = mail.lower()
            to_add = DBSession.query(User).filter(User.email == mail).first()
            if to_add is None:
                to_add = handler.user.create_tmp_user(mail)
            handler.circle.add_user(circle_id=circle_id, user=to_add)

        # build common parameters
        if not checker.user_own_circle(user.id, circle_id):
            flash('you have no right to edit this circle: you are not the creator of it')
            raise redirect('/circles')

        for u in circle.users:
            u.__dict__['cid'] = circle_id
        wrappers = [u for u in circle.users if u.id != user.id]

        data = [util.to_datagrid(datagrid.circle_description_grid, wrappers, grid_display=len(wrappers) > 0)]

        kw['cid'] = circle_id
        widget.value = kw
        return dict(page='circles', name=circle.name, widget=widget, items=data, tooltip=t)
Пример #5
0
    def export(self, track_id, *args, **kw):
        user = handler.user.get_user_in_session(request)
        trac = DBSession.query(Track).filter(Track.id == track_id).first()
        if not checker.can_download(user, trac):
            flash("You haven't the right to export any tracks which is not yours")
            raise redirect('../')

        data = util.to_datagrid(track_grid, [trac])
        tmpl_context.form = track_export
        kw['track_id'] = track_id
        return dict(page='tracks', model='Track', info=data, form_title='', value=kw)
Пример #6
0
    def index(self, *args, **kw):
        kw['page'] = 'circle'
        user = handler.user.get_user_in_session(request)

        data = util.to_datagrid(datagrid.circle_grid, user.circles_owned, grid_display=len(user.circles) > 0)
        t = handler.help.help_address(url('/help'), 'circles', 'help about circles')

        widget = form.NewCircle(action=url('/circles/index')).req()
        if request.method == 'GET':
            return dict(page='circles', item=data, tooltip=t, widget=widget)
        else:
            try:
                widget.validate(kw)
            except twc.ValidationError as e:
                return dict(page='circles',  item=data, tooltip=t, widget=e.widget, ac_error=True)

        user = handler.user.get_user_in_session(request)
        handler.circle.create(kw['name'], kw['description'], user)
        data = util.to_datagrid(datagrid.circle_grid, user.circles_owned, grid_display=len(user.circles) > 0)
        return dict(page='circles', model='circle', item=data, widget=widget, tooltip=t)
Пример #7
0
    def share(self, *args, **kw):
        user = handler.user.get_user_in_session(request)

        if request.method == 'GET':
            project_id = args[0]
        else:
            project_id = kw.get('pid')

        if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin(user=user):
            flash('You must have %s permission to share the project', 'error') % constants.right_upload
            raise redirect('/tracks', {'pid': project_id})

        project = DBSession.query(Project).filter(Project.id == project_id).first()
        widget = form.ShareProject(action=url('/projects/share/%s' % project_id))

        # public url
        pub = url('/public/project', {'id': project_id, 'k': project.key})
        # download url
        if project.download_key is None:
            project.download_key = project.setdefaultkey()
        down = url('/public/project', {'id': project_id, 'k': project.download_key})

        widget.value = {'pid': project_id}

        tl = handler.help.help_address(url('help'), '#share', 'sharing projects')

        if request.method == 'POST':
            if kw.has_key('rights'):
                rights_checkboxes = kw.get('rights_checkboxes', None)
                if rights_checkboxes is not None:
                    if not isinstance(rights_checkboxes,list):
                        rights_checkboxes = [rights_checkboxes]
                    handler.project.change_rights(kw.get('pid'), kw.get('cid'), rights=rights_checkboxes)
                else: handler.project.change_rights(kw.get('pid'), kw.get('cid'))


            else:
                circle_ids = kw.get('circles', [])
                if not circle_ids: circle_ids = []
                if not isinstance(circle_ids, list):
                    circle_ids = [circle_ids]
                if len(circle_ids) > 0 and '' in circle_ids: circle_ids.remove('')
                handler.project.e(project=project, circle_ids=circle_ids)

        debug(project.get_circle_with_right_display)

        cr_data = [util.to_datagrid(datagrid.project_sharing, project.circles_rights, "Sharing", len(project.circles_rights)>0)]

        widget.child.children[1].options =  [('','')] + [(c.id, c.name) for c in user.circles_sharing if c not in project.shared_circles] +\
                                            [(c.id, c.name, {'selected': True}) for c in project.shared_circles]

        return dict(page='projects', public=pub, download=down, name=project.name,
            tooltip_links=tl, widget=widget, items=cr_data, project_id=project_id)
Пример #8
0
 def admin(self):
     projects = DBSession.query(Project).all()
     data_projects = [
         util.to_datagrid(project_admin_grid, projects, "All projects",
                          len(projects) > 0)
     ]
     t = handler.help.tooltip['project']
     return dict(page='projects',
                 model='project',
                 tooltip=t,
                 form_title="new project",
                 projects=data_projects,
                 value={})
Пример #9
0
Файл: job.py Проект: bbcf/pygdv
    def index(self, *args, **kw):
        user = handler.user.get_user_in_session(request)
        if request.method == 'POST':
            jid = kw.get('id', None)
            if jid is not None and checker.can_edit_job(user.id, jid):
                handler.job.delete(jid)
            else:
                flash('not authorized')

        jobs = DBSession.query(Job).filter(Job.user_id == user.id).all()

        data = util.to_datagrid(datagrid.job_grid, jobs, "Job Listing", grid_display=len(jobs) > 0)
        t = handler.help.help_address(url('/help'), 'jobs', 'How to compute new data')

        return dict(page='jobs', model='job', form_title="new job", item=data, value=kw, tooltip=t)
Пример #10
0
    def index(self, *args, **kw):
        user = handler.user.get_user_in_session(request)
        if request.method == 'POST':
            jid = kw.get('id', None)
            if jid is not None and checker.can_edit_job(user.id, jid):
                handler.job.delete(jid)
            else:
                flash('not authorized')

        jobs = DBSession.query(Job).filter(Job.user_id == user.id).all()

        data = util.to_datagrid(datagrid.job_grid,
                                jobs,
                                "Job Listing",
                                grid_display=len(jobs) > 0)
        t = handler.help.help_address(url('/help'), 'jobs',
                                      'How to compute new data')

        return dict(page='jobs',
                    model='job',
                    form_title="new job",
                    item=data,
                    value=kw,
                    tooltip=t)
Пример #11
0
    def share(self, *args, **kw):
        user = handler.user.get_user_in_session(request)

        if request.method == 'GET':
            project_id = args[0]
        else:
            project_id = kw.get('pid')

        if not checker.check_permission(
                user=user,
                project_id=project_id,
                right_id=constants.right_upload_id) and not checker.is_admin(
                    user=user):
            flash('You must have %s permission to share the project',
                  'error') % constants.right_upload
            raise redirect('/tracks', {'pid': project_id})

        project = DBSession.query(Project).filter(
            Project.id == project_id).first()
        widget = form.ShareProject(action=url('/projects/share/%s' %
                                              project_id))

        # public url
        pub = url('/public/project', {'id': project_id, 'k': project.key})
        # download url
        if project.download_key is None:
            project.download_key = project.setdefaultkey()
        down = url('/public/project', {
            'id': project_id,
            'k': project.download_key
        })

        widget.value = {'pid': project_id}

        tl = handler.help.help_address(url('help'), '#share',
                                       'sharing projects')

        if request.method == 'POST':
            if kw.has_key('rights'):
                rights_checkboxes = kw.get('rights_checkboxes', None)
                if rights_checkboxes is not None:
                    if not isinstance(rights_checkboxes, list):
                        rights_checkboxes = [rights_checkboxes]
                    handler.project.change_rights(kw.get('pid'),
                                                  kw.get('cid'),
                                                  rights=rights_checkboxes)
                else:
                    handler.project.change_rights(kw.get('pid'), kw.get('cid'))

            else:
                circle_ids = kw.get('circles', [])
                if not circle_ids: circle_ids = []
                if not isinstance(circle_ids, list):
                    circle_ids = [circle_ids]
                if len(circle_ids) > 0 and '' in circle_ids:
                    circle_ids.remove('')
                handler.project.e(project=project, circle_ids=circle_ids)

        debug(project.get_circle_with_right_display)

        cr_data = [
            util.to_datagrid(datagrid.project_sharing, project.circles_rights,
                             "Sharing",
                             len(project.circles_rights) > 0)
        ]

        widget.child.children[1].options =  [('','')] + [(c.id, c.name) for c in user.circles_sharing if c not in project.shared_circles] +\
                                            [(c.id, c.name, {'selected': True}) for c in project.shared_circles]

        return dict(page='projects',
                    public=pub,
                    download=down,
                    name=project.name,
                    tooltip_links=tl,
                    widget=widget,
                    items=cr_data,
                    project_id=project_id)
Пример #12
0
 def admin(self):
     projects = DBSession.query(Project).all()
     data_projects = [util.to_datagrid(project_admin_grid, projects, "All projects", len(projects) > 0)]
     t = handler.help.tooltip['project']
     return dict(page='projects', model='project', tooltip=t, form_title="new project", projects=data_projects, value={})
Пример #13
0
    def edit(self, *args, **kw):
        user = handler.user.get_user_in_session(request)

        # get circle id
        if request.method == 'GET':
            sequence_id = args[0]
        else:
            sequence_id = kw.get('cid')

        sequence_id = int(sequence_id)
        sequence = DBSession.query(Sequence).filter(
            Sequence.id == sequence_id).first()
        if not sequence:
            abort(404, 'Sequence with id %s not found' % sequence_id)

        if not sequence.public:
            add_user_widget = form.AddUser(action=url('/sequences/edit/%s' %
                                                      sequence_id)).req()

            if request.method == 'POST':
                # add an user
                mail = kw.get('mail')
                try:
                    add_user_widget.validate({
                        'cid': sequence_id,
                        'mail': mail
                    })
                except twc.ValidationError as e:
                    users = ', '.join(['%s' % u.email for u in sequence.users])
                    default_tracks = ', '.join(
                        ['%s' % t.name for t in sequence.default_tracks])
                    kw['cid'] = sequence_id
                    users = sequence.users
                    for u in users:
                        u.__dict__['sid'] = sequence_id
                    widget = e.widget
                    widget.value = kw
                    return dict(page='sequences',
                                users=users,
                                add_user=add_user,
                                add_user_widget=add_user_widget,
                                default_tracks=default_tracks,
                                au_error=True,
                                seq_id=sequence_id)

                to_add = DBSession.query(User).filter(
                    User.email == mail).first()
                if to_add is None:
                    to_add = handler.user.create_tmp_user(mail)
                sequence.users.append(to_add)
                DBSession.flush()

            kw['cid'] = sequence_id
            add_user_widget.value = kw

        else:
            add_user_widget = None

        users = sequence.users
        for u in users:
            u.__dict__['sid'] = sequence_id

        tracks = sequence.default_tracks
        for t in tracks:
            t.__dict__['sid'] = sequence_id

        add_user = util.to_datagrid(datagrid.sequence_user_grid, users,
                                    "Users",
                                    len(users) > 0)

        def_tracks = util.to_datagrid(datagrid.sequence_default_tracks, tracks,
                                      "Default tracks",
                                      len(tracks) > 0)

        return dict(page='sequences',
                    users=users,
                    add_user=add_user,
                    add_user_widget=add_user_widget,
                    default_tracks=def_tracks,
                    au_error=False,
                    seq_id=sequence_id)
Пример #14
0
    def index(self, *args, **kw):

        seq_form = form.NewSequenceForm(action=url('/sequences')).req()
        species = genrep.get_species()

        m = {}
        sp_to_add = []
        for sp in species:
            assemblies = genrep.get_assemblies_not_created_from_species_id(
                sp.id)
            if len(assemblies) > 0:
                m[sp.id] = [(ass.id, ass.name) for ass in assemblies]
                sp_to_add.append(sp)
        sp_opts = [(sp.id, sp.species) for sp in sp_to_add]
        seq_form.child.children[1].options = sp_opts
        value = {'smapping': json.dumps(m)}
        seq_form.value = value
        grid = datagrid.sequences_grid

        if request.method == 'GET':
            sequences = DBSession.query(Sequence).all()
            seq_grid = [
                util.to_datagrid(grid, sequences, "Sequences",
                                 len(sequences) > 0)
            ]

            return dict(page="sequences", widget=seq_form, grid=seq_grid)
        else:
            species_id = kw['species']
            assembly_id = kw['assembly']
            # look if the species already exist in GDV, else create it
            species = DBSession.query(Species).filter(
                Species.id == species_id).first()
            if not species:
                species = handler.genrep.get_species_by_id(species_id)
                current_sp = Species()
                current_sp.id = species.id
                current_sp.name = species.species
                DBSession.add(current_sp)
                DBSession.flush()
                current_sp = DBSession.query(Species).filter(
                    Species.id == species_id).first()
                flash('''Species created: %s''' % (current_sp))

            # look if the assembly not already created, else create it
            if not DBSession.query(Sequence).filter(
                    Sequence.id == assembly_id).first():
                assembly = handler.genrep.get_assembly_by_id(assembly_id)
                seq = Sequence()
                seq.id = assembly_id
                seq.name = assembly.name
                seq.species_id = species_id
                DBSession.add(seq)
                DBSession.flush()
                seq = DBSession.query(Sequence).filter(
                    Sequence.id == assembly_id).first()
                handler.sequence.add_new_sequence(seq)
                flash('''Sequence created: %s''' % (seq))
            DBSession.flush()
            sequences = DBSession.query(Sequence).all()
            seq_grid = [
                util.to_datagrid(grid, sequences, "Sequences",
                                 len(sequences) > 0)
            ]
            return dict(page="sequences", widget=seq_form, grid=seq_grid)
Пример #15
0
    def index(self, *args, **kw):
        user = handler.user.get_user_in_session(request)
        shared_by = None
        # view on a specific project
        if 'pid' in kw and kw.get('pid'):
            project_id = kw.get('pid')
            project = DBSession.query(Project).filter(Project.id == project_id).first()
            if project is None:
                flash("Project doesn't exists", "error")
                raise redirect('/tracks')
            if not checker.check_permission(user=user, project=project, right_id=constants.right_read_id):
                flash('You must have %s permission to view the project.' % constants.right_read, 'error')
                raise redirect('/tracks')
            tracks = project.tracks
            # view on user project
            if checker.own(user=user, project=project):
                kw['own'] = True
                kw['upload'] = True
                grid = datagrid.track_grid_user(user, project)

            # view from a shared user
            else:
                rights = handler.project.get_rights(project=project, user=user)
                debug('find %s' % rights, 2)
                if constants.right_upload_id in [r.id for r in rights]:
                    kw['upload'] = True
                debug('view from a shared user %s' % rights)
                grid = datagrid.track_grid_permissions(user=user, rights=rights, project=project)
                shared_by = "%s %s" % (project.user.firstname, project.user.name[0].upper())

            kw['pn'] = project.name
            track_list = [util.to_datagrid(grid, tracks, "Track Listing", len(tracks) > 0)]
            shared_with = project.get_circle_with_right_display

        # view all user tracks
        else:
            if 'pid' in kw:
                del kw['pid']
            shared_with = ''
            tracks = list(user.tracks)
            # shared tracks
            shared_tracks = handler.user.shared_tracks(user.id, constants.rights['download']['id'])
            tracks.extend(shared_tracks)
            debug('shared tracks : %s' % ', '.join((str(x) for x in shared_tracks)))

            track_list = [util.to_datagrid(datagrid.track_grid_user(user), tracks, "Track Listing", len(tracks) > 0)]
            kw['upload'] = True

        t = handler.help.help_address(url('/help'), 'main', 'track list help')

        # project list
        project_list = [(p.id, p.name,) for p in user.projects]

        # shared projects
        shared_with_rights = handler.project.get_shared_projects(user)
        sorted_projects = sorted(shared_with_rights.iteritems(), key=lambda k: k[0].name)
        shared_project_list = [(p.id, p.name, ''.join([r[0] for r in rights])) for p, rights in sorted_projects]
        return dict(page='tracks', model='track', form_title="new track", track_list=track_list,
            project_list=project_list, shared_project_list=shared_project_list, value=kw,
            tooltip=t, project_id=kw.get('pid', None), upload=kw.get('upload', None), project_name=kw.get('pn', None),
            shared_with=shared_with, owner=kw.get('own', False), shared=not kw.get('own', False), shared_by=shared_by)
Пример #16
0
 def admin(self):
     c = DBSession.query(Circle).all()
     dc = [util.to_datagrid(circle_grid, c, "All circles", len(c) > 0)]
     t = handler.help.tooltip['circle']
     return dict(page='circles', model='circle', tooltip=t, items=dc, value={})