include archived
This commit is contained in:
39
app.py
39
app.py
@@ -29,22 +29,27 @@ def login_required(view):
|
||||
return view(*args, **kwargs)
|
||||
return wrapped
|
||||
|
||||
def projects_for(profile, case_email_match, per_page, offset):
|
||||
def projects_for(profile, case_email_match, per_page, offset, include_archived=False):
|
||||
"""
|
||||
Filter projects based on user profile and case_email query string argument.
|
||||
|
||||
|
||||
Args:
|
||||
profile (dict): User profile containing 'enabled', 'is_admin', 'case_email', and 'case_domain_email' fields
|
||||
case_email_match (str): Case email from query string argument, or None
|
||||
|
||||
include_archived (bool): When False (default), archived projects are excluded
|
||||
|
||||
Returns:
|
||||
list: List of project dictionaries that match the filtering criteria
|
||||
"""
|
||||
is_admin = profile.get("is_admin", False)
|
||||
|
||||
|
||||
if not profile.get("enabled"):
|
||||
return ([], 0)
|
||||
|
||||
|
||||
def not_archived(ref):
|
||||
"""Exclude archived projects unless include_archived is set."""
|
||||
return ref if include_archived else ref.where("is_archived", "==", False)
|
||||
|
||||
# Query Firestore for projects where case_email is in viewing_emails array
|
||||
try:
|
||||
cnt = 0
|
||||
@@ -55,7 +60,7 @@ def projects_for(profile, case_email_match, per_page, offset):
|
||||
# Check if case_email_match is a valid email address (contains @)
|
||||
if '@' in case_email_match_lower and not case_email_match_lower.startswith('@'):
|
||||
# If it's a complete email address, filter by exact match in viewing_emails
|
||||
projects_ref = db.collection("projects").where("viewing_emails", "array_contains", case_email_match_lower).where("is_archived", "==", False)
|
||||
projects_ref = not_archived(db.collection("projects").where("viewing_emails", "array_contains", case_email_match_lower))
|
||||
cnt = int(projects_ref.count().get()[0][0].value)
|
||||
projects = []
|
||||
for doc in projects_ref.order_by("matter_description").limit(per_page).offset(offset).stream():
|
||||
@@ -69,7 +74,7 @@ def projects_for(profile, case_email_match, per_page, offset):
|
||||
domain_search = domain_search[1:] # Remove the @ sign
|
||||
|
||||
# Filter by domain match in viewing_emails
|
||||
projects_ref = db.collection("projects").where("viewing_domains", "array_contains", domain_search).where("is_archived", "==", False)
|
||||
projects_ref = not_archived(db.collection("projects").where("viewing_domains", "array_contains", domain_search))
|
||||
print("HERE domain", domain_search)
|
||||
cnt = int(projects_ref.count().get()[0][0].value)
|
||||
|
||||
@@ -78,10 +83,10 @@ def projects_for(profile, case_email_match, per_page, offset):
|
||||
projects.append(doc.to_dict())
|
||||
return (projects, cnt)
|
||||
|
||||
else:
|
||||
projects_ref = db.collection("projects").where("is_archived", "==", False)
|
||||
else:
|
||||
projects_ref = not_archived(db.collection("projects"))
|
||||
|
||||
else:
|
||||
else:
|
||||
# For non-admin users, check if they have domain email or specific case email
|
||||
case_domain_email = profile.get("case_domain_email", "")
|
||||
case_email = profile.get("case_email", "")
|
||||
@@ -89,10 +94,10 @@ def projects_for(profile, case_email_match, per_page, offset):
|
||||
if case_domain_email:
|
||||
# Use exact match on viewing_domains field
|
||||
domain_lower = case_domain_email.lower()
|
||||
projects_ref = db.collection("projects").where("viewing_domains", "array_contains", domain_lower).where("is_archived", "==", False)
|
||||
projects_ref = not_archived(db.collection("projects").where("viewing_domains", "array_contains", domain_lower))
|
||||
elif case_email:
|
||||
# Use the original logic for specific case email match
|
||||
projects_ref = db.collection("projects").where("viewing_emails", "array_contains", case_email.lower()).where("is_archived", "==", False)
|
||||
projects_ref = not_archived(db.collection("projects").where("viewing_emails", "array_contains", case_email.lower()))
|
||||
else:
|
||||
return ([], 0)
|
||||
|
||||
@@ -288,7 +293,8 @@ def dashboard(page=1):
|
||||
case_email_match = request.args.get('case_email')
|
||||
if not is_admin and (not profile.get('case_email') and not profile.get('case_domain_email')):
|
||||
return redirect(url_for("welcome"))
|
||||
paginated_rows, total_projects = projects_for(profile, case_email_match, per_page, offset)
|
||||
include_archived = request.args.get('include_archived') == '1'
|
||||
paginated_rows, total_projects = projects_for(profile, case_email_match, per_page, offset, include_archived)
|
||||
|
||||
# Calculate pagination
|
||||
total_pages = (total_projects + per_page - 1) // per_page # Ceiling division
|
||||
@@ -304,6 +310,7 @@ def dashboard(page=1):
|
||||
total_pages=total_pages,
|
||||
total_projects=total_projects,
|
||||
per_page=per_page,
|
||||
include_archived=include_archived,
|
||||
is_admin=is_admin)
|
||||
|
||||
|
||||
@@ -323,9 +330,13 @@ def dashboard_export_xls():
|
||||
if not is_admin and (not profile.get('case_email') and not profile.get('case_domain_email')):
|
||||
return redirect(url_for("welcome"))
|
||||
|
||||
if is_admin and request.args.get('case_email'):
|
||||
case_email = request.args.get('case_email')
|
||||
include_archived = request.args.get('include_archived') == '1'
|
||||
|
||||
# Get all projects without pagination
|
||||
try:
|
||||
all_rows, cnt = projects_for(profile, case_email, 10000, 0)
|
||||
all_rows, cnt = projects_for(profile, case_email, 10000, 0, include_archived)
|
||||
# Filter projects where case_email is in viewing_emails array
|
||||
# Order by matter_description to maintain consistent ordering
|
||||
print(f"Retrieved {cnt} projects from Firestore for XLS export")
|
||||
|
||||
Reference in New Issue
Block a user