コード例 #1
0
ファイル: sample.py プロジェクト: bbcf/biorepo
    def edit(self, *args, **kw):

        user = handler.user.get_user_in_session(request)
        sample = DBSession.query(Samples).filter(Samples.id == args[0]).first()
        admin = isAdmin(user)
        user_lab = session.get("current_lab", None)
        if user_lab:
            lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()

        if admin:
            projects = DBSession.query(Projects).all()
            measurements = DBSession.query(Measurements).all()
        else:
            projects = DBSession.query(Projects).filter(Projects.user_id == user.id).all()
            for p in projects:
                if p not in lab.projects:
                    projects.remove(p)
            attributs = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab.id, Attributs.deprecated == False)).all()
            measurements = []
            for a in attributs:
                for m in a.measurements:
                    if m not in measurements and m.user_id == user.id:
                        measurements.append(m)

        if sample.get_userid == user.id or admin:

            edit_form = build_form("edit", "sample", sample.id)(action=url('/samples/post_edit'))
            edit_form.child.children[0].value = sample.id
            projects_list = [(p.id, '%s' % p.project_name) for p in projects]
            edit_form.child.children[1].options = projects_list
            id_project = DBSession.query(Projects.id).filter(Projects.id == sample.project_id).first()
            #measurement(s) attached to the sample
            list_unselected = [m for m in measurements if m not in sample.measurements]
            meas_selected = [(meas.id, '%s' % (meas.name)) for meas in list_unselected] + [(meas.id, '%s' % (meas.name), {'selected': True}) for meas in sample.measurements]
            edit_form.child.children[1].value = id_project[0]
            edit_form.child.children[2].value = sample.name
            edit_form.child.children[3].options = get_list_types(user_lab)
            edit_form.child.children[3].value = sample.type
            edit_form.child.children[4].value = sample.protocole
            edit_form.child.children[5].options = meas_selected

            return dict(page='samples', widget=edit_form.req(), value=kw)
        else:
            flash("It is not your sample -> you are not allowed to edit this sample", 'error')
            raise redirect('/samples')
コード例 #2
0
ファイル: sample.py プロジェクト: bbcf/biorepo
    def new(self, *args, **kw):
        #take the logged user
        user = handler.user.get_user_in_session(request)
        user_lab = session.get("current_lab", None)
        if user_lab:
            lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()
        projects = DBSession.query(Projects).filter(Projects.user_id == user.id).all()
        for p in projects:
            if p not in lab.projects:
                projects.remove(p)

        new_form = build_form("new", "sample", None)(action=url('/samples/post')).req()
        #static fields
        new_form.child.children[0].options = [(project.id, '%s' % project.project_name) for project in projects]
        new_form.child.children[1].placeholder = "Your sample name..."
        new_form.child.children[2].options = get_list_types(user_lab)
        new_form.child.children[3].placeholder = "Your protocole here..."

        return dict(page='samples', widget=new_form)