Пример #1
0
def index():
    user_id = get_user_id()
    if not user_id:
        return render_template("login.html", login_message="")

    g.menuf = 'index'
    g.menusub = 'index'
    return render_template("index.html")
Пример #2
0
        def before_request():
            if get_user_id():
                return
            # api: rest apis
            # manage: login apis
            if request.blueprint in ['api', 'manage', None]:
                return
            # special api for blueprints
            if request.endpoint.endswith('ForApi') or \
                    request.endpoint.endswith('for_api'):
                return

            return redirect(url_for('manage.index'))
Пример #3
0
def upload_image():
    image = request.files.get('avatar')
    g.menuf = 'setter'
    g.menusub = 'user'
    try:
        form = request.form
        res = SetterService().upload_info(image, form)
    except Exception as e:
        LOG.error("setter>upload_info is error: %s" % e)
        res = Status(101,
                     'failure',
                     u'Server发生错误,获取失败',
                     {}).json()
    LOG.info('%s update information' % get_user_id())
    return res
Пример #4
0
    def upload_info(self, image_file, form):
        for k, v in self.request_list.iteritems():
            if not k or not v:
                continue

            if not form.get(k):
                return Status(202, 'failure', u'请完善%s信息在进行提交' % v, {}).json()
        db_image = ''
        if image_file:
            image_name = image_file.filename
            if not self.__allow_format_img(image_name):
                return Status(202, 'failure', u'图片格式支持:jpg、png、bmp、jpeg',
                              {}).json()

            _base_dir = get_base_dir()
            now_date = get_now(format="%Y-%m-%d")

            def __get_filename_by_md5(file_name):
                suffix = (os.path.splitext(file_name)[1]).lower()
                _v = get_now() + file_name
                return (md5(_v) + suffix)

            store_file_name = __get_filename_by_md5(image_name)
            db_image = os.path.join((UPLOAD_BASE_DIR + now_date),
                                    store_file_name)
            store_dir = _base_dir + UPLOAD_BASE_DIR + now_date
            if not os.path.exists(store_dir):
                mk_dirs(store_dir)
            image_file.save(os.path.join(store_dir, store_file_name))

        try:
            user_mode = self.sysuser_bo.get_user_by_params(get_user_id())
            if db_image:
                user_mode.image = db_image
            ret_image = db_image if db_image else user_mode.image
            user_mode.fullname = form.get('fullname')
            user_mode.phone = form.get('phone')
            if form.get('email'):
                user_mode.email = form.get('email')
            self.sysuser_bo.merge_model(user_mode)
        except Exception as e:
            LOG.error("upload info is error: %s" % e)
            return Status(300, 'failure', u'upload info更新db失败', {}).json()

        return Status(100, 'success', u'信息完善成功!', {'image': ret_image}).json()
Пример #5
0
    def quit_empl(self, card_id):
        if not card_id:
            return Status(202, 'failure', u'quit_empl API无card_id参数',
                          {}).json()
        if isinstance(card_id, unicode):
            card_id = card_id.encode('utf-8')

        empl_mode = self.employee_bo.get_empl_by_card_id(card_id)
        if not empl_mode:
            return Status(203, 'failure', u'quit_empl删除不存在用户:%s' % card_id, {
                'data_id': card_id
            }).json()

        empl_mode.status = '2'
        empl_mode.quit_submit_time = get_now()
        empl_mode.quit_submit_rtx = get_user_id()
        self.employee_bo.merge_model(empl_mode)
        return Status(100, 'failure', u'%s操作离职成功' % empl_mode.china_name, {
            'data_id': card_id
        }).json()
