Django Monthly Grid / Table - django

I have a stock portfolio with monthly returns. Currently the returns are stored in the database as the first of each month, and the year.
So January 1, 2016 - 5%
February 1, 2016 - 3%
What's the best way to display this in a Django template?
I want to have each year in a separate row, and columns being the dates so:
Jan Feb Mar Apr....
2014
2015
2016
What's the best way to put the monthly returns into their correct position?
Thanks for the help!

I don't know if it is the best way, but I end up using a list of tuples for doing this.
In the views.py, make a dictionary entry that contains the line you want to display in a tuple and make a list of those lines:
def testview(request):
x = [(2014,1,2,3),(2015,4,5,6),(2016,7,8,9)]
return render(request, 'yourtemplate.html', {'data':x})
Next make a js table in your template (yourtemplate.html) and loop over the lines
<table>
<tr>
<th></th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
</tr>
{% for tuple in data %}
<tr>
<th>{{tuple.0}}</th>
<th>{{tuple.1}}</th>
<th>{{tuple.2}}</th>
<th>{{tuple.3}}</th>
</tr>
{% endfor %}
</table>
I hope this helps!

Related

Removing zero quantity items from Netsuite Picking Ticket Advanced PDF

I am new to NetSuite and my current role. Our warehouse team is strunggling with Picking Tickets coming through with zero quantity items among a long list of items to be picked.
Pickers are making mistakes and picking items for which an order has not been placed. The original problem is with the Sales Order which is being worked on by others.
I am trying to find a quick solution whereby when picking tickets are printed the zero quantity items are filtered out and not printed.
Really appreciate any help provided.
Try this "SHOW UNCOMMITTED ITEMS ON PICKING TICKETS"
Navigation: setup--> Accounting-->Accounting preferences-->order management
If anyone else comes across this, you can also add this code to the PDF template in the case where you still need the uncommitted line items in Netsuite but just not printed on the PDF:
<thead>
<tr>
<th>...</th>
<tr/>
</thead>
<!-- only line items with qty > 0 on Sales Order will print -->
<#if item.quantity gt 0>
<tr>
<td>...</td>
</tr>
</#if>

Convert HTML Table to plain Text in Power BI

