Example #1
0
def set_default_url(request):
    url = request.GET.get('url')
    account = request.user.account
    if url:
        account.default_url = url
        account.save()
        return json_response({'code': 0, 'msg': '成功'})
    else:
        return json_response({'code': 1, 'msg': '参数缺失'})
Example #2
0
def change_password(request):
    if request.method == 'POST':
        msg = u'修改密码成功'
        code = 0
        cds = request.POST
        print cds
        u = request.user
        old_pwd = cds.get('old_pwd', '')
        if u.check_password(old_pwd):
            pwd = cds.get('new_pwd', '')
            if len(pwd) < 6 or len(pwd) > 20:
                msg = u'密码长度应该为6到20位之间'
                code = 1
            if pwd == old_pwd:
                msg = u'新旧密码不能相同'
                code = 1

            pwd_rep = cds.get('new_pwd_rep', '')
            if pwd != pwd_rep:
                msg = u'两次输入的密码不相同'
                code = 1
        else:
            code = 1
            msg = u'原密码错误'
        if not code:
            u.set_password(pwd)
            u.save()
        return json_response({'code': code, 'msg': msg})
    else:
        return render_to_response('registration/change_password.html',
                                  context_instance=RequestContext(request))
Example #3
0
def account_setting(request):
    if request.method == 'POST':
        cds = json.loads(request.body)
        p = request.user.account.personinfo
        if p:
            f = AccountSettingForm(cds, instance=p)
        else:
            f = AccountSettingForm(cds)
        if not f.is_valid():
            return json_response({'code': 1, "msg": ErrorDic2str(f.errors)})
        p = f.save()
        request.user.account.personinfo = p
        request.user.account.save()
        return json_response({"code": 0, "msg": "成功修改个人信息"})
    else:
        person = request.user.account.personinfo
        POSITIONS = Person.POSITIONS
        return render_to_response('registration/account_settings.html', {
            'person': person,
            'POSITIONS': POSITIONS
        },
                                  context_instance=RequestContext(request))
Example #4
0
def staff_point_stat(request):
    cds = request.GET
    unit = cds.get('timeLevel', 'day')
    begin_time = cds.get('begin_time')
    department_id = cds.get('department', '')
    if department_id:
        department = Department.objects.get(id=department_id)
    else:
        department = request.user.account.staff.department
    if begin_time:
        begin_time = datetime.date.fromtimestamp(int(begin_time))
    end_time = cds.get('end_time')
    if end_time:
        end_time = datetime.date.fromtimestamp(int(end_time))
    x_data, y_data, y_data_branchs, y_titles = split_staff_point_by_time(
        unit=unit,
        begin_time=begin_time,
        end_time=end_time,
        department=department)
    option = staff_point_option(xdata=x_data,
                                ydata=y_data,
                                ydata_branchs=y_data_branchs,
                                ytitles=y_titles)
    return json_response(option)
