예제 #1
0
 def test_create_volunteer(self):
     group = Group.objects.get(name="group1")
     create_volunteer("admin", "123456", "xiaoming", "1380000", cert_number="abc123", year=10, group_id=group.id)
     v = Volunteer.objects.get(openid='123456')
     self.assertEqual(v.creator.username, "admin")
     self.assertEqual(v.group.name, "group1")
     self.assertEqual(v.phone, "1380000")
     self.assertEqual(v.cert_number, "abc123")
     self.assertEqual(v.year, 10)
예제 #2
0
def register_volunteer(request):
    openid = request.POST['openid']
    qrcode_id = request.POST['qrcode_id']
    email = request.POST['email']
    name = request.POST['name']
    phone = request.POST['phone']
    cert_number = request.POST['cert-number']
    year = request.POST['year']
    result = Result()
    try:
        year = float(year)
    except:
        result.code = Consts.FAILED_CODE
        result.msg = Consts.INVALID_VOLUNTEER_YEAR_MSG
        return HttpResponse(json.dumps(result.to_dict()), content_type="application/json")


    if admin.check_volunteer_exist(openid):
        result.code = Consts.FAILED_CODE
        result.msg = Consts.VOLUNTEER_EXIST_MSG
        return HttpResponse(json.dumps(result.to_dict()), content_type="application/json")

    qr = Qrcode.objects.filter(id=qrcode_id).first()
    if not qr:
        return render(request, 'mobile_callback.html', {"type": "danger", "content": Consts.QR_NOT_FOUND_MSG})
    if qr.expire_time < datetime.datetime.now():
        return render(request, 'mobile_callback.html', {"type": "danger", "content": Consts.EXPIRED_QRCODE_MSG})

    user = qr.creator
    group_id = None
    if user and not user.is_superuser and len(get_all_groups(user.username)) > 0:
        group_id = get_all_groups(user.username).first().id

    try:
        admin.create_volunteer(user.username, openid, name, phone, email, cert_number, year, group_id)
        return render(request, 'mobile_callback.html', {"type": "success", "content": u"注册成功"})
    except:
        result.code = Consts.FAILED_CODE
    return render(request, 'mobile_callback.html', {"type": "danger", "content": Consts.UNKNOWN_ERROR})
예제 #3
0
 def test_remove_volunteer(self):
     group = Group.objects.get(name="group1")
     create_volunteer("admin", "123456", "xiaoming", "1380000", cert_number="abc123", year=10, group_id=group.id)
     self.assertTrue(check_volunteer_exist("123456"))
     remove_volunteer("123456")
     self.assertFalse(check_volunteer_exist("123456"))