tasks for specific sub categories
This commit is contained in:
41
app.py
41
app.py
@@ -49,16 +49,39 @@ def index():
|
||||
current_entry['activity_name'] = active_activity['name']
|
||||
current_entry['activity_color'] = active_activity.get('color', '#3498db')
|
||||
|
||||
# 1. Tasks generated specifically for this session (time_entry_id linked)
|
||||
# 2. Open tasks linked to this activity type (contextual todos)
|
||||
active_tasks = list(db.tasks.find({
|
||||
# Logic for fetching tasks:
|
||||
# 1. Fetch Session Specific Tasks (linked via time_entry_id)
|
||||
session_tasks = list(db.tasks.find({
|
||||
'user_id': user_id,
|
||||
'status': 'open',
|
||||
'$or': [
|
||||
{'time_entry_id': current_entry['_id']},
|
||||
{'activity_id': current_entry['activity_id'], 'is_template': False, 'time_entry_id': None}
|
||||
]
|
||||
'time_entry_id': current_entry['_id']
|
||||
}))
|
||||
|
||||
# 2. Fetch Contextual Tasks (linked via activity_id, no time_entry_id)
|
||||
context_criteria = {
|
||||
'user_id': user_id,
|
||||
'status': 'open',
|
||||
'activity_id': current_entry['activity_id'],
|
||||
'is_template': False,
|
||||
'time_entry_id': None
|
||||
}
|
||||
|
||||
current_subcat = current_entry.get('subcategory')
|
||||
|
||||
if current_subcat:
|
||||
# If active entry has subcategory: Show tasks matching that subcategory OR general tasks (no subcategory)
|
||||
context_criteria['$or'] = [
|
||||
{'subcategory': current_subcat},
|
||||
{'subcategory': {'$in': [None, '']}}
|
||||
]
|
||||
else:
|
||||
# If active entry has NO subcategory: Show only General tasks (no subcategory assigned)
|
||||
# This hides specific subcategory tasks when just tracking the general activity
|
||||
context_criteria['subcategory'] = {'$in': [None, '']}
|
||||
|
||||
context_tasks = list(db.tasks.find(context_criteria))
|
||||
|
||||
active_tasks = session_tasks + context_tasks
|
||||
|
||||
return render_template('dashboard.html',
|
||||
activities=activities,
|
||||
@@ -361,6 +384,7 @@ def create_task():
|
||||
|
||||
name = request.form['name']
|
||||
activity_id = request.form.get('activity_id')
|
||||
subcategory = request.form.get('subcategory', '') # Get subcategory
|
||||
due_date_str = request.form.get('due_date')
|
||||
is_template = 'is_template' in request.form
|
||||
|
||||
@@ -371,7 +395,8 @@ def create_task():
|
||||
'is_template': is_template,
|
||||
'source': 'manual', # Mark as manually created
|
||||
'created_at': datetime.now(),
|
||||
'comments': []
|
||||
'comments': [],
|
||||
'subcategory': subcategory # Save subcategory
|
||||
}
|
||||
|
||||
if activity_id:
|
||||
|
||||
Reference in New Issue
Block a user