Beispiel #1
0
def register_staff(request):
    context = {
        'page': 'register_staff',
    }
    if request.session.get('is_login', None):
        username = request.session.get('username')
        store = request.session.get('storeid')
        context['username'] = username
        if request.session.get('identity') != 'shopkeeper':
            context['errmsg'] = '请以店主账号登录'
            shopkeeper = False
            return render(request,
                          'staff/register_staff.html',
                          context=context)
        else:
            shopkeeper = True
    else:
        return login(request)

    if request.method == "POST" and shopkeeper:
        username = request.POST.get('username')
        name = request.POST.get('name')
        password = request.POST.get('password')
        phonenumber = request.POST.get("phonenumber")
        desc = request.POST.get("desc")
        user_model = Staff.objects.filter(username=username).filter(
            store_id=store)

        # 参数验证
        if not all([username, name, password, phonenumber, desc]):
            # 参数不完整
            context['errmsg'] = '数据不完整'
            return render(request,
                          'staff/register_staff.html',
                          context=context)

        if user_model:  #不为NULL
            context['errmsg'] = '用户名已存在'
            return render(request,
                          'staff/register_staff.html',
                          context=context)
        else:
            user = Staff()
            user.username = username
            user.name = name
            user.password = password
            user.phonenumber = phonenumber
            user.desc = desc
            user.store_id = store
            user.save()
            return redirect(reverse('staff:find_staff'))
    return render(request, 'staff/register_staff.html', context=context)
Beispiel #2
0
def new_staff(req):
	from staff.models import Staff

	if req.method == 'POST':
		posted = req.POST

		staff = Staff()

		staff.groupschedule = req.user.groupschedule
		staff.name = posted['name']

		staff.save()

		return redirect('/')

	temp = 'staff/new_staff.html'
	contxt = {}

	return render(req,temp,contxt)
Beispiel #3
0
 def test_name(self):
     staff = Staff(firstname='l', secondname='b')
     self.assertEqual(staff.firstname, 'l')
     self.assertEqual(staff.secondname, 'b')
     self.assertEqual(staff.name(), 'l b')
     self.assertEqual(str(staff), 'l b')