def process_shift_deletion(shift): active_applications = shift.applications.filter_active() for application in active_applications.all(): with localize_for_user(application.owner): async_send_mail('shift_deleted', application.owner.email, get_context(shift, application.owner))
def process_confirming(application, user, comment): process_state_changing(application, user, 'The application is confirmed', comment) with localize_for_user(application.shift.owner): async_send_mail('application_confirmed', application.shift.owner.email, get_context(application, comment))
def process_shift_creation(shift): suitable_residents = Resident.objects.filter_for_shift(shift) \ .filter(notification_new_shifts=True) for resident in suitable_residents: with localize_for_user(resident): async_send_mail('shift_created', resident.email, get_context(shift, resident))
def process_resident_profile_filling(resident): from apps.accounts.models import AccountManager with localize_for_user(resident): async_send_mail( 'resident_profile_filled', list(AccountManager.objects.values_list('email', flat=True)), get_context(resident))
def process_completing(application, user, comment): process_state_changing(application, user, 'The application is completed', comment) if application.owner.notification_application_status_changing: with localize_for_user(application.owner): async_send_mail('application_completed', application.owner.email, get_context(application, comment))
def process_postponing(application): process_state_changing( application, application.shift.owner, 'You application is postponed due to accepting an another application') if application.owner.notification_application_status_changing: with localize_for_user(application.owner): async_send_mail('application_postponed', application.owner.email, get_context(application))
def process_renewing(application): process_state_changing( application, application.shift.owner, 'The shift became available and your application is renewed') if application.owner.notification_application_status_changing: with localize_for_user(application.owner): async_send_mail('application_renewed', application.owner.email, get_context(application))
def process_rejecting(application, user, comment): process_state_changing( application, user, 'Your application is rejected. You may apply for other shifts ' 'at any time', comment) if application.owner.notification_application_status_changing: with localize_for_user(application.owner): async_send_mail('application_rejected', application.owner.email, get_context(application))
def process_approving(application, user, comment): process_state_changing( application, user, 'The application is approved. Please, confirm that you will ' 'work on the shift', comment) with localize_for_user(application.owner): if application.owner.notification_application_status_changing: async_send_mail('application_approved', application.owner.email, get_context(application, comment))
def process_shift_updating(shift): active_applications = shift.applications.filter_active() if active_applications.exists(): suitable_residents = [ application.owner for application in active_applications.all() ] is_applicant = True else: suitable_residents = Resident.objects.filter_for_shift(shift) \ .filter(notification_new_shifts=True) is_applicant = False for resident in suitable_residents: with localize_for_user(resident): async_send_mail( 'shift_updated', resident.email, get_context(shift, resident, is_applicant=is_applicant))
def process_cancelling(application, user, comment): process_state_changing(application, user, 'The application is cancelled', comment) destination = get_opposite_side(application, user) mail_notification_enabled = destination.is_scheduler or ( destination.is_resident and destination.notification_application_status_changing) if mail_notification_enabled: with localize_for_user(destination): async_send_mail( 'application_cancelled', destination.email, { 'source': get_user_context(user), 'destination': get_user_context(destination), 'comment': comment, 'application': get_application_context(application), 'shift': get_shift_context(application.shift), })
def process_message_creation(message, notify=True): from .application import get_application_context, get_opposite_side if notify: notify_message_created(message) destination = get_opposite_side(message.application, message.owner) mail_notification_enabled = destination.is_scheduler or ( destination.is_resident and destination.notification_new_messages) if mail_notification_enabled: with localize_for_user(destination): async_send_mail( 'message_created', destination.email, { 'source': get_user_context(message.owner), 'destination': get_user_context(destination), 'text': message.text, 'application': get_application_context( message.application), 'shift': get_shift_context(message.application.shift), })
def process_resident_rejecting(resident): with localize_for_user(resident): async_send_mail('resident_rejected', resident.email, get_context(resident))
def process_invitation(application, comment): create_message(application, application.shift.owner, comment) with localize_for_user(application.owner): async_send_mail('invitation_created', application.owner.email, get_context(application, comment))