Пример #6
0
    def add_or_edit_empl(self, args):
        """
        add employee
        :param args: form parameters
        :return: 
        """
        new_args = dict()
        for k, v in args.items():
            if isinstance(k, unicode):
                k = k.encode('utf-8')
            if v and isinstance(v, unicode):
                v = v.encode('utf-8')
            if k not in self.request_add_attrs:
                return Status(202, 'failure', u'%s参数不合法' % k, {}).json()

            if k in self.request_not_need_attrs:
                new_args[k] = str(v)
                continue

            if k and not v:
                attr_name = self.employee_attrs_dict.get(k)
                return Status(203, 'failure', u'%s内容需要进行填写' % attr_name,
                              {}).json()

            new_args[k] = v

        card_id = args.get('card_id')
        is_add = new_args['is_add']
        china_name = args.get('china_name')
        if isinstance(card_id, unicode):
            card_id = card_id.encode('utf-8')
        exist_empl_mode = self.employee_bo.get_empl_by_card_id(card_id)

        if is_add in ['1', 1] and exist_empl_mode:
            return Status(204, 'failure', u'%s用户已存在,无需重新建立信息档案' % china_name,
                          {}).json()

        empl_mode = self.employee_bo.new_mode() if is_add == '1' \
            else exist_empl_mode

        # submit
        for attr in self.request_add_attrs:
            if not attr:
                continue

            if attr == 'china_name':
                empl_mode.china_name = new_args.get(attr)
            elif attr == 'english_name':
                empl_mode.english_name = new_args[attr]
            elif attr == 'email':
                empl_mode.email = new_args[attr]
            elif attr == 'phone':
                empl_mode.phone = new_args[attr]
            elif attr == 'entry_date':
                empl_mode.entry_date = new_args[attr]
            elif attr == 'sex':
                empl_mode.sex = new_args[attr]
            elif attr == 'nation':
                empl_mode.nation = new_args[attr]
            elif attr == 'birth_date':
                empl_mode.birth_date = new_args[attr]
            elif attr == 'political_status':
                empl_mode.political_status = new_args[attr]
            elif attr == 'nationality':
                empl_mode.nationality = new_args[attr]
            elif attr == 'residence_type':
                empl_mode.residence_type = new_args[attr]
            elif attr == 'education':
                empl_mode.education = new_args[attr]
            elif attr == 'marriage':
                empl_mode.marriage = new_args[attr]
            elif attr == 'card_type':
                empl_mode.card_type = new_args[attr]
            elif attr == 'card_id':
                empl_mode.card_id = new_args[attr]
            elif attr == 'card_deadline':
                empl_mode.card_deadline = new_args[attr]
            elif attr == 'card_place':
                empl_mode.card_place = new_args[attr]
            elif attr == 'current_address':
                empl_mode.current_address = new_args[attr]
            elif attr == 'bank_type':
                empl_mode.bank_type = new_args[attr]
            elif attr == 'bank_country':
                empl_mode.bank_country = new_args[attr]
            elif attr == 'bank_city':
                empl_mode.bank_city = new_args[attr]
            elif attr == 'bank_id':
                empl_mode.bank_id = new_args[attr]
            elif attr == 'bank_name':
                empl_mode.bank_name = new_args[attr]
            elif attr == 'status':
                empl_mode.status = new_args[attr] if new_args[attr] else '1'

        # record
        if is_add in [1, '1']:
            empl_mode.entry_submit_rtx = get_user_id()
            empl_mode.entry_submit_time = get_now()
        else:
            empl_mode.last_update_rtx = get_user_id()
            empl_mode.last_update_time = get_now()

        self.employee_bo.add_model(empl_mode) if is_add == '1' \
            else self.employee_bo.merge_model(empl_mode)

        if is_add == '1':
            LOG.info("%s add employee is success" % card_id)
            return Status(100, 'success', u'新增%s成功' % china_name, {}).json()

        LOG.info("%s edit employee is success" % card_id)
        return Status(110, 'success', u'%s信息编辑成功' % china_name, {}).json()
Пример #7
0
def login_out():
    user_id = get_user_id()
    if user_id:
        LOG.info('%s login out ==========' % user_id)
    session.clear()
    return redirect(url_for('manage.index'))