Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. session list cleanups #593

Merged
merged 6 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions docassemble/AssemblyLine/data/questions/interview_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ default screen parts:
---
mandatory: True
code: |
if not user_logged_in():
command("signin")
if get_config("assembly line",{}).get("enable answer sets"):
nav.unhide()
else:
nav.hide()
section_in_progress_forms
---
code: |
al_sessions_to_exclude_from_interview_list = get_config("assembly line", {}).get("exclude from interview list")
---
sections:
- section_in_progress_forms: In progress forms
- section_answer_sets: Answer sets
Expand All @@ -103,22 +108,22 @@ question: |
% endif
<span style="float: right;">${ action_button_html(get_config("assembly line",{}).get("new form url", AL_ORGANIZATION_HOMEPAGE), label="Start a new form", icon="plus-circle", color="primary", size="md") }</span>
subquestion: |
% if len(get_saved_interview_list(filename=None, filename_to_exclude=al_session_store_default_filename)) > 0:
% if len(get_saved_interview_list(filename=None, filename_to_exclude=al_session_store_default_filename, exclude_filenames=al_sessions_to_exclude_from_interview_list)) > 0:
% if get_config("interview page pre"):
${ get_config("interview page pre") }
% else:
Tap the title of a form to keep working on it or to download your completed
documents.
% endif

${ session_list_html(filename=None, limit=20, offset=session_page*20) }
${ session_list_html(filename=None, limit=20, offset=session_page*20, exclude_filenames=al_sessions_to_exclude_from_interview_list) }

