Exemplo n.º 1
0
def test_sysinfo_manage():
    db_util = DBUtil()

    #create
    demo_system = SystemInfo(sys_name='oa333', db_type=DatabaseType.oracle, db_ip='127.0.0.1',
                         db_port='1521', db_name='db', db_table_name='accounts', db_column_username='******',
                         db_column_password='******', db_password_encrypt_algorithm=EncryptAlgorithmType.md5)
    db_util.add_system(demo_system)
    for i in db_util.get_all_system():
        print i

    #update
    demo_system.db_type = DatabaseType.mysql
    demo_system.db_port = '3306'

    #request
    idd = demo_system.id
    print '____________________%d' % idd
    s =  db_util.get_system_by_id(idd)
    print s
    print '__ __ __ __ __ __ __ ___ ___%d' % idd

    #delete
    db_util.del_system(s)
    s =  db_util.get_system_by_id(idd)
    print s
Exemplo n.º 2
0
def test_get_account_data_mysql():
    db_util = DBUtil()

    test_system = SystemInfo(sys_name='test_system', db_type=DatabaseType.mysql, db_ip='127.0.0.1',
                         db_port='3306', db_name='wpd', db_table_name='user_table', db_column_username='******',
                         db_column_password='******', db_password_encrypt_algorithm=EncryptAlgorithmType.md5)

    db_util.add_system(test_system)
    print '____________________%d' % test_system.id
    test_system.get_account_data(username='******', password='******')
Exemplo n.º 3
0
def test_get_account_data_oracle():
    db_util = DBUtil()

    test_system = SystemInfo(sys_name='test_system2', db_type=DatabaseType.oracle, db_ip='192.168.238.130',
                         db_port='1521', db_name='ora11g', db_table_name='PM_BID_PROJECT_INFO', db_column_username='******',
                         db_column_password='******', db_password_encrypt_algorithm=EncryptAlgorithmType.md5)

    db_util.add_system(test_system)
    print '____________________%d' % test_system.id
    test_system.get_account_data(username='******', password='******')
Exemplo n.º 4
0
def createSystemInfo(request):

    if request.method == 'POST':
        #databaseInfo_selects = DatabaseInfo.objects.values().filter(id=request.POST["database_name"])
        form = CreateSystemInfoForm(request.POST)
        # 验证数据的合法性
        if form.is_valid():
            # 如果提交数据合法,调用表单的 save 方法将数据保存到数据库
            SystemInfo(name=request.POST["name"],
                       account=request.POST["account"],
                       password=request.POST["password"],
                       address=request.POST["address"],
                       remark=request.POST["remark"],
                       create_user=request.session.get("username"),
                       modify_user=request.session.get("username")).save()
            database_name = DatabaseInfo.objects.get(
                name=request.POST["database_name"])
            SystemInfo.objects.get(
                name=request.POST["name"]).database_name.add(database_name)
            # 创建成功,跳转回首页
            return HttpResponseRedirect('/testadmin/systemInfo')
    else:
        form = CreateDatabaseInfoForm()
    databaseInfo_selects = DatabaseInfo.objects.values()
    return render(
        request, "testadmin/create_systeminfo.html", {
            'form': form,
            'databaseInfo_selects': databaseInfo_selects,
            'post': request.POST
        })
Exemplo n.º 5
0
def participant_key_filter( competition, key, auto_add_participant=True ):
	key = key.strip()
	
	system_info = SystemInfo.get_singleton()
	
	# Check if the code has an embedded license code.
	license_code = None
	if system_info.license_code_regex:
		for license_code_regex in system_info.license_code_regex.split('||'):
			license_code_regex = license_code_regex.strip()
			try:
				license_code = re.match(license_code_regex, key).group('license_code').lstrip('0')
				break
			except Exception as e:
				pass
	
	# Convert the key to upper.
	# The license_code, tag and tag2 are all stored in upper-case, so it is safe to do exact matches.
	key = key.upper().lstrip('0')
	
	if not key:
		return None, []
		
	if competition.using_tags:
		if competition.use_existing_tags:
			tag_query = Q(license_holder__existing_tag=key) | Q(license_holder__existing_tag2=key)
		else:
			tag_query = Q(tag=key) | Q(tag2=key)
	else:
		tag_query = None
	
	uci_id = is_uci_id( key )
	
	# Check for an existing participant.
	if license_code:
		participants = list( Participant.objects.filter( competition=competition, role=Participant.Competitor, license_holder__license_code=license_code ) )
	elif uci_id:
		participants = list( Participant.objects.filter( competition=competition, role=Participant.Competitor, license_holder__uci_id=uci_id ) )
	else:
		or_query = Q(license_holder__license_code=key)
		if tag_query: 		or_query |= tag_query
		participants = list( Participant.objects.filter( competition=competition, role=Participant.Competitor ).filter( or_query ) )
	
	if participants:
		participants.sort( key = lambda p: (p.category.sequence if p.category else 999999, p.bib or 999999) )
		return participants[0].license_holder, participants
	
	# Check for a license encoded in an rfid tag.
	tag_original = None
	if competition.using_tags and competition.use_existing_tags:
		if system_info.tag_creation == 2:
			license_from_tag = getLicenseFromTag( key, system_info.tag_from_license_id )
			if license_from_tag is not None:
				tag_original = key
				key = license_from_tag
	
	# Second, check for a license holder matching the key.
	if license_code:
		q = Q(license_code=license_code)
	elif uci_id:
		q = Q(uci_id=uci_id)
	elif competition.using_tags and competition.use_existing_tags:
		q = Q(license_code=key) | Q(existing_tag=key) | Q(existing_tag2=key)
	else:
		q = Q(license_code=key)
	
	try:
		license_holder = LicenseHolder.objects.get( q )
	except LicenseHolder.DoesNotExist as e:
		license_holder = None
	except LicenseHolder.MultipleObjectsReturned as e:
		license_holder = None
	
	if not license_holder:
		return None, []			# No license holder.
		
	if competition.using_tags and competition.use_existing_tags and tag_original and license_holder.existing_tag != tag_original:
		license_holder.existing_tag = tag_original
		license_holder.save()
	
	if not auto_add_participant:
		return license_holder, []
	
	return add_participant_from_license_holder( competition, license_holder )