Set background color for column - django

Is it possible to set background color of a column in a django-tables2? My rows consists of 2 different object data so I have to make user to simple distinguish between them.
For example by changing a css class of the column.
class AdminPairTable(tables.Table):
reservation_1_destination_from = tables.TemplateColumn("""{{ record.0.destination_from }}""")
reservation_1_destination_to = tables.TemplateColumn("""{{ record.0.destination_to }}""")
reservation_1_date_departure = tables.TemplateColumn("""{{record.0.date_departure}}""")
reservation_1_time_departure = tables.TemplateColumn("""{{record.0.time_departure}}""")
reservation_1_specification = tables.TemplateColumn("""{{record.0.specification}}""")
reservation_2_destination_from = tables.TemplateColumn("""{{ record.1.destination_from }}""")
reservation_2_destination_to = tables.TemplateColumn("""{{ record.1.destination_to }}""")
reservation_2_date_arrival = tables.TemplateColumn("""{{record.1.date_arrival}}""")
reservation_2_time_arrival = tables.TemplateColumn("""{{record.1.time_arrival}}""")
reservation_2_specification = tables.TemplateColumn("""{{record.1.specification}}""")
confirm_pair = tables.TemplateColumn("""<button class="btn btn-success">Zaradiť pár</button>""")
The only way which comes to my mind is to simply use JQuery but it's not a best way.

You can set column attributes while creating columns.
Not sure why you use the TemplateColumn to just render a value, just Column would work here too (except for confirm_pair of course).

Related

Revit Python Shell - Iterate over each Element, find View Name and group by Sheet Number