<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
% if session_page > 0:
<li class="page-item"><a class="page-link" href="${ url_action("update_page_event", page_increment=-1) }">Previous</a></li>
% endif
% if len(get_saved_interview_list(filename=None, filename_to_exclude=al_session_store_default_filename, limit=20, offset=session_page*20)) >= 20:
% if len(get_saved_interview_list(filename=None, filename_to_exclude=al_session_store_default_filename, exclude_filenames=al_sessions_to_exclude_from_interview_list, limit=20, offset=session_page*20)) >= 20:
<li class="page-item"><a class="page-link" href="${ url_action("update_page_event", page_increment=1) }">Next</a></li>
% endif
</ul>
Expand All @@ -129,7 +134,7 @@ subquestion: |
# TODO: might be able to save some DB queries here but performance is good
section: section_in_progress_forms
under: |
% if len(get_saved_interview_list(filename=None, filename_to_exclude=al_session_store_default_filename)) > 0:
% if len(get_saved_interview_list(filename=None, filename_to_exclude=al_session_store_default_filename, exclude_filenames=al_sessions_to_exclude_from_interview_list)) > 0:
<div style="float: right;">
${ action_button_html(url_action("interview_list_delete_all"), label="Delete All", size="md", color="danger", icon="trash-can", id_tag="al-delete-all-sessions") }
</div>
Expand Down Expand Up @@ -210,16 +215,14 @@ fields:
continue button label: |
:save: Save changes
---
code: |
rename_interview_answers(user_info().filename, user_info().session, new_name = al_sessions_snapshot_new_label)
log("New name saved", "success")
al_sessions_rename_session = True
---
only sets:
- interview_list_rename_action
code: |
al_sessions_snapshot_new_label
try:
rename_interview_answers(action_argument("filename"), action_argument("session"), new_name = al_sessions_snapshot_new_label)
log(f"New name saved", "success")
session_page = 0 # Take back to first page where the renamed session will appear
except:
log("Problem saving new name", "danger")
interview_list_rename_action = True
Expand Down
43 changes: 31 additions & 12 deletions docassemble/AssemblyLine/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def get_saved_interview_list(
offset: int = 0,
filename_to_exclude: str = "",
exclude_current_filename: bool = True,
exclude_filenames: List[str] = None,
exclude_newly_started_sessions: bool = True,
) -> List[Dict]:
"""Get a list of saved sessions for the specified filename. If the save_interview_answers function was used
to add metadata, the result list will include columns containing the metadata.
Expand Down Expand Up @@ -305,8 +307,8 @@ def get_saved_interview_list(

AND
(userdict.filename = :filename OR :filename is null)
AND userdict.filename != :filename_to_exclude
AND userdict.filename != :current_filename
AND (userdict.filename NOT IN :filenames_to_exclude)
AND (NOT :exclude_newly_started_sessions OR num_keys > 1)
ORDER BY modtime desc
LIMIT :limit
OFFSET :offset;
Expand All @@ -324,6 +326,11 @@ def get_saved_interview_list(
current_filename = ""
if not filename_to_exclude:
filename_to_exclude = ""
if exclude_filenames:
filenames_to_exclude = exclude_filenames
else:
filenames_to_exclude = []
filenames_to_exclude.extend([current_filename, filename_to_exclude])
if user_id is None:
if user_logged_in():
user_id = user_info().id
Expand Down Expand Up @@ -351,8 +358,8 @@ def get_saved_interview_list(
filename=filename,
limit=limit,
offset=offset,
filename_to_exclude=filename_to_exclude,
current_filename=current_filename,
filenames_to_exclude=tuple(filenames_to_exclude),
exclude_newly_started_sessions=exclude_newly_started_sessions,
)
sessions = []
for session in rs:
Expand Down Expand Up @@ -588,6 +595,8 @@ def session_list_html(
metadata_key_name: str = "metadata",
filename_to_exclude: str = al_session_store_default_filename,
exclude_current_filename: bool = True,
exclude_filenames: List[str] = None,
exclude_newly_started_sessions: bool = True,
name_label: str = word("Title"),
date_label: str = word("Date modified"),
details_label: str = word("Progress"),
Expand All @@ -598,6 +607,7 @@ def session_list_html(
delete_action: str = "interview_list_delete_session",
copy_action: str = "interview_list_copy_action",
clone_label: str = word("Copy as answer set"),
show_title: bool = True,
limit: int = 50,
offset: int = 0,
) -> str:
Expand All @@ -616,6 +626,8 @@ def session_list_html(
offset=offset,
filename_to_exclude=filename_to_exclude,
exclude_current_filename=exclude_current_filename,
exclude_filenames=exclude_filenames,
exclude_newly_started_sessions=exclude_newly_started_sessions,
)

if not answers:
Expand Down Expand Up @@ -648,7 +660,7 @@ def session_list_html(
"arguments": {
"session": answer.get("key"),
"filename": answer.get("filename"),
"title": answer.get("title") or "",
"title": nice_interview_subtitle(answer),
},
},
]
Expand Down Expand Up @@ -680,13 +692,20 @@ def session_list_html(
)

table += """<tr class="al-saved-answer-table-row">"""
table += f"""
<td class="text-break">
<a class="al-session-form-title" href="{ interview_url(i=answer.get("filename"), session=answer.get("key")) }">{ nice_interview_title(answer) }</a>
{"<br/>" if nice_interview_subtitle(answer) else ""}
<span class="al-session-form-subtitle">{ nice_interview_subtitle(answer) if nice_interview_subtitle(answer) else "" }</span>
</td>
"""
if show_title:
table += f"""
<td class="text-break">
<a class="al-session-form-title" href="{ interview_url(i=answer.get("filename"), session=answer.get("key")) }">{ nice_interview_title(answer) }</a>
{"<br/>" if nice_interview_subtitle(answer) else ""}
<span class="al-session-form-subtitle">{ nice_interview_subtitle(answer) if nice_interview_subtitle(answer) else "" }</span>
</td>
"""
else:
table += f"""
<td class="text-break">
<a class="al-session-form-title" href="{ interview_url(i=answer.get("filename"), session=answer.get("key")) }">{ nice_interview_subtitle(answer) or nice_interview_title(answer) }</a>
</td>
"""
table += f"""
<td>
<span class="al-session-date-modified">{ local_date(answer.get("modtime")) }</span> <br/>
Expand Down