def get_events_users_inbetween(calendar, since, until): delta = until - since result = {} for i in range(delta.days + 1): that_day = since + timedelta(days=i) that_day = timezone.make_aware(that_day, timezone.get_current_timezone()) day = Day(calendar.events.all(), that_day) for o in day.get_occurrences(): if o.start <= that_day <= o.end: items = o.event.title.split(',') for item in items: username = item if Group.objects.filter(name=item.strip()) is not None: for user in User.objects.filter(groups__name=item): if user not in result.keys(): result.append(user) else: result[username]["end"] = o.end else: if item not in result.keys(): user_instance = User.objects.get(username=item.strip()) result[username] = {"start": o.start, "person": username.strip(), "end": o.end, "email": user_instance.email} else: result[username]["end"] = o.end return result.values()
def monthly_schedule(request, year, month): if int(year) > 2037 or int(year) < 1970 or int(month) < 1 or int(month) > 12: raise Http404 MonthlyScheduleFormset = formset_factory(wraps(MonthlyScheduleForm)(partial(MonthlyScheduleForm, days=monthrange(int(year), int(month))[1])), extra=0) initial_data = [] for barber in Barber.objects.all(): data = {} calendar = Calendar.objects.get_or_create(name='barber_schedule')[0] month_period = Month(calendar.events.get_for_object(barber), datetime(int(year), int(month), 1)) for day_period in month_period.get_days(): if day_period.has_occurrences(): data['day_{}'.format(day_period.start.day)] = True initial_data.append(data) if request.method == 'POST': formset = MonthlyScheduleFormset(request.POST, initial=initial_data) if formset.is_valid(): for form, barber in zip(formset, Barber.objects.all()): for day in form.changed_data: if not form.cleaned_data[day]: calendar = Calendar.objects.get(name='barber_schedule') events = calendar.events.get_for_object(barber) period = Day(events, datetime(int(year), int(month), int(day[4:]))) if period.has_occurrences(): for occurrence in period.get_occurrences(): Event.objects.get(id=occurrence.event_id).delete() else: calendar = Calendar.objects.get_or_create(name='barber_schedule')[0] event = Event( start=make_aware(datetime(int(year), int(month), int(day[4:]), settings.DAY_START)), end=make_aware(datetime(int(year), int(month), int(day[4:]), settings.DAY_END)) ) event.save() calendar.events.add(event) relation = EventRelation.objects.create_relation(event, barber) relation.save() else: formset = MonthlyScheduleFormset(initial=initial_data) context = dict( admin.site.each_context(request), days=range(1, monthrange(int(year), int(month))[1] + 1), first_weekday=monthrange(int(year), int(month))[0], barbers=zip(Barber.objects.all(), formset), formset=formset, prev_date=(datetime(int(year), int(month), 1) - timedelta(days=1)), current_date=datetime.now(), next_date=(datetime(int(year), int(month), monthrange(int(year), int(month))[1]) + timedelta(days=1)), ) if request.method == 'POST': return redirect(reverse('admin:monthly_schedule', kwargs={'year': year, 'month': month}), context) else: return render(request, 'admin/monthly_schedule.html', context)
def get_current_events_users(calendar): now = timezone.make_aware(datetime.now(), timezone.get_current_timezone()) result = [] day = Day(calendar.events.all(), now) for o in day.get_occurrences(): if o.start <= now <= o.end: usernames = o.event.title.split(',') for username in usernames: result.append(User.objects.get(username=username.strip())) return result
def get_current_events_users(calendar): now = timezone.make_aware(datetime.now(), timezone.get_current_timezone()) result = [] day = Day(calendar.events.all(), now) for o in day.get_occurrences(): if o.start <= now <= o.end: usernames = o.event.title.split(',') for username in usernames: result.append(User.objects.get(username=username.strip())) return result
def actions(request): actions = models.Action.objects.order_by('-created_on') period = Day(actions, now()) # XXX: Hack for don't get tomorow occs occs = [occ for occ in period.get_occurrences() if occ.start.date() == now().date()] return render(request, 'bio/actions.html', { 'meta': actions.model._meta, 'objects': occs, 'calendar': Calendar.objects.get(name='Bio') })
def get_current_events_users(calendar): now = timezone.now() result = [] day = Day(calendar.events.all(), now) for o in day.get_occurrences(): if o.start <= now <= o.end: items = o.event.title.split(',') for item in items: if Group.objects.filter(name=item.strip()).exists(): for user in User.objects.filter(groups__name=item.strip()): user.came_from_group = item.strip() result.append(user) else: result.append(User.objects.get(username=item.strip())) return result
def get_data(self): period = Day(Event.objects.exclude(appointment=None).filter( appointment__customer=self.customer), self.date) data = [{'id': x.event.appointment_set.first().pk, 'title': "{}".format(x.event.appointment_set.first().display_name), 'userId': [x.event.appointment_set.first().venue.pk], 'start': x.start.isoformat(), 'end': x.end.isoformat(), 'clientId': x.event.appointment_set.first().clientId, 'status': x.event.appointment_set.first().status, 'tag': getattr(x.event.appointment_set.first().tag, 'html_name', ""), 'body': x.event.description } for x in period.get_occurrences()] return data
def get_events_users_inbetween(calendar, since, until): delta = until - since result = {} for i in range(delta.days + 1): that_day = since + timedelta(days=i) that_day = timezone.make_aware(that_day, timezone.get_current_timezone()) day = Day(calendar.events.all(), that_day) for o in day.get_occurrences(): if o.start <= that_day <= o.end: usernames = o.event.title.split(',') for username in usernames: if username not in result.keys(): user_instance = User.objects.get(username=username.strip()) result[username] = {"start": o.start, "person": username.strip(), "end": o.end, "email": user_instance.email} else: result[username]["end"] = o.end return result.values()
def get_events_users_inbetween(calendar, since, until): delta = until - since result = {} for i in range(delta.days + 1): that_day = since + timedelta(days=i) that_day = timezone.make_aware(that_day, timezone.get_current_timezone()) day = Day(calendar.events.all(), that_day) for o in day.get_occurrences(): if o.start <= that_day <= o.end: usernames = o.event.title.split(',') for username in usernames: if username not in result.keys(): user_instance = User.objects.get( username=username.strip()) result[username] = { "start": o.start, "person": username.strip(), "end": o.end, "email": user_instance.email } else: result[username]["end"] = o.end return result.values()