setupTableChrome(tableData);
/* Add table data rows */
+ var column_index;
for (var i in tableData.rows){
+ /* only display if the column is display-able */
var row = $("<tr></tr>");
+ column_index = -1;
for (var key_j in tableData.rows[i]){
+
/* if we have a static: version of a key, prefer the static: version for rendering */
var orig_key_j = key_j;
key_j = "static:" + key_j;
}
+ /* we skip over un-displayable column entries */
+ column_index += 1;
+ if (! tableData.columns[column_index].displayable) {
+ continue;
+ }
+
var td = $("<td></td>");
td.prop("class", orig_key_j);
if (tableData.rows[i][key_j]){
/* Add table header and column toggle menu */
for (var i in tableData.columns){
var col = tableData.columns[i];
+ if (col.displayable === false) {
+ continue;
+ }
var header = $("<th></th>");
header.prop("class", col.field_name);
self.add_column(title="Git repository URL",
help_text="The Git repository for the layer source code",
hidden=True,
- static_data_name="git_url",
+ static_data_name="layer__vcs_url",
static_data_template=git_url_template)
git_dir_template = '''
self.add_column(title="Revision",
field_name="layer_version__get_vcs_reference")
-
self.add_column(title="Build",
help_text="Add or delete recipes to and from your project",
hideable=False,
static_data_name="add-del-layers",
static_data_template='{% include "recipe_btn.html" %}')
+ self.add_column(title="Project compatible Layer ID",
+ displayable = False,
+ field_name = "projectcompatible_layer",
+ computation = lambda x: (x.layer_version.get_equivalents_wpriority(Project.objects.get(pk=kwargs['pid']))[0]))
+
class LayerRecipesTable(RecipesTable):
""" Smaller version of the Recipes table for use in layer details """
elif isinstance(d[di], int) and hasattr(obj, "get_%s_display" % di):
nd[di] = getattr(obj, "get_%s_display" % di)()
return nd
+ elif isinstance( obj, type(lambda x:x)):
+ import inspect
+ return inspect.getsourcelines(obj)[0]
else:
raise TypeError("Unserializable object %s (%s) of type %s" % ( obj, dir(obj), type(obj)))
self.empty_state = "Sorry - no data found"
self.default_orderby = ""
+ # add the "id" column, undisplayable, by default
+ self.add_column(title="Id",
+ displayable=False,
+ orderable=True,
+ field_name="id")
+
+
def get(self, request, *args, **kwargs):
if request.GET.get('format', None) == 'json':
def add_column(self, title="", help_text="",
orderable=False, hideable=True, hidden=False,
field_name="", filter_name=None, static_data_name=None,
+ displayable=True, computation=None,
static_data_template=None):
"""Add a column to the table.
'filter_name' : filter_name,
'static_data_name': static_data_name,
'static_data_template': static_data_template,
+ 'displayable': displayable,
+ 'computation': computation,
})
def render_static_data(self, template, row):
col['field_name'] = col['static_data_name']
- if True: # we add the raw model data at all times
- model_data = row
+ # compute the computation on the raw data if needed
+ model_data = row
+ if col['computation']:
+ model_data = col['computation'](row)
+ else:
# Traverse to any foriegn key in the object hierachy
for subfield in field.split("__"):
if hasattr(model_data, subfield):
if isinstance(model_data, types.MethodType):
model_data = model_data()
- required_data[field] = model_data
+ required_data[col['field_name']] = model_data
data['rows'].append(required_data)