Пример #1
0
    def load_projects(self):
        db = self.manager.db
        with db.session_ctx():
            ps = db.get_projects(order=gen_ProjectTable.name.asc())
            ms = db.get_mass_spectrometers()
            recents = [ProjectRecordView('Recent {}'.format(mi.name.capitalize())) for mi in ms]

            ad = recents + [ProjectRecordView(p) for p in ps]

            self.projects = ad
            self.oprojects = ad
Пример #2
0
    def _identifier_change_hook(self, db, new, lns):
        if len(new) > 2:
            if self.project_enabled:

                def get_projects():
                    for li in lns:
                        try:
                            yield li.sample.project
                        except AttributeError as e:
                            print('exception', e)

                ps = sorted(list(set(get_projects())))
                ps = [ProjectRecordView(p) for p in ps]
                self.projects = ps
                self.selected_projects = []

            if self.irradiation_enabled:

                def get_irradiations():
                    for li in lns:
                        try:
                            yield li.irradiation_position.level.irradiation.name
                        except AttributeError:
                            pass

                irrads = sorted(list(set(get_irradiations())))
                self.irradiations = irrads
                if irrads:
                    self.irradiation = irrads[0]
Пример #3
0
 def _make_project_records(self,
                           ps,
                           ms=None,
                           include_recent=True,
                           include_recent_first=True):
     if not ps:
         return []
     pss = sorted([ProjectRecordView(p) for p in ps], key=lambda x: x.name)
     return pss
Пример #4
0
    def _make_project_records(self,
                              ps,
                              ms=None,
                              include_recent=True,
                              include_recent_first=True):
        if not ps:
            return []

        db = self.db
        with db.session_ctx():
            if not ms:
                ms = db.get_mass_spectrometers()
                if ms:
                    ms = [mi.name for mi in ms]
                else:
                    ms = []

            recents = []
            if include_recent:
                recents = [
                    ProjectRecordView('RECENT {}'.format(mi.upper()))
                    for mi in ms
                ]

            pss = [ProjectRecordView(p) for p in ps]

            if include_recent:
                # move references project to after Recent
                p = next((p for p in pss if p.name.lower() == 'references'),
                         None)
                if p is not None:
                    rp = pss.pop(pss.index(p))
                    pss.insert(0, rp)
            else:
                pss = [p for p in pss if p.name.lower() != 'references']

            if include_recent_first:
                return recents + pss
            else:
                return pss + recents
Пример #5
0
 def _make_project(self, record):
     return ProjectRecordView(record)
Пример #6
0
 def activated(self):
     with self.dvc.session_ctx(use_parent_session=False):
         self.items = self.oitems = [
             ProjectRecordView(pr) for pr in self.dvc.get_projects()
         ]