def post(self, request, format=None): employee = EmployeeProfile.objects.filter( id=request.data['profile_id'] ).first() if not employee: return Response('No employee profile found', status=status.HTTP_400_BAD_REQUEST) from_email = '*****@*****.**' subject = 'Welcome to Roster Barn. New account signup.' if request.data.get('development'): signup_link = 'http://0.0.0.0:5000/employee/{}'.format(employee.id) else: # Change this when front end is up. signup_link = 'http://0.0.0.0:5000/employee/{}'.format(employee.id) body = "A profile has been created for you, please use the" \ " following link to sign up. \n {}".format(signup_link) try: send_text_email(from_email, request.data['email'], subject, body) employee.was_invited = True employee.save() return Response('email sent successfully', status=status.HTTP_200_OK) except: return Response('email error', status=status.HTTP_503_SERVICE_UNAVAILABLE)
def email_notify_employees(data): employee_ids = set([x.employee.id for x in data]) from_email = '*****@*****.**' subject = 'You have new shifts posted' for person in EmployeeProfile.objects.filter(id__in=employee_ids, email_notifications=True ).all(): message = '' matches = [x for x in data if x.employee.id == person.id] for match in matches: date = WorkDay.objects.get(id=match.day.id).day_date time = match.starting_time message += "{} at {}\n".format( print_date(date), print_time(time) ) send_text_email(from_email, person.email, subject, message)
def post(self, request, format=None): subject = request.data['subject'] body = request.data['body'] from_email = '*****@*****.**' employees = EmployeeProfile.objects.filter( department=request.data['department'] ) try: counter = 0 for employee in employees: if employee.email: counter += 1 send_text_email(from_email, employee.email, subject, body) return Response('{} emails sent'.format(counter), status=status.HTTP_200_OK) except: return Response('email error', status=status.HTTP_503_SERVICE_UNAVAILABLE)
def post(self, request, format=None): working_date = date_string_to_datetime(request.data['date'], request.data['time']) one_day = datetime.timedelta(days=1) after = working_date + one_day before = working_date - one_day qs = Shift.objects.filter(day__day_date__gte=before, day__day_date__lte=after) qs = qs.exclude(day__day_date=after, starting_time__gte=working_date.time()) qs = qs.exclude(day__day_date=before, starting_time__lte=working_date.time()) employees = qs.values('employee').distinct() employee_ids = [x['employee'] for x in employees] available_employees = EmployeeProfile.objects.filter(department=request.data['department']) available_employees = available_employees.exclude(id__in=employee_ids) try: counter = 0 subject = 'Shift available' body = 'There is a new shift available on {} at {}. If you' \ ' would like to work please contact your manager.'.format( request.data['date'], request.data['time']) from_email = '*****@*****.**' for employee in available_employees: if employee.email: counter += 1 send_text_email(from_email, employee.email, subject, body) recipient_names = [(x.first_name, x.last_name) for x in available_employees] return Response({'emails sent': counter, 'employees notified': recipient_names}, status=status.HTTP_200_OK) except: return Response('email failed', status=status.HTTP_503_SERVICE_UNAVAILABLE)