I am a beginner in power BI. I have to create a report with share point data. I have imported the data into dataset. However, some columns have text with html table tags or style like below -
<div class="ExternalClass5DA0D04953B047459697675F266FEABF">
<p>​</p>
<table width="395" border="0" cellspacing="0" cellpadding="0" style="width:296pt;">
<tbody>
<tr height="115" style="height:86.4pt;">
<td width="395" height="115" class="xl64" style="width:296pt;height:86.4pt;">
I am working on issue. I shall update the progress. <br>
</td>
</tr>
</tbody>
</table>
<p><br></p>
</div>
But I would like to show the plain text only which is "I am working on issue. I shall update the progress."
From this community thread, you can find a handy function for stripping all the HTML tags:
Here's the core logic (ignoring the documentation metadata for readability):
let func = (HTML) =>
let
Check = if Value.Is(Value.FromText(HTML), type text) then HTML else "",
Source = Text.From(Check),
SplitAny = Text.SplitAny(Source,"<>"),
ListAlternate = List.Alternate(SplitAny,1,1,1),
ListSelect = List.Select(ListAlternate, each _<>""),
TextCombine = Text.Combine(ListSelect, "")
in
TextCombine
in
func
Having this handy bit of code, create a new blank query and paste the above code into the advanced editor and give it a name, say, TextFromHTML.
Once you have that function defined, you can use it in any of your queries. For example, here's what a step to transform the column ColWithHTML might look like:
Table.TransformColumns(#"Prior Step", {{"ColWithHTML", each TextFromHTML(_), type text}})
You can create a new column with below formula as show below
if [HMTLField] = null then null else Html.Table([HMTLField] , {{"text",":root"}})
Then click on the button on right top of the field to convert this field as text by expanding it.

EmberJS - {{moment-format 'date' 'output' 'input'}} repeats todays date in every row when used in {{#each} block

I am using ember-moment addon in order to format the dates in the following table:
<tbody>
{{#each model as |model|}}
<tr class="clickable-row">
<td>{{model.id}}</td>
<td>{{model.first_name}}</td>
<td>{{model.last_name}}</td>
<td>{{model.date_of_birth}}</td>
<td>{{model.inserted_at}}</td>
<td>{{model.departed_at}}</td>
</tr>
{{/each}}
</tbody>
date_of_birth property returned from the DB ha the following format:
yyyy-mm-ddThh:mm:ss+|-hhmm
When I try to format it like below;
{{moment-format 'model.date_of_birth' 'DD/MM/YYYY' 'yyyy-mm-ddThh:mm:ss+|-hhmm' }}
I end up with a populated table full of unique rows, except the date of birth is just today's date on every single row.
I know I am missing something obvious and someone out there is going to make me look very silly!
You should pass binding date object to the helper instead of passing its name as a string. Therefore use it like this:
{{moment-format model.date_of_birth 'DD/MM/YYYY' }}

Change <td> to <th> in first row of a HTML table server side using Cold Fusion

I am sending a HTML string to the Cold Fusion (9) server. The string contains a HTML table with multiple rows. Since the table doesn't have a head I need to change the <td>s of the first row into <th>s.
For your information:
The code to change is a paste code coming from MS Word. The code gets sent to the server to check if there are any tables in it. If yes, there is an option dialog shown to the user where he can descide how the table will be formatted (striped, hovers and so on).
In my opinion the best way to do that would be ReReplace(). But I can't figure what the right regex can be.
Any suggestions on that will be much appreciated.
The code looks like:
<table class="table">
<tbody>
<tr><td>Head 1</td><td>Head 2</td><td>Head 3</td></tr>
<tr><td>Content 1 Row 1</td><td>Content 2 Row 1</td><td>Content 3 Row 1</td></tr>
<tr><td>Content 1 Row 2</td><td>Content 2 Row 2</td><td>Content 3 Row 2</td></tr>
</tbody>
</table>
And should look like:
<table class="table">
<tbody>
<tr><th>Head 1</th><th>Head 2</th><th>Head 3</th></tr>
<tr><td>Content 1 Row 1</td><td>Content 2 Row 1</td><td>Content 3 Row 1</td></tr>
<tr><td>Content 1 Row 2</td><td>Content 2 Row 2</td><td>Content 3 Row 2</td></tr>
</tbody>
</table>
Thanks in advance.
Obligatory warning: maybe a parser or as #npinti suggested changing the output in the first place is a far better way to go.
That being said, you could use a lazy quantifier (expensive!) between the <td> tags and feed the function chunks of <table> parts and substitute it with <th>\2</th> (see the regex 101 demo for an example).
(<td>(.*?)<\/td>)
Hint: This does not take additional attributes into account (e.g. class="test123").

how to print each value in list returned from controller action in to each row of gsp table?

I am returning a list of dates,list of size and list of months from controller action to gsp..i want each value in dates,size and months list to be displayed in 3 different fields of each row.how to achieve it?
Advance thanks
laxmi.P
Suppose dlist is the list of dates you are passing from the controller/action, then in gsp:
<table>
<g:each in="${dlist}">
<tr>Date: ${it}</tr>
</g:each>
</table>
or
<table>
<g:each var="date" in="${dlist}">
<p>date: ${date}</p>
</g:each>
</table>
Enjoy
UPDATE:
To achieve this thing, I think it would be better to pass list of maps to gsp page, e.g
def index = {
def data = [[date:"d1",size:'s1', month:'m1'],
[date:'d2',size:'s2', month:'m2'],
[date:'d3',size:'s3', month:'m3']]
render(view:'/index',
model:[data:data])
}
in gsp page:
<table>
<g:each in="${data}">
<tr><td>Date: ${it.date}, Size: ${it.size}, Month: ${it.month}</td></tr>
</g:each>
</table>
HTML view:
Date: d1, Size: s1, Month: m1
Date: d2, Size: s2, Month: m2
Date: d3, Size: s3, Month: m3
use <g:each> tag. Your <table> tag should be outside <g:each> and <tr> tags inside <g:each>