I want to create a list of all Viewports by associated sheet number, View Name and Location Center. Like so:
vPorts = [('A0.01, View Name 01',[Center of ViewPort location]),('A0.02, View Name 01',[Centre of ViewPort location]),('A0.02, View Name 02',[Center of ViewPort location]),('A0.04, View Name 01',[Centre of ViewPort location]), etc.]
This so a user can align Multiple Viewports to each other in a listbox (not shown here) in WPF. I have the below:
import clr
clr.AddReferenceByPartialName('PresentationCore')
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName('System')
clr.AddReferenceByPartialName('System.Windows.Forms')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
from Autodesk.Revit.UI import *
doc = __revit__.ActiveUIDocument.Document
#List of ViewPort Elements
vPorts = []
#List for ViewPorts by sheet number, view name and location
vPortsloc = []
col_sheets = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType().ToElements()
for sheet in col_sheets:
vPorts.append(sheet.GetAllViewports())
for vp in vPorts:
print(vp)
Which gets me all the Viewports on all Sheets as List objects.
But I now want to format this list as stated above. I tried the following:
for vp in vPorts:
v = doc.GetElement(vp.ViewId)
vPortsloc.append(v.SheetNumber + v.Name + (v.GetBoxCenter().ToPoint()))
I believe I am not iterating over the whole List of lists. Not to mention I am new to python.. Any help would be really appreciated. Thanks!
Thanks Callum that helped alot! I just had to fix one or two typos, use append () instead of add, and get the View Name as well instead of the Sheet Name. As below
viewPorts = list(FilteredElementCollector(doc).OfClass(Viewport))
viewPortTriples = []
for vp in viewPorts:
sheet = doc.GetElement(vp.SheetId)
view = doc.GetElement(vp.ViewId)
viewPortTriples.append([sheet.SheetNumber, view.ViewName, vp.GetBoxCenter()])
print(viewPortTriples)
It could help to visualise multiple-dimensioned Lists like this:
vPortTriples = [
[Sheet Number, Sheet Name, ViewPort Center],
[Sheet Number, Sheet Name, ViewPort Center],
[Sheet Number, Sheet Name, ViewPort Center]
]
It looks like youre appending three separate items to a List. Should they be added as a new List, like this?
vPortTriples.append([v.SheetNumber, v.Name, v.GetBoxCenter().ToPoint()])
If you really are looking to catch every Viewport in a project, you can fetch all the ViewPorts by Class, so in your code it would look like:
# I find it easiest to convert FilteredElementCollector to a list
viewPorts = list(FilteredElementCollector(doc).OfClass(Viewport))
viewPortTriples = []
for vp in viewPorts:
# need to fetch the ViewPorts Sheet
sheet = doc.GetElement(vp.SheetId)
# add a new List to the 'viewPortTriples' List
viewPorts.Add([sheet.SheetNumber, sheet.Name, vp.GetBoxCenter()]
This is a pretty expensive way to do it though, better to fetch them only for the relevant sheet - say, by a specific Sheet Number (which may have been what you were trying to do in your example anyway!):
def getViewPorts (document, sheetNumber): # returns [[viewPort, bboxCenter], ... ]
sheets = list(FilteredElementCollector(document).OfClass(ViewSheet))
try:
targetSheet = [i for i in sheets if i.Sheetnumber == sheetNumber][0]
except:
print 'failed to find sheet',sheetNumber
return []
viewPortLocations = [] # a list of [[viewPort, bboxCenter], ... ]
for vpId in targetSheet.GetAllViewports():
vp = document.GetElement(vpId)
viewPortLocations.Add([vp, vp.GetBoxCenter()])
return viewPortLocations

How can I change the color of inside borders only for header columns?

I want to have output a table into RTF that has no lines inside the table but has the inside border in header cells. In addition, the header column is colorful. I know how to change the border color for all the cells but I can't figure out how to only change the header ones. I need to do it with proc template. Right now I get this table:
But I need to have it like this:
The code is :
proc template;
define style styles.new;
parent = Styles.Printer;
replace color_list /
'link' = blue
'bgH' = cxFF8200
'bgT' = white
'bgD' = white
'fg' = black
'bg' = white;
replace Table from Output /
frame = hsides
rules = groups
cellpadding = 2pt
cellspacing = 0.25pt
borderwidth = 0.75pt
background = color_list('bgt') ;
end;
run;
ods listing style=new;
Could someone tell me please how could I change the code to get the correct output?
Thank you!
The white column header separation 'lines' you are seeing are not actually drawn.
Change to cellspacing=1in and you will observe that the 'lines' are actually artifacts of the spacing and correspond to the overall background. I don't think there is an easy way to have header cell borders that are different than data cell borders.

How to use hover with multi-line in bokeh?

I'm facing issues with multi-line figure in bokeh. i can't get the values when i show my graph. i'm using series data type.
Code:
df = pandas.read_csv("Data.csv", parse_dates=["time"])
result = df.groupby(['time','up','down'], as_index = False)['up', 'down'].sum()
p = Figure(width=500, height=250,logo =None,
sizing_mode='scale_width',
tools="pan, box_zoom, wheel_zoom, save, reset, box_select",
x_axis_type="datetime",
title="Graph:",
x_axis_label="Time Frame",
y_axis_label="Utilization (GB)",
toolbar_location="below",
toolbar_sticky=False)
up = result["up"]
time = result["time"]
down = result["down"]
p.multi_line(xs = [time, time], ys = [up, down], color=['#2828B0', '#BC0096'], line_width=1, legend='graph_1')
hover = HoverTool(tooltips = [('Time', '#time'),
('data', '#up')])
p.add_tools(hover)
p.show()
The # fields of hover tooltips refer to columns in Bokeh ColumnDataSource objects. Since you have not created a CDS explicitly with column names of your choice, Bokeh makes one for you with the standard column name xs and ys in this case. So:
HoverTool(tooltips = [
('Time', '#xs'),
('data', '#ys')]
)
That will put a hover that displays over all segments in the multi-line. There is no way to have a hover work for just one or the other. If you need that, you will have to use separate calls to line instead of multi_line.

Python-docx - How to change table font size?

table = document.add_table(rows=1, cols=1)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
I have to change font size of text 'Qty' in table with one row and one column, how can I make it?
You need to get the paragraph in the cell. From the documentation of python-docx:
3.5.2 _Cell objects:
class docx.table._Cell (tc, parent)
paragraphs
List of paragraphs in the cell. A table cell is required to
contain at least one block-level element and end with a paragraph. By
default, a new cell contains a single paragraph. Read-only
Reference: python-docx Documentation - Read the Docs
The code:
To change font size of text 'Qty'
paragraph =hdr_cells[0].paragraphs[0]
run = paragraph.runs
font = run[0].font
font.size= Pt(30) # font size = 30
To change font size of the whole table:
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
for paragraph in paragraphs:
for run in paragraph.runs:
font = run.font
font.size= Pt(30)
Reference of how to access paragraphs in a table: Extracting data from tables
Up there the solution really helped. I use it for a while. But I found a tiny problem:time. As your table grows bigger the time you cost to build the table getting longer. So I improve it. Cut two rounds. Here you are:
The code changes the whole table
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
paragraph = paragraphs[0]
run_obj = paragraph.runs
run = run_obj[0]
font = run.font
font.size = Pt(30)
When you cut two rounds you save the time
Building on user7609283 answer, here is a short version to set a cell to bold (the cell must contain text before applying format as it looks for the first paragraph):
row_cells = table.add_row().cells
row_cells[0].text = "Customer"
row_cells[0].paragraphs[0].runs[0].font.bold = True
This font change applies to all cells of a table and is streamlined. All cells must contain text before being formatted or an index out of range error is thrown:
for row in table.rows:
for cell in row.cells:
cp = cell.paragraphs[0].runs
cp[0].font.size = Pt(14)
This next font change applies to a single cell as wanted, in this case the top left cell:
tc = table.cell(0, 0).paragraphs[0].runs
tc[0].font.size = Pt(14)

CAD to Feature Class

import arcpy
fc = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\789-AS-BUILT 8-7-13.dwg\Polyline'
out_gdb = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\RandolphPoint.gdb.gdb'
field = 'Layer'
values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))]
uniqueValues = set(Values)
for value in uniqueValues:
sql = """Layer" = '{0}'""".format(Value)
name = arcpy.ValidateTableName(value,out_gdb)
arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, name, sql)
I am trying to convert CAD(dwg) to ArcGIS 10.2.2 Feature Classes using a file geodatase as the workspace. I was just taught this code at an ESRI conference and of course it worked beautifully for the insturtor.
My error I am getting is "NameError:name'Values' is not defined" however I did define it as values = [row[0] for row in arcpy.da.SearchCursor(fc, (field))] I have been working hours on this, it would help out my job considerably.
Python variables are case-sensitive.
You've declared values with a lower-case v, but you're referring to it on the next line with an upper-case V.
(Same with value/Value further down.
import arcpy
fc = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\789ASBUILT.dwg\Polyline'
out_gdb = r'H:\H-ONUS UTILITY DATA GIS\As_Builts\2014\RandolphPoint_Phase2\RandolphPoint.gdb'
field = 'Layer'
value = [row[0] for row in arcpy.da.SearchCursor(fc, (field))]
uniquevalues = set(value)
for value in uniquevalues:
sql = """"Layer" = '{0}'""".format(value)
name = arcpy.ValidateTableName(value,out_gdb)
arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, name, sql)
Here is the solution, I had an extra .gdb in the geodatabase path
my word value was values so had to take the s off
and also in my sql statement I was missing a " before the word Layer
If anyone is reading this just change the individual parameters and it works beautifully!
thanks Juffy for responding and trying to help me out
Cartogal