class DatLine(Dictable):
"""Line of .dat file parsed into comments and machine-readable data."""
dictables = {'booking_line', 'code', 'comment', 'error', 'is_intro'}
+ prev_line_empty: bool
def __init__(self, line: str) -> None:
self.raw = line[:]
booking.recalc_prev_next(self.bookings)
if booking:
booking.gap_lines = gap_lines[:-1]
+ self._recalc_prev_line_empty()
def save(self) -> None:
"""Save current state to ._path_dat."""
"""If .dat_lines different to those of last .load()."""
return self._hash_dat_lines() != self.last_save_hash
+ def _recalc_prev_line_empty(self) -> None:
+ prev_line = None
+ for line in self.dat_lines:
+ line.prev_line_empty = False
+ if prev_line:
+ line.prev_line_empty = not prev_line.code + prev_line.comment
+ prev_line = line
+
def _recalc_dat_lines(self) -> None:
self.dat_lines = self.initial_gap_lines[:]
for booking in self.bookings:
self.dat_lines += booking.booked_lines
self.dat_lines += booking.gap_lines
+ self._recalc_prev_line_empty()
def _move_booking(self, idx_from, idx_to) -> None:
moving = self.bookings[idx_from]
<form action="/ledger_{% if raw %}raw{% else %}structured{% endif %}" method="POST">
<table class="ledger">
{% for dat_line in dat_lines %}
- <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}">
-
- <td{% if dat_line.is_intro %} id="{{dat_line.booking_id}}"{% endif %}>
- {% if dat_line.is_intro %}
- <a href="#{{dat_line.booking_id}}">[#]</a>
- {{ table_dat_lines_action_button(dat_line, "move", "up", "^", dat_line.booking.can_move(1)) }}
- {% elif dat_line.booking_line.idx == 1 %}
- <a href="/balance?up_incl={{dat_line.booking_id}}">[b]</a>
- {{ table_dat_lines_action_button(dat_line, "move", "down", "v", dat_line.booking.can_move(0)) }}
- {% elif dat_line.booking_line.idx == 2 %}
- {{ table_dat_lines_action_button(dat_line, "copy", "here", "c") }}
- {{ table_dat_lines_action_button(dat_line, "copy", "to_end", "C") }}
- {% endif %}
- </td>
+ {% if raw or dat_line.code or dat_line.comment %}
+
+ {% if (not raw) and dat_line.prev_line_empty %}
+ <tr ><td> </td></tr>
+ {% endif %}
+ <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}">
- {% if raw %}
- <td{% if dat_line.error %} class="invalid"{% endif %}>
+ <td{% if dat_line.is_intro %} id="{{dat_line.booking_id}}"{% endif %}>
{% if dat_line.is_intro %}
- <a href="/bookings/{{dat_line.booking_id}}"/>{{dat_line.raw_nbsp|safe}}</a>
- {% else %}
- {{dat_line.raw_nbsp|safe}}
+ <a href="#{{dat_line.booking_id}}">[#]</a>
+ {{ table_dat_lines_action_button(dat_line, "move", "up", "^", dat_line.booking.can_move(1)) }}
+ {% elif dat_line.booking_line.idx == 1 %}
+ <a href="/balance?up_incl={{dat_line.booking_id}}">[b]</a>
+ {{ table_dat_lines_action_button(dat_line, "move", "down", "v", dat_line.booking.can_move(0)) }}
+ {% elif dat_line.booking_line.idx == 2 %}
+ {{ table_dat_lines_action_button(dat_line, "copy", "here", "c") }}
+ {{ table_dat_lines_action_button(dat_line, "copy", "to_end", "C") }}
{% endif %}
</td>
- {% else %}
- {% if dat_line.is_intro %}
- <td class="date {% if dat_line.error %} invalid{% endif %}" colspan=2>
- <a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking.date}}</a>
+
+ {% if raw %}
+ <td{% if dat_line.error %} class="invalid"{% endif %}>
+ {% if dat_line.is_intro %}
+ <a href="/bookings/{{dat_line.booking_id}}"/>{{dat_line.raw_nbsp|safe}}</a>
+ {% else %}
+ {{dat_line.raw_nbsp|safe}}
+ {% endif %}
</td>
- <td{% if dat_line.error %} class="invalid"{% endif %}>{{dat_line.booking.target}}</td>
- <td>{{dat_line.comment}}</td>
- {% elif dat_line.error %}
- <td class="invalid" colspan=3>{{dat_line.code}}</td>
- <td>{{dat_line.comment}}</td>
- {% elif dat_line.booking_line %}
- <td class="amt">{{dat_line.booking_line.amount_short}}</td>
- <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"…")}}</td>
- <td>{{dat_line.booking_line.account}}</td>
- <td>{{dat_line.comment}}</td>
{% else %}
- <td colspan=2></td>
- <td colspan=2>{{dat_line.comment}} </td>
+ {% if dat_line.is_intro %}
+ <td class="date {% if dat_line.error %} invalid{% endif %}" colspan=2>
+ <a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking.date}}</a>
+ </td>
+ <td{% if dat_line.error %} class="invalid"{% endif %}>{{dat_line.booking.target}}</td>
+ <td>{{dat_line.comment}}</td>
+ {% elif dat_line.error %}
+ <td class="invalid" colspan=3>{{dat_line.code}}</td>
+ <td>{{dat_line.comment}}</td>
+ {% elif dat_line.booking_line %}
+ <td class="amt">{{dat_line.booking_line.amount_short}}</td>
+ <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"…")}}</td>
+ <td>{{dat_line.booking_line.account}}</td>
+ <td>{{dat_line.comment}}</td>
+ {% else %}
+ <td colspan=2></td>
+ <td colspan=2>{{dat_line.comment}} </td>
+ {% endif %}
{% endif %}
- {% endif %}
- </tr>
-
- {% if (not raw) and dat_line.error %}
- <tr class="alternating warning">
- <td></td>
- <td class="invalid" colspan=3>{{dat_line.error}}</td>
- <td></td>
</tr>
- {% endif %}
+ {% if (not raw) and dat_line.error %}
+ <tr class="alternating warning">
+ <td></td>
+ <td class="invalid" colspan=3>{{dat_line.error}}</td>
+ <td></td>
+ </tr>
+ {% endif %}
+
+ {% endif %}
{% endfor %}
</table>
</form>