I have a filter class defined below.
filters.py
class CTAFilter(django_filters.FilterSet):
id = django_filters.NumberFilter(label="DSID")
class Meta:
model = CTA
fields = ['id', 'EmailID','id','Shift_timing']
Now I want to use this CTAFilter in normal template(table data)view and in download views.
I have observed that It is working fine for normal render view but when I am using it in my download views it is not working and I am getting all model data in the .xls file.
Please find the below questions which I have posted.
how to use Django filtered class data to 2 seperate view
I am not able to resolve this problem I have tried to check if I can define it globally so that the filter will work for all views(like RESTAPI).
Is there any way I can make my download view as a child view class of normal render view so that I will use the below code from the parent view(as it is working fine)?
cta_list = CTA.objects.all()
cta_filter = CTAFilter(request.GET, queryset=cta_list) allcta = cta_filter.qs
A>Normal View where the filter is working fine.
def retrievecta_view(request):
if request.method == 'GET':
allcta = CTA.objects.all()
allcta1 = allcta
allctagen = allcta1.filter(Shift_timing__exact='General')
allctamor = allcta1.filter(Shift_timing__exact='Morning')
allctseve = allcta1.filter(Shift_timing__exact='Evening')
allctatotal = allcta1.filter(Shift_timing__exact='Total')
# For filtering using 'django_filters',
cta_list = CTA.objects.all()
cta_filter = CTAFilter(request.GET, queryset=cta_list)
allcta = cta_filter.qs
paginator = Paginator(allcta, 50)
page_number = request.GET.get('page')
try:
allcts = paginator.page(page_number)
except PageNotAnInteger:
allcts = paginator.page(1)
except EmptyPage:
allcts = paginator.page(paginator.num_pages)
return render(request, 'abcd/cta.html', {'allcta': allcta, 'cta_filter': cta_filter, 'allcta1': allcta1,
'allctagen': allctagen, 'allctamor': allctamor,
'allctaeve': allctaeve,
'allctatotal': allctatotal})
b> Download view where I am trying to use the same filter but it is giving me all records.
def exportcts_data(request):
response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename="CTA_ShiftTiming.xls"'
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('CTS_ShiftChange Data') # this will make a sheet named Users Data
# Sheet header, first row
row_num = 0
font_style = xlwt.XFStyle()
font_style.font.bold = True
columns = ['id','idk','Shift_timing','EmailID','Vendor_Company','Project_name','SerialNumber','Reason','last_updated_time']
for col_num in range(len(columns)):
ws.write(row_num, col_num, columns[col_num], font_style) # at 0 row 0 column
# Sheet body, remaining rows
font_style = xlwt.XFStyle()
cts_list = CTA.objects.all()
cts_filter = CTAFilter(request.GET, queryset=cts_list)
allcts = cts_filter.qs
rows = allcts.values_list('id', 'idk', 'Shift_timing', 'EmailID', 'Vendor_Company', 'Project_name',
'SerialNumber', 'Reason', 'last_updated_time')
for row in rows:
row_num += 1
for col_num in range(len(row)):
ws.write(row_num, col_num, row[col_num], font_style)
wb.save(response)
return response
I'm not quite following why you want to have separate view for downloads which ultimately should be rendering the same data as the normal view if they are using the same filter. Maybe it is just my misunderstanding so I'm not sure if this will help you but let's see.
First off let me explain a little background. This is a task management application and in there I have an html page where the person logged in can view all of their completed tasks. (Nice and simple.) However the user may have tasks from many different projects so I have created a dropdown list that allows them to filter by a single project. They may also want to only see a specific period of tasks so I have allowed them to set a date range by providing a start and end date. (Nothing startling or earth shattering here.) Once the parameters are set, the user clicks a search button and the filtered results are displayed. The page also has an Export button which downloads the results of the filtered list to a .xls spreadsheet.
So how do I do this? Well first of all, I am using Django-Tables2 for rendering my tables. I simple predefine the table in tables.py and throw it the data I want from my views and it takes care of everything. Therefore my view code is minimal and very simple and looks like this.
from django_tables2.export.export import TableExport
from .tables import CompletedTable
def completedlist(request, page='0', name=''):
#Check to see if we have clicked a button inside the form
if request.method == 'POST':
return redirect ('tasks:tasklist')
else:
# Pre-filtering of user and Master = True etc is done in the MasterListFilter in filters.py
# Then we compile the list for Filtering by.
f = CompletedListFilter(request.GET, queryset=Task.objects.all(),request=request)
# Then we apply the complete list to the table, configure it and then render it.
completedtable = CompletedTable(f.qs)
rows = len(completedtable.rows)
if int(page) > 0:
RequestConfig(request, paginate={'page': page, 'per_page': 10}).configure(completedtable)
else:
RequestConfig(request, paginate={'page': 1, 'per_page': 10}).configure(completedtable)
export_format = request.GET.get('_export', None)
if TableExport.is_valid_format(export_format):
exporter = TableExport(export_format, completedtable)
return exporter.response('Completed Tasks.{}'.format(export_format))
return render (request,'tasks/completedlist.html',{'completedtable': completedtable, 'filter': f, 'rows': rows})
As you can see, every time the user hits either the search or export buttons, I am recompiling the queryset in variable f with the following line:
f = CompletedListFilter(request.GET, queryset=Task.objects.all(),request=request)
I have predefined the .xls format in the html page with this code:
<button class="btn btn-primary btn-xs" name="_export" value="xls" type="submit">Export</button>
So then I can test to see if the user clicked the Export button or not by getting the value of _export from the request like this:
export_format = request.GET.get('_export', None)
If the user did not click the export button, export_format will default to none. If they did, it will be .xls as defined in the html. Then I simply either export the data in line with the filters set by the user or I render the page with the same filtered list of data like this:
if TableExport.is_valid_format(export_format):
exporter = TableExport(export_format, completedtable)
return exporter.response('Completed Tasks.{}'.format(export_format))
return render (request,'tasks/completedlist.html',{'completedtable': completedtable, 'filter': f, 'rows': rows})
So there you have it. As you say your filter is working for the normal view I have not detailed my filter as that would seem to be unnecessary.
Maybe this solution is too simplistic for your requirements and yes, before I get shot down by other developers, there are several limitations, such as 'What if the user wants to use something other than .xls?' or 'What if they want to export more than one Project at a time?' Like everything, there is always room for improvement but when I'm bashing my head with an issue, I often find it helps to strip things back to basics and see what comes from that.
function() {
function render(params)
{
params.portlet.title = 'My Portlet';
var content = '<body>'+
'<form>' +
' <fieldset>'+
' <legend>Selecting elements </legend> ' +
'<p> <label>Select Range</label> <select id = "myList"><option value = "1">Daily</option> <option value = "2">Weekly</option>'+
' <option value = "3">Monthly</option> <option value = "4">Yearly</option>' +
' </select>' +
' </p>' +
' </fieldset>' +
'</form>' +
' </body>';
params.portlet.html = content;
}
Can you guys help me in writing code for pie chart . and provide me some syntax for calling other scripts from portlet.
I've tried adding a select field( Drop down) using html in netsuite and it is working fine. But i want pie chart in my UI.
NetSuite runs JavaScript/HTML/CSS like everything else. I would make an HTML file holding everything you need (JavaScript, CSS, and any plotting libraries), and open it with localhost to check things out. When you have that the way you like it, pick the option that works for you to port that into NetSuite:
Copy the text to var content = "your_html_here" (will likely be a pain to maintain but will work fine).
Load the HTML file into your file cabinet, and load it into your portlet script to do text replacing to insert any data you need (one extra step, but much easier to maintain and you can pull down the HTML file to do any local testing you need):
var content = file.load({id: /Suitescripts/path_to_your_html_file.html"}).getContents()
content = content.replace("Placeholder_Text", "With This")
Since you're asking how to build a pie chart, I would recommend using something like d3js where you might be able to build off this example of a pie chart.
If you get stuck, or need some help, comment back down below. There's no such thing as a stupid question, promise!
EDIT
You asked about adding search results to your HTML file. Although it sounds like you've answered your question, I will document the process here just in case, never know whose coming here from Google!
var mySearch = search.load({id: "my_search_id", ...})
mySearch.run.each(function(result) {
searchHTML += "<tr>"
searchHTML += `<td>${result.getText({name: "fieldname", ... })}</td>`
searchHTML += `<td>${result.getValue({name: "fieldname", ... })}</td>`
searchHTML += "</tr>"
// To move onto the next result
return true;
})
Hope that helps!
I am having an issue with one part of my automation job, and that is selecting ALL the options in a combobox, on a webpage, using VBA and IE.
This code selects ONE item in the combo box
Set frm = HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
frm.Value = "AUT"
However, when I try to select multiple items, it just selects the last one, not all of them.
Here is the code from the web page
<p id="DispFormCollapsible.Rc10"class="formrow" >
<span id="DispFormCollapsible.Rc10.C1" class="querytextleft">
<label for="UFG.USER_TYPES" id="LabelForContro123"class = "simpletext" >
Accessible Types:<span class="redstar">*</span></label></span>
<span id="DispFormCollapsible.Rc10.C2" class="querytextright">
<span class="labelColumn_combo">
<span class="labelColumn_combi_brdr">
<select name= "UFG.USER_TYPES" multiple= "true" class = "dropdownexpandalbe"
id="UFG.USER_TYPES" title = "Accessible Financial Transaction Types">
<option value="AUT" title="ACTIVE USER TYPE1" >TYPE1</option>
<option value="SET" title="Selective User Type" >TYPE2</option>
<option value="TST" title="Test User Type" >TEST3</option>
</select></span></span>
<input type ="hidden" name= "UFG.USER_TYPES" value="NULL" >
</span></p>
Here is my VBA line to select an item
Set frm = HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
frm.Value = "AUT"
What I need it to do, is select all the "option values" in the combobox. I think it needs to be an array maybe, or some other way. I've tried searching, but I'm getting nowhere. Any help appreciated. Thx
Tried the following, but get an error 91 Block not set. I've also tried using the Values "AUT" in the children, and when doing that I don't get an error, but it doesn not select anything.
With HTMLDoc.getElementsByName("Select")(0)
.Children(1).Selected = True
.Children(2).Selected = True
.Children(3).Selected = True
End With
Also tried the following, this doesn't give an error, but only selects the first option in the list.
With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
.Children(AUT).Selected = True
.Children(SET).Selected = True
.Children(TST).Selected = True
End With
This is strange, when I use this code, it selects the first two in the list, but not the third.
With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
.Children(all).Selected = True
End With
With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
.Children(0).Selected = True
.Children(1).Selected = True
.Children(2).Selected = True
End With
The above code fixed it... whoopie!
I'm trying to use the following code to upload a file to a webpage:
WD.document.getElementById("fileUpload").Value = "filepath"
'The code does not came with the property 'value' empty( = "") its just not 'there until i click the buttom "search"
'and use the popup dialog to select a file.
'Also when inserting the value by code, the source code
' returns 'value = ""' and whenever i try again,
' it still gets value = ""
WD.document.getElementById("fileUpload").Click
'The Click fires a windows popup dialog for selecting a file, so its not worthy 'to use it.
WD.document.getElementById("frmUpload").submit
'i can use this command to fire the event of uploading, but with a value = "" 'its going to return the "file not found" popup
'HERES THE SOURE CODE FOR THE SITUATION___________________:
<INPUT id=fileUpload size=48 type=file name=fileUpload>'the element
<FORM id=frmUpload encType=multipart/form-data method=post action=/ChamadoPC/Upload/12295979/1 target=fraUpload jQuery15105169442065138357="118">'the form
hope you can help me, hope everybody understand!
I am a beginner in Selenium and Python, writing my first code to log in to a specified website and got stuck with the button part, not sure how to give an XPath to the below button code.
<button class="js-tfaLoginButton Button Button--pill Button--action Loadable u-marginBottomStandard u-size1of2 u-cursorPointer u-outlineNone" type="submit" data-qa="submit_login">
Sign In
</button>
Tried out the below XPath but doesn't work:
/button[#class="js-tfaLoginButton Button Button--pill Button--action Loadable u-marginBottomStandard u-size1of2 u-cursorPointer u-outlineNone"]#class
Or is there any other method instead of XPath?
Thank you.
The correct XPath is:
//button[#class="js-tfaLoginButton Button Button--pill Button--action Loadable u-marginBottomStandard u-size1of2 u-cursorPointer u-outlineNone"]
Hope it helps you!
We have the following ways to identify the element in the browser
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
Out the above ways to locate element. We can use tagname or value(text) present inside the tag, like this:
XPATH:
driver.find_elements(By.XPATH, '//button[contains(text(), "Sign In"]')
or
driver.find_element(By.XPATH, '//button[text()="Sign In"]')
TAG_NAME:
driver.find_elements(By.TAG_NAME, '//button')