django using variable in request.POST.get('x') - html

In my current project, users can create spreadsheets with fields, then each field inherits a unique ID based on the column it is attached to in the spreadsheet, so when fields are updated, my template looks like this:
<input type="text" name="{{field.unique_id}}" id="{{field.unique_id}}" value="{{field.data}}">
But in my views, when I attempt to grab the value from the field:
request.POST.get('field.unique_id')
It sees nothing because it's looking for literally 'field.unique_id' and not the variable that field.unique_id would produce.
Is there a way to tell it to replace field.unique_id with the variable or do I have to define the id of the POST get manually?

You can use a variable in request.POST.get() instead of a string, for example.
request.POST.get(my_var)
However in your case, request.POST.get(field.unique_id) does not work, since the keys in request.POST are strings, and field.unique_id is an integer.
The answer is to use str() to convert it to a string.
request.POST.get(str(field.unique_id))

Related

How do I retrieve all column fields as objects from Tabulator?

I want to make the custom filter dynamic. So, for writing future code I could pass in a list of references to each field object in the table.
That way I do not have to hardcode data.(field name here). Instead, it would work off the list of properties of the column object.
I know there ways to get the field normally but they are always returned as strings not object references. This obviously will not work with the dot operator.
I have some success with using JSON.parse followed by looping through the entries. But like before it returns the field as a string instead of a reference.
So is there a way to retrieve the column fields as objects and if so how?
I tried using the getColumns but I am still getting undefined when grabbing the fields. There is something wrong with my code.
function customFilter(data, filterParams) {
//data - the data for the row being filtered
//filterParams - params object passed to the filter
for (column of table.getColumns()){
field = column.getField();
console.log(data.field);
}
}
You speak about references in your question, but references to what? the field names themselves arent references to anything, they simply show Tabulator how to access the underlying row data, without a specific row data object to reference, there isn't anything to build any references from
You can only have a reference if it points to something, but there is nothing for the field definitions to point to without the row data.
If you are looking to have objects that you can manipulate the the getColumns function returns an array of Column Components with each component having a range of functions that can be called to manipulate that column. including the getField function that returns the field for that column.
Given that the Tabulator filter functions will accept the filed names with dot notation that shouldnt be an issue at all, but you can also pass the column component directly into the filter, so it shouldnt be a problem their either

Query Google Admin User directory comparing parameters

I'm trying to filter my users list by comparing two parameters
query="EmployeeData.EmployeeID=externalId"
EmployeeData.EmployeeID is a custom schema that is populated, with a cron job, with the same value as externalId.
Of course I let the cron do the field copy only if necessary, this is the reason I'm trying to filtering the users list.
In the way i wrote seems that the query trying to looking for a value "externalId" into the EmployeeData.EmployeeID ignoring that "externalId" is a even a field
any suggestion?
The way your code is written, the query sent to Google's servers is as you correctly guessed the following:
EmployeeData.EmployeeID=externalId where your actual externalId is not sent but rather the string "externalId".
To replace this string for the actual value of your variable, you can use what is called "string concatenation" 1. To do it, you just need to modify your code as shown below:
query="EmployeeData.EmployeeID=" + externalId;
This way, the query will be sent as you need to Google's servers.

Enummerate Field Names In Swagger

So I have done some hunting around online, and have been able to figure out how to use the enum tag in a swagger doc to specify a list of possible values for a field. However, in my current API what I need instead is to have a list of potential fields, each of which has a string value.
To be more precise, I have a POST request that sends JSON in the request body. As part of this request users need to send a single ID field. However, we accept multiple types of ID fields. So the request would look something like this:
{name:"name", product:"product", [FirstIdType, SecondIdType, ThirdIdType]:"ID Value"}
So I need to have the user submit a JSON that has a name, product, and one of FirstIdType, SecondIdType, or ThirdIdType. Technically it is required to have exactly one of those three ID types in the request, but I don't really mind if that isn't possible in the swagger doc. Noting it in the description for the field is fine.
The other constraint is that I can't really change the design at this point. The app has already been built using this design and changing it is out of my hands. Which means that I can't just make an array of ID Types and then choose one of them.
Here is the relevant bit from my swagger doc. The area that needs changed is the ID field. Any thoughts or directions on how to get that to go forward would be really appreciated.
definitions:
request_post:
description: (post) request schema
properties:
name:
type: string
product:
type: string
Id:
type: string
Instead of defining what optional fields can come on the path, you can label the fields that are required and make the rest variable by default.
http://swagger.io/specification/#parameterObject
required boolean Determines whether this parameter is mandatory. If
the parameter is in "path", this property is required and its value
MUST be true. Otherwise, the property MAY be included and its default
value is false.

JMeter: Is there any way to inject value "Patient_1077,ELLA(161st Pharmacy address)" in a input field

I have a a field which accepts value as "Patient_1077,ELLA(161st Pharmacy address)" i.e: Patient ID, name and Address, that I want to parameterize, CSV is not helpful in this case as value contains comma itself, is there any alternative way where I can inject these kind of values from file and parameterize the same?
Delimiter is configurable. See this for an example:
http://ivetetecedor.com/how-to-use-a-csv-file-with-jmeter/
You can also quote the data, which is another solution in your case.
You can make values in csv like:
Patient_0154, ELLA(102st The Cave)
Patient_0155, ELLA(101st The
Wall)
Then read it:
Patient_0154 -> user
ELLA(102st The Cave) -> adress
And when you need the value you do the simple trick — ${user},${adress}.
At least this is my approach when I don't want to code a lot for a simple task.

Saving values containing comma's in a HTML Multiple select

I have a HTML multiple select being used which caused no issue until a selection with a comma was entered. When saving / loading the values are split by ',' into a list. Therefore causing an issue
I have tried to find a way of possibly changing the character that is being used to split the values when the form is posted but came to a dead end.
Would be very grateful if someone has any insight into this.
Thanks in advance.
---Update with Code---
The control is created dynamically
Dim SelectName1 As New HtmlSelect
SelectName1.ID = "SelectName" & id
SelectName1.Name = "SelectName"
SelectName1.Multiple = True
and filled by looping though the values.
For Each value As String In Request.Form(idToFind).Split(",")
If Not IsDBNull(SelectName.Items.FindByValue(value)) Then....
I cannot add any more code than that, Apologies
After updating the question by add code, I think the available options are limited:
Create an extra Javascript method, that stores the selected values in a json object and store it into a hidden input field. I'm not an expert in asp.net, though I'm sure there exists a method to parse json objects from a string.
Create an extra javascript method, that concatinating all values to a String and store it into a hidden input field. With creation of a single string, you can define your own delimiter.
After that, add this extra Javascript mehod to the event onSubmit. Then submit the form and read the value from hidden input field.
P.S. In my eyes the second idea is more simple to create, than the first one. And maybe there are better ways.