本文整理汇总了Python中crashstats.crashstats.models.GraphicsDevices类的典型用法代码示例。如果您正苦于以下问题:Python GraphicsDevices类的具体用法?Python GraphicsDevices怎么用?Python GraphicsDevices使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphicsDevices类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: graphics_devices
def graphics_devices(request):
context = {}
form = forms.GraphicsDeviceForm()
upload_form = forms.GraphicsDeviceUploadForm()
if request.method == 'POST' and 'file' in request.FILES:
upload_form = forms.GraphicsDeviceUploadForm(
request.POST,
request.FILES
)
if upload_form.is_valid():
if upload_form.cleaned_data['database'] == 'pcidatabase.com':
function = utils.pcidatabase__parse_graphics_devices_iterable
else:
function = utils.pci_ids__parse_graphics_devices_iterable
payload = list(function(upload_form.cleaned_data['file']))
api = GraphicsDevices()
result = api.post(data=payload)
log(request.user, 'graphicsdevices.post', {
'success': result,
'database': upload_form.cleaned_data['database'],
'no_lines': len(payload),
})
messages.success(
request,
'Graphics device CSV upload successfully saved.'
)
return redirect('manage:graphics_devices')
elif request.method == 'POST':
form = forms.GraphicsDeviceForm(request.POST)
if form.is_valid():
payload = [{
'vendor_hex': form.cleaned_data['vendor_hex'],
'adapter_hex': form.cleaned_data['adapter_hex'],
'vendor_name': form.cleaned_data['vendor_name'],
'adapter_name': form.cleaned_data['adapter_name'],
}]
api = GraphicsDevices()
result = api.post(data=payload)
log(request.user, 'graphicsdevices.add', {
'payload': payload,
'success': result
})
if result:
messages.success(
request,
'Graphics device saved.'
)
return redirect('manage:graphics_devices')
context['page_title'] = "Graphics Devices"
context['form'] = form
context['upload_form'] = upload_form
return render(request, 'manage/graphics_devices.html', context)
示例2: graphics_devices_lookup
def graphics_devices_lookup(request):
form = forms.GraphicsDeviceLookupForm(request.GET)
if form.is_valid():
vendor_hex = form.cleaned_data['vendor_hex']
adapter_hex = form.cleaned_data['adapter_hex']
api = GraphicsDevices()
result = api.get(vendor_hex=vendor_hex, adapter_hex=adapter_hex)
return result
else:
return http.HttpResponseBadRequest(str(form.errors))
示例3: test_graphics_devices_csv_upload_pci_ids
def test_graphics_devices_csv_upload_pci_ids(self):
self._login()
url = reverse('siteadmin:graphics_devices')
def mocked_post(**payload):
data = payload['data']
expected = {
'vendor_hex': '0x0010',
'adapter_hex': '0x8139',
'vendor_name': 'Allied Telesis, Inc',
'adapter_name': 'AT-2500TX V3 Ethernet'
}
assert data[0] == expected
assert len(data) == 6
return True
GraphicsDevices.implementation().post.side_effect = mocked_post
sample_file = os.path.join(
os.path.dirname(__file__),
'sample-pci.ids'
)
with open(sample_file) as fp:
response = self.client.post(url, {
'file': fp,
'database': 'pci.ids',
})
assert response.status_code == 302
assert url in response['location']
示例4: test_graphics_devices_csv_upload_pcidatabase_com
def test_graphics_devices_csv_upload_pcidatabase_com(self):
self._login()
url = reverse('siteadmin:graphics_devices')
def mocked_post(**payload):
data = payload['data']
expected = {
'vendor_hex': '0x0033',
'adapter_hex': '0x002f',
'vendor_name': 'Paradyne Corp.',
'adapter_name': '.43 ieee 1394 controller'
}
assert data[0] == expected
assert len(data) == 7
return True
GraphicsDevices.implementation().post.side_effect = mocked_post
sample_file = os.path.join(
os.path.dirname(__file__),
'sample-graphics.csv'
)
with open(sample_file) as fp:
response = self.client.post(url, {
'file': fp,
'database': 'pcidatabase.com',
})
assert response.status_code == 302
assert url in response['location']
示例5: test_graphics_devices_edit
def test_graphics_devices_edit(self):
self._login()
url = reverse('siteadmin:graphics_devices')
def mocked_post(**payload):
data = payload['data']
expected = {
'vendor_hex': 'abc123',
'adapter_hex': 'xyz123',
'vendor_name': 'Logictech',
'adapter_name': 'Webcamera'
}
assert data[0] == expected
return True
GraphicsDevices.implementation().post.side_effect = mocked_post
data = {
'vendor_hex': 'abc123',
'adapter_hex': 'xyz123',
'vendor_name': 'Logictech',
'adapter_name': 'Webcamera'
}
response = self.client.post(url, data)
assert response.status_code == 302
assert url in response['location']
示例6: graphics_devices
def graphics_devices(request):
context = {}
form = forms.GraphicsDeviceForm()
upload_form = forms.GraphicsDeviceUploadForm()
if request.method == 'POST' and 'file' in request.FILES:
upload_form = forms.GraphicsDeviceUploadForm(
request.POST,
request.FILES
)
if upload_form.is_valid():
payload = list(
parse_graphics_devices_iterable(
upload_form.cleaned_data['file']
)
)
api = GraphicsDevices()
result = api.post(json.dumps(payload))
messages.success(
request,
'Graphics device CSV upload successfully saved.'
)
return redirect('manage:graphics_devices')
elif request.method == 'POST':
form = forms.GraphicsDeviceForm(request.POST)
if form.is_valid():
payload = [{
'vendor_hex': form.cleaned_data['vendor_hex'],
'adapter_hex': form.cleaned_data['adapter_hex'],
'vendor_name': form.cleaned_data['vendor_name'],
'adapter_name': form.cleaned_data['adapter_name'],
}]
api = GraphicsDevices()
result = api.post(json.dumps(payload))
if result:
messages.success(
request,
'Graphics device saved.'
)
return redirect('manage:graphics_devices')
context['page_title'] = "Graphics Devices"
context['form'] = form
context['upload_form'] = upload_form
return render(request, 'manage/graphics_devices.html', context)
示例7: graphics_devices
def graphics_devices(request):
context = {}
form = forms.GraphicsDeviceForm()
upload_form = forms.GraphicsDeviceUploadForm()
if request.method == "POST" and "file" in request.FILES:
upload_form = forms.GraphicsDeviceUploadForm(request.POST, request.FILES)
if upload_form.is_valid():
if upload_form.cleaned_data["database"] == "pcidatabase.com":
function = utils.pcidatabase__parse_graphics_devices_iterable
else:
function = utils.pci_ids__parse_graphics_devices_iterable
payload = list(function(upload_form.cleaned_data["file"]))
api = GraphicsDevices()
result = api.post(json.dumps(payload))
log(
request.user,
"graphicsdevices.post",
{"success": result, "database": upload_form.cleaned_data["database"], "no_lines": len(payload)},
)
messages.success(request, "Graphics device CSV upload successfully saved.")
return redirect("manage:graphics_devices")
elif request.method == "POST":
form = forms.GraphicsDeviceForm(request.POST)
if form.is_valid():
payload = [
{
"vendor_hex": form.cleaned_data["vendor_hex"],
"adapter_hex": form.cleaned_data["adapter_hex"],
"vendor_name": form.cleaned_data["vendor_name"],
"adapter_name": form.cleaned_data["adapter_name"],
}
]
api = GraphicsDevices()
result = api.post(json.dumps(payload))
log(request.user, "graphicsdevices.add", {"payload": payload, "success": result})
if result:
messages.success(request, "Graphics device saved.")
return redirect("manage:graphics_devices")
context["page_title"] = "Graphics Devices"
context["form"] = form
context["upload_form"] = upload_form
return render(request, "manage/graphics_devices.html", context)
示例8: test_graphics_devices_lookup
def test_graphics_devices_lookup(self):
self._login()
url = reverse('siteadmin:graphics_devices_lookup')
def mocked_get(**params):
if (
'adapter_hex' in params and
params['adapter_hex'] == 'xyz123' and
'vendor_hex' in params and
params['vendor_hex'] == 'abc123'
):
return {
"hits": [
{
"vendor_hex": "abc123",
"adapter_hex": "xyz123",
"vendor_name": "Logictech",
"adapter_name": "Webcamera"
}
],
"total": 1
}
raise NotImplementedError(url)
GraphicsDevices.implementation().get.side_effect = mocked_get
response = self.client.get(url)
assert response.status_code == 400
response = self.client.get(url, {
'vendor_hex': 'abc123',
'adapter_hex': 'xyz123',
})
assert response.status_code == 200
content = json.loads(response.content)
assert content['total'] == 1
expected = {
'vendor_hex': 'abc123',
'adapter_hex': 'xyz123',
'vendor_name': 'Logictech',
'adapter_name': 'Webcamera'
}
assert content['hits'][0] == expected