Пример #1
0
    def put(self, *args, **kwargs):
        print u'scientist put'

        if not self.current_user_id:
            self.send_error(status_code=403)
            return

        scientist_dict = json.loads(self.get_argument(u'data', u'{}'))
        print 'FROM CLIENT:', scientist_dict
        scientist_dict.update(
            scientist_id=self.current_user_id
        )
        scientist_photo = {}

        files = self.request.files.get('raw_image', [])

        if files:
            scientist_photo = dict(
                raw_image=files,
                raw_image_coords=scientist_dict.pop(u'raw_image_coords', {})
            )
        try:
            response = yield ScientistBL.update(scientist_dict=scientist_dict, scientist_photo=scientist_photo)
        except Exception, ex:
            logging.info('Exc on update scientist: {}'.format(self.current_user_id))
            logging.exception(ex)
            response = dict(
                message=ex.message
            )
Пример #2
0
    def get(self, *args, **kwargs):
        scientist_id = None
        try:
            if not any(args):
                print u'scientists list get'
                response = yield ScientistBL.get_all()
            else:
                scientist_id = args[0].replace(u'/', u'')
                print u'get scientist:', scientist_id
                response = yield ScientistBL.get(scientist_id)

        except Exception, ex:
            logging.info(SC_EXC(scientist=scientist_id))
            logging.exception(ex)
            response = dict(
                message=ex.message
            )
Пример #3
0
 def post(self, *args, **kwargs):
     from scientist.scientist_bl import ScientistBL
     data = json.loads(self.get_argument(u'data', u'{}'))
     email = data.get(u'email', u'')
     pwd = data.get(u'pwd', u'')
     scientist_id = yield ScientistBL.check_login(email, pwd)
     if not scientist_id:
         self.send_error(status_code=403)
         return
     self.set_secure_cookie(u'scientist', str(scientist_id))
     self.redirect(self.get_argument(u'next', u'/'))
Пример #4
0
    def delete(self, scientist_id):
        print u'scientist delete: ', scientist_id

        try:
            yield ScientistBL.delete(scientist_id.replace(u'/', u''))
            self.clear_cookie(u'scientist')
            return
        except Exception, ex:
            logging.info('Exc on delete scientist: {}'.format(scientist_id))
            logging.exception(ex)
            response = dict(
                message=ex.message
            )
Пример #5
0
    def get(self, *args, **kwargs):
        print u'favorite desired projects get'

        if not self.current_user_id:
            self.send_error(status_code=403)
            return

        try:
            response = yield ScientistBL.get_desired_projects(self.current_user_id)
        except Exception, ex:
            logging.info('Exc on get my projects: {}'.format(self.current_user_id))
            logging.exception(ex)
            response = dict(
                message=ex.message
            )
Пример #6
0
def fill_init_data():
    from tests.scientist_data import Scientist
    from scientist.scientist_bl import ScientistBL

    from tests.project_data import Project
    from project.project_bl import ProjectBL

    scientist_data = Scientist.get_scientist()
    print 'Creating init scientists'
    try:
        for k, val in scientist_data.iteritems():
            yield ScientistBL.create(scientist_dict=val, test_mode=True)
    except Exception, ex:
        logging.exception(ex)
        raise
Пример #7
0
    def post(self, *args, **kwargs):
        print u'scientist post'

        scientist_dict = json.loads(self.get_argument(u'data', u'{}'))
        print scientist_dict
        scientist_photo = dict(
            raw_image=self.request.files.get('raw_image', []),
            raw_image_coords=scientist_dict.pop(u'raw_image_coords', {})
        )

        try:
            response = yield ScientistBL.create(scientist_dict=scientist_dict, scientist_photo=scientist_photo)
            self.set_secure_cookie(u'scientist', str(response[u'scientist_id']))
        except Exception, ex:
            logging.info('Exc on create scientist:')
            logging.exception(ex)
            response = dict(
                message=ex.message
            )