Is there an alternative to "keep-together='always'" on table-row? - xslt

Upon finding the "keep-together" attribute, and needing to not page break inside a row I added keep-together="always" on every table-row element in my xslt.
Is there a nicer way of achieving the same effect? It seems a bit hacky.
(ps. I will accept "no" as an answer if no one provides a better one, provided some kind of explanation is proffered.)

keep-together="always" is dangerous because that's a compound property that also indirectly sets keep-together.within-line="always" (prohibiting line breaks inside a table-cell). You should use keep-together.within-column="always" instead. But specifying that on a table-row is actually the way to go. Nothing hacky about it.
See also: http://www.w3.org/TR/xsl11/#datatype

I have used the following three methods to keep table rows together with some success:
Keep whole block together
<tr keep-together.within-page="always">
...
</tr>
Keep adjacent blocks together
<tr keep-with-next.within-page="always">
<td keep-together.within-page="always">...</td>
...
</tr>
<tr>...</tr>
<tr>...</tr>
<tr keep-with-previous.within-page="always">
<td keep-together.within-page="always">...</td>
...
</tr>
Though you have to be careful - if the row or cell would span more than one page of a generated document, you will loose the bottom of that page off the bottom!

This answer solved my problem of a table row that was flowing over a page break when i needed to lock the table together. i used the <fo:table keep-together="always"></fo:table>
Thanks.

With an XSL formatter that handles integer keeps, you can use an integer value so that the formatter will try to keep the row together but will break the row rather than run off the end of the page. However, this question is tagged for FOP, and FOP's compliance page currently states that it has limited support for integer keeps (http://xmlgraphics.apache.org/fop/compliance.html#fo-property-keep-together), so YMMV.

Related

capybara find and save text value from a page

i am in the process of writing a Capybara Automation suite. one thing that i am trying to do is extract a value between the td tags from the html source
<td class="table-column-data">CB/AE9999XX/A001</td>
i.e. find and extract the value CB/AE9999XX/A001 then save it into a variable to use later on.
i hope you can help
thanks
saved_text = find("td.table-column-data").text
Will get the text from the element - obviously the selector passed needs to select a unique element, which will depend on the surrounding html
You can use the below mentioned way to extract and save the value in a variable:
extractedValue = find('.table-column-data').text
This will fetch the text "CB/AE9999XX/A001" and store it in the variable "extractedValue".
Apart from this, you can also extract the text using jquery as shown below:
extractedValue = page.evaluate_script("$('.table-column-data').text()")
Hope this helps :)

Web2py Foreign key ID getting displayed