Example #5
0
def department_add(request, pid=None):
    account = request.user.account
    context = {}
    if pid:
        title = u'添加部门信息'
        parent = Department.objects.get(id=pid)
        if request.POST:
            form1 = CreateDepartmentForm(request.POST)
            form1.fields['positions'].queryset = parent.positions.all()
            form2 = CreateDepartmentSetForm(request.POST)
            if form1.is_valid() and form2.is_valid():
                department = form1.save(commit=False)
                department.level = 2
                department.parent = parent
                departmentset = form2.save(commit=False)
                if departmentset.increase_min < parent.departmentset.increase_min:
                    return json_response({
                        'code': 1,
                        'msg': '部门最小贡献增幅不得小于上级部门规定最小增幅'
                    })
                if departmentset.increase_max > parent.departmentset.increase_max:
                    return json_response({
                        'code': 1,
                        'msg': '部门最大贡献增幅不得高于上级部门规定最大增幅'
                    })
                department.save()
                departmentset.department = department
                departmentset.save()
                return HttpResponseRedirect('/department_manage/%s' %
                                            department.parent.id)
        else:
            form1 = CreateDepartmentForm()
            form1.fields['positions'].queryset = parent.positions.all()
            form2 = CreateDepartmentSetForm(instance=parent.departmentset)
        context = {
            'title': title,
            'form1': form1,
            'form2': form2,
            'parent': parent,
        }
    else:
        title = u'添加公司信息'
        if account.staff.department:
            return HttpResponse(u'您已经有公司信息,不能再次添加')
        if request.POST:
            form1 = CreateDepartmentForm(request.POST)
            form1.fields.pop('positions')
            form2 = CreateDepartmentSetForm(request.POST)
            form3 = CreateBaseSetForm(request.POST)
            if form1.is_valid() and form2.is_valid() and form3.is_valid():
                department = form1.save(commit=False)
                department.level = 1
                department.save()
                department.positions.add(Position.objects.get(id=1))
                account.staff.department = department
                account.staff.save()
                departmentset = form2.save(commit=False)
                departmentset.department = department
                departmentset.save()
                department.positions.add(Position.objects.get(id=1))
                baseset = form3.save(commit=False)
                baseset.company = department
                baseset.save()
                account.default_url = '/staff_detail/%s' % account.staff.id
                account.save()
                return HttpResponseRedirect('/department_manage/%s' %
                                            department.id)
        else:
            form1 = CreateDepartmentForm()
            form1.fields.pop('positions')
            form2 = CreateDepartmentSetForm()
            form3 = CreateBaseSetForm()
        context = {
            'title': title,
            'form1': form1,
            'form2': form2,
            'form3': form3,
        }
    return render_to_response('department/department_add.html',
                              context,
                              context_instance=RequestContext(request))
Example #6
0
def turn_default_url(request):
    account = request.user.account
    if account.default_url:
        return HttpResponseRedirect(account.default_url)
    else:
        return json_response({'code': 1, 'msg': '默认页不存在'})
Example #7
0
def staff_add(request, did=None):
    account = request.user.account
    title = u'添加员工信息'
    department = None
    if did:
        department = Department.objects.get(id=did)
        if request.POST:
            form1 = CreateStaffForm(request.POST, request.FILES)
            form1.fields['position'].queryset = department.positions.all()
            form2 = CreateStaffSetForm(request.POST)
            if form1.is_valid() and form2.is_valid():
                staff = form1.save(commit=False)
                staffset = form2.save(commit=False)
                if staffset.increase < department.departmentset.increase_min:
                    return json_response({
                        'code': 1,
                        'msg': '个人贡献增幅不得低于部门设定中的最小增幅'
                    })
                if staffset.increase > department.departmentset.increase_max:
                    return json_response({
                        'code': 1,
                        'msg': '个人贡献增幅不得高于部门设定中的最大增幅'
                    })
                staff.department = department
                user = User.objects.create_user(username=staff.phone,
                                                password='******',
                                                first_name=staff.name)
                account = Account(accountinfo=user, default_url='')
                account.save()
                if staff.position.role:
                    staff_role = staff.position.role
                    account.roles.add(staff_role)
                staff.account = account
                staff.save()
                staffset.staff = staff
                staffset.save()
                return HttpResponseRedirect('/staff_manage/%s' % did)
        else:
            form1 = CreateStaffForm()
            form1.fields['position'].queryset = department.positions.all()
            form2 = CreateStaffSetForm(
                {'increase': department.departmentset.increase})
    else:
        title = u'添加创始人信息'
        if request.POST:
            form1 = CreateStaffForm(request.POST, request.FILES)
            form1.fields.pop('position')
            form2 = CreateStaffSetForm(request.POST)
            if form1.is_valid() and form2.is_valid():
                staff = form1.save(commit=False)
                staff.position = Position.objects.get(id=1)
                user = User.objects.create_user(username=staff.phone,
                                                password='******',
                                                first_name=staff.name)
                account = Account(accountinfo=user, default_url='')
                account.save()
                if staff.position.role:
                    staff_role = staff.position.role
                    account.roles.add(staff_role)
                staff.account = account
                staff.save()
                staffset = form2.save(commit=False)
                staffset.staff = staff
                staffset.save()
                return HttpResponseRedirect('/staff_detail/%s' % staff.id)
        else:
            form1 = CreateStaffForm()
            form1.fields.pop('position')
            form2 = CreateStaffSetForm()
    context = {
        'title': title,
        'form1': form1,
        'form2': form2,
        'department': department,
    }
    return render_to_response('staff/staff_add.html',
                              context,
                              context_instance=RequestContext(request))