Skip to content

Commit

Permalink
#244 filter for email moved to query_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
yn-coder committed Oct 30, 2020
1 parent d1f6e30 commit b05df7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ich_bau/templatetags/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

@register.simple_tag(name='site_version_info')
def site_version_info():
return 'v0.0038 at 23.10.2020'
return 'v0.0039 at 30.10.2020'
87 changes: 42 additions & 45 deletions project/management/commands/do_schedule_letters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,48 @@ def handle(self, *args, **options):
print( "No EMAIL_HOST_USER, can't send mails" )
return

# select active users, whom have a managed associations
# select active users, if users have a mail's, whom have a managed associations
users = User.objects.annotate( c_manager = Count('manager_user'), c_managed = Count('profile__managed_profile') )
users = users.filter(is_active = True ).filter( Q(c_manager__gt = 0 ) | Q( c_managed__gt = 0 ) )
users = users.filter(is_active = True, email__isnull = False ).filter( Q(c_manager__gt = 0 ) | Q( c_managed__gt = 0 ) )

for u in users:
# if users have a mail's
if u.email:

schedule = None
scheduled_task_empty = True
tasks = None

unaccepted_projects = Get_UnAccepted( u )

notifications_count = GetUserNoticationsQ(u, True).count()

# if user has the work schedule item - use it
schedules = Get_Profile_ScheduleItem_This_Week( Get_Profile_ScheduleItem( u.profile ) )
if schedules.exists():
schedule = schedules.first()
tasks = Task.objects.filter( scheduledtask__schedule_item = schedule )
scheduled_task_empty = ( tasks.count() == 0 )

if scheduled_task_empty:
tasks = Get_User_Tasks( u )

context_dict = { 'user' : u,
'current_domain' : get_full_site_url(),
'unaccepted_projects' : unaccepted_projects,
'schedule' : schedule,
'scheduled_task_empty' : scheduled_task_empty,
'tasks' : tasks,
'notifications_count' : notifications_count,
}

html_message_text = render_to_string( 'project/email_tasks_digest.txt', context_dict )

try:
send_mail( 'Tasks',
html_message_text,
settings.EMAIL_HOST_USER,
[u.email],
fail_silently=False,
html_message=html_message_text
)
print( u.email )
except:
print( 'Fail to send email' )
schedule = None
scheduled_task_empty = True
tasks = None

unaccepted_projects = Get_UnAccepted( u )

notifications_count = GetUserNoticationsQ(u, True).count()

# if user has the work schedule item - use it
schedules = Get_Profile_ScheduleItem_This_Week( Get_Profile_ScheduleItem( u.profile ) )
if schedules.exists():
schedule = schedules.first()
tasks = Task.objects.filter( scheduledtask__schedule_item = schedule )
scheduled_task_empty = ( tasks.count() == 0 )

if scheduled_task_empty:
tasks = Get_User_Tasks( u )

context_dict = { 'user' : u,
'current_domain' : get_full_site_url(),
'unaccepted_projects' : unaccepted_projects,
'schedule' : schedule,
'scheduled_task_empty' : scheduled_task_empty,
'tasks' : tasks,
'notifications_count' : notifications_count,
}

html_message_text = render_to_string( 'project/email_tasks_digest.txt', context_dict )

try:
send_mail( 'Tasks',
html_message_text,
settings.EMAIL_HOST_USER,
[u.email],
fail_silently=False,
html_message=html_message_text
)
print( u.email )
except:
print( 'Fail to send email' )

0 comments on commit b05df7b

Please sign in to comment.