I am using web2py for the first time for a project. I made a field in the following way
db.define_table('my_years',Field('case_year',db.case_years,required=True,requires = IS_IN_DB( db, 'case_years.id', '%(year)s' )));
This field is referring to another table which has a list of years, that table is defined as follows:
db.define_table('case_years',Field('year'),format = '%(year)s') ;
Then I am displaying the my_years in a view.
<table id="case_list">
<thead>
<tr>
<th>Number</th>
<th>Year</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{{ for case in cases: }}
<tr>
<td>{{=case.case_number}}</td>
<td>{{=case.case_year}}</td>
<td> Edit Case </td>
</tr>
{{pass}}
</tbody>
</table>
The issue I am facing is that while displaying the year from "my_years" I'm seeing the primary key ID of the case_years instead of seeing the Value (i.e. case_years.year) in years.
Please help..
If you remove the explicit requires argument, then you will get a default requires that is the same as you defined it, plus you will get a default represent attribute that will display the year instead of the id in SQLTABLE, SQLFORM.grid, and read and update SQLFORM's.
Field('case_year', db.case_years, required=True)
Alternatively, you could explicitly define the represent attribute:
Field('case_year', db.case_years, required=True,
requires=IS_IN_DB(db, 'case_years.id', '%(year)s'),
represent=lambda id, r: db.case_years(id).year))
Also, note that you don't need semicolons at the ends of your lines of code.
UPDATE (based on new code provided):
In your view, the field's represent attribute will have no effect because you are not using a SQLFORM or SQLTABLE but simply displaying a single value:
{{=case.case_year}}
case.case_year is an id value, so that's what will get displayed above. If you want to display the associated year from the db.case_years table, you need to do:
{{=db.case_years(case.case_year).year}}
You can also do a recursive select:
{{=case.case_year.year}}
which is equivalent to the above. Note, both methods will result in an additional database query for each case, so this will be somewhat inefficient. Instead, you can make your initial query for the cases a join and include the "year" field from the case_years table (see http://web2py.com/books/default/chapter/29/06#Inner-joins).

Avoid a second iteration in Django template

I've created a QuerySet in a view. I need to do something to one of the fields (parse it in to a dictionary, to be exact). So, I iterate through the QuerySet to do my parsing. Then, I take my new object (whatever it's going to be), and pass it to the template. Then, the template has to iterate through the object... Essentially 2 iterations of the same information.
Here's my view code:
t = Transaction.objects.values()
for r in t:
r['data'] = dict([z.split(':',1) for z in r['data'].split('|')])
...Of course, I pass the new and improved 't' to the template, where something like this happens:
{% for r in t %}
<tr>
<td>{{ r.username }}</td><td>{{ r.source }}</td><td>{{ r.trans }}</td><td>{{ r.transtime }}</td>
<td>
{% for k,v in r.data.items %}
{{ k }}: {{v}}<br>
{% endfor %}
</td>
</tr>
{% endfor %}
In the old-school days of spaghetti code, this wouldn't be an issue. I'd just loop through the data, and for each record I'd parse out and display what I needed...
So here's my question: In django-world, how do I avoid looping through my data twice? Is this "OK" in Python-world, or is there a better way? Thanks!
It's hard to really understand what you need without a more concrete example of what you are doing, but generally one would solve this by passing the view that queryset object wrapped in a generator for deferred processing.
There's nothing necessarily "wrong" with looping through the same iterable twice. Sometimes, that may be necessary, and without example code, there's no way to say whether it is or not.
What does matter is that it's not actually querying the database twice. Django caches querysets, but the way you interact with it sometimes can cause additional queries on top of that. Again, though, without example code, I can't say whether you have a problem with that or not.
UPDATE There's nothing wrong with what you've done, if there's additional processing needed on the queryset, the right place to do that is in the view. Looping over the new and improved version in the template is not a problem, and the database is not being hit with redundant queries. I say stop worrying so much ;)

Accessing viewModel properties

I have a template binding as follows
<tbody id ="mytemplatetbody"
data-bind="template: {name: 'myTemplate', foreach: Items}">
</tbody>
The rows in template have a status field whose value can be 1 or 2 or 3. There are three checkboxes on this screen and depending on what checkbox(es) user selects, the rows should be visible.
This is what I have done: Added three observable properties to viewModel and tied them to the three checkboxes. I can display those values as follows:
<span data-bind="text: viewModel.checkBox1Selected()"></span>
Question: I am not able to put any if statements in my template for example like this...
{{if viewModel.checkBos1Selected() }}
...so what is the best way or anyway I can accomplish what I described above?
A common way to do this type of thing is to create a dependentObservable to represent your filtered rows. Then, bind your template against this dependentObservable. Whenever one of your observable filters changes, then the filtered rows will be re-evaluated.
Here is a sample: http://jsfiddle.net/rniemeyer/BXeCb/
You can certainly do the filtering however works best for your app. I used the checked binding against an observableArray to hold my filters, but you could easily go with your method of using three observable properties on your view model.

Ordered list form value in Django form

Is there a way to submit an unbounded list of values as part of a form and retrieve it in Django as an ordered list? I saw this question: Django equivalent of PHP's form value array/associative array which makes sense, however since the values are submitted with the same name as separate POST values I assume they are unordered.
Ideally, I'd like this on the front end:
<input type="hidden" name="list[0]" value="blah">
<input type="hidden" name="list[1]" value="blah2">
<input type="hidden" name="list[2]" value="blah3">
and be able to see which list item occurred in which position when the form was submitted.
I want it sorted in an order determined in the front-end HTML, not sorted by value. I know about getlist(), but that doesn't preserve order.
As far as I'm aware, the square bracket notation is a convention of PHP rather than HTML per se.
There seems to be a Django workaround using dot notation to generate expanded dictionaries (http://stackoverflow.com/questions/2527476/phps-form-bracket-trick-is-to-djangos). I haven't tried it, but it seems it could work
The other solution is to parse the form names yourself, extracting the number from the square brackets and generating your own ordered list
(DISCLAIMER: I'm a mere casual programmer, and am more than willing to acknowledge that im wrong - but hopefully the SO moderation system will moderate any silly comments into oblivion)