req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req)
result = json.loads(response.read())
- print result
+ print result.encode('utf-8')
with open("./results.json",'r') as load_f:
load_dict = (json.load(load_f, encoding="UTF-8"))
test_desc = models.TextField(verbose_name="test desc", help_text="test desc")
# test_branch_id = models.ForeignKey(TestBranch, verbose_name="test category", help_text="test category")
meta_time = models.DateTimeField(default=timezone.now, verbose_name="meta time")
- hash = models.CharField(unique=True, default='', max_length=32, verbose_name="record hash", help_text="record hash")
+ hash = models.CharField(unique=True, default='', max_length=128, verbose_name="record hash", help_text="record hash")
+ uuid = models.CharField(unique=True, default='', max_length=64, verbose_name="record uuid", help_text="record uuid")
add_time = models.DateTimeField(default=timezone.now, verbose_name="test added time")
class Meta:
# client_max_num = serializers.SerializerMethodField()
class Meta:
model = TestRecord
- fields = ('hash', 'add_time', 'machine_info', 'pg_info', 'trend', 'linux_info', 'meta_info')
+ fields = ('uuid', 'add_time', 'machine_info', 'pg_info', 'trend', 'linux_info', 'meta_info')
def get_trend(self, obj):
dataset_list = TestDataSet.objects.filter(test_record_id=obj.id).values_list('status').annotate(Count('id'))
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import shortuuid
+
+from django.contrib.auth.hashers import make_password
from django.shortcuts import render
from rest_framework.pagination import PageNumberPagination
# jsLoads = json.loads(data[0])
# todo get machine by token
- # todo hash the json_data to ensure unique
+ test_machine = 1
+
from django.db import transaction
try:
+
+ record_hash = make_password(str(json_data), 'pg_perf_farm')
+ print(record_hash.__len__())
+ r = TestRecord.objects.filter(hash=record_hash).count()
+ if r != 0:
+ raise TestDataUploadError("The same record already exists, please do not submit it twice.")
+
with transaction.atomic():
linux_data = json_data['linux']
'pg_info': pgInfoRet.id,
'linux_info': linuxInfoRet.id,
'meta_info': metaInfoRet.id,
- 'test_machine': 1,
+ 'test_machine': test_machine,
'test_desc': 'here is desc',
- 'meta_time': metaInfoRet.date
+ 'meta_time': metaInfoRet.date,
+ 'hash': record_hash,
+ 'uuid': shortuuid.uuid()
}
testRecord = CreateTestRecordSerializer(data=test_record_data)
testRecordRet = None