コード例 #1
0
    def post(self):
        # create barcodes
        msg = ""
        newbc = []
        assignedbc = []
        projects = []
        action = self.get_argument("action")
        num_barcodes = int(self.get_argument('numbarcodes'))

        if action == "create":
            newbc = db.create_barcodes(num_barcodes)
            msg = ("%d Barcodes created! Please wait for barcode download" %
                   num_barcodes)

        elif action == "assign":
            projects = [
                url_unescape(p).encode('utf-8')
                for p in self.get_arguments('projects')
            ]
            new_project = self.get_argument('newproject').strip()
            try:
                if new_project:
                    db.create_project(new_project)
                    projects.append(new_project)
                assignedbc = db.assign_barcodes(num_barcodes, projects)
            except ValueError as e:
                msg = u"ERROR! %s" % e.message
            else:
                projects = [p.decode('utf-8') for p in projects]
                tmp = u"%d barcodes assigned to %s, please wait for download."
                msg = tmp % (num_barcodes, ", ".join(projects))

        else:
            raise HTTPError(400, 'Unknown action: %s' % action)

        project_names = db.getProjectNames()
        remaining = len(db.get_unassigned_barcodes())
        self.render("ag_new_barcode.html",
                    currentuser=self.current_user,
                    projects=project_names,
                    remaining=remaining,
                    msg=msg,
                    newbc=newbc,
                    assignedbc=assignedbc,
                    assign_projects=", ".join(projects))
コード例 #2
0
ファイル: ag_new_barcode.py プロジェクト: josenavas/labadmin
    def post(self):
        # create barcodes
        msg = ""
        newbc = []
        assignedbc = []
        projects = []
        action = self.get_argument("action")
        num_barcodes = int(self.get_argument('numbarcodes'))

        if action == "create":
            newbc = db.create_barcodes(num_barcodes)
            msg = ("%d Barcodes created! Please wait for barcode download"
                   % num_barcodes)

        elif action == "assign":
            projects = [url_unescape(p).encode('utf-8')
                        for p in self.get_arguments('projects')]
            new_project = self.get_argument('newproject').strip()
            try:
                if new_project:
                    db.create_project(new_project)
                    projects.append(new_project)
                assignedbc = db.assign_barcodes(num_barcodes, projects)
            except ValueError as e:
                msg = u"ERROR! %s" % e.message
            else:
                projects = [p.decode('utf-8') for p in projects]
                tmp = u"%d barcodes assigned to %s, please wait for download."
                msg = tmp % (num_barcodes, ", ".join(projects))

        else:
            raise HTTPError(400, 'Unknown action: %s' % action)

        project_names = db.getProjectNames()
        remaining = len(db.get_unassigned_barcodes())
        self.render("ag_new_barcode.html", currentuser=self.current_user,
                    projects=project_names, remaining=remaining,
                    msg=msg, newbc=newbc, assignedbc=assignedbc,
                    assign_projects=", ".join(projects))
コード例 #3
0
    def test_post_update_ag_project_change(self):
        db.alter_access_levels('test', [3])
        self.data['project'] = 'UNKNOWN_%s' % os.getpid()
        self.mock_login()
        # ensure project is in the DB
        db.create_project(self.data['project'])

        response = self.post('/barcode_util/', data=self.data)
        self.assertEqual(response.code, 200)
        self.assertIn('Barcode %s general details updated' % self.ag_good,
                      response.body)
        self.assertIn('Project successfully changed', response.body)
        barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good)
        self.assertEqual(barcode_projects, self.data['project'])
        self.assertEqual(parent_project, 'American Gut')

        # reset back
        db.setBarcodeProjects(self.ag_good,
                              rem_projects=[self.data['project']])
        barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good)
        self.assertEqual(barcode_projects, '')
        self.assertEqual(parent_project, 'American Gut')
        db.ut_remove_project(self.data['project'])
コード例 #4
0
    def test_post_update_ag_project_change(self):
        db.alter_access_levels('test', [3])
        self.data['project'] = 'UNKNOWN_%s' % os.getpid()
        self.mock_login()
        # ensure project is in the DB
        db.create_project(self.data['project'])

        response = self.post('/barcode_util/', data=self.data)
        self.assertEqual(response.code, 200)
        self.assertIn('Barcode %s general details updated' % self.ag_good,
                      response.body)
        self.assertIn('Project successfully changed', response.body)
        barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good)
        self.assertEqual(barcode_projects, self.data['project'])
        self.assertEqual(parent_project, 'American Gut')

        # reset back
        db.setBarcodeProjects(self.ag_good,
                              rem_projects=[self.data['project']])
        barcode_projects, parent_project = db.getBarcodeProjType(self.ag_good)
        self.assertEqual(barcode_projects, '')
        self.assertEqual(parent_project, 'American Gut')
        db.ut_remove_project(self.data['project'])
コード例 #5
0
ファイル: test_data_access.py プロジェクト: mortonjt/labadmin
    def test_create_project(self):
        with self.assertRaises(ValueError):
            db.create_project("American Gut Project")
        with self.assertRaises(ValueError):
            db.create_project("    ")

        db.create_project("New Test Project")
        obs = db._con.execute_fetchall("SELECT * from project")
        exp = [[1, "American Gut Project"], [2, "New Test Project"]]
        self.assertEqual(obs, exp)
コード例 #6
0
ファイル: test_data_access.py プロジェクト: mortonjt/labadmin
    def test_create_project(self):
        with self.assertRaises(ValueError):
            db.create_project("American Gut Project")
        with self.assertRaises(ValueError):
            db.create_project("    ")

        db.create_project("New Test Project")
        obs = db._con.execute_fetchall("SELECT * from project")
        exp = [[1, "American Gut Project"], [2, "New Test Project"]]
        self.assertEqual(obs, exp)