示例#1
0
 def handle(self, *args, **options):
     notice_setting = NoticeType.objects.get(label="calendars_weekly_summary")
     for user in User.objects.filter(is_active=True):
         if should_send(user, notice_setting, "1"):
             content_type = ContentType.objects.get_for_model(Calendar)
             events = Event.objects.filter(
                 start_time__gte=get_today(),
                 start_time__lte=get_next_week(),
                 content_type=content_type,
                 object_id__in=user.calendars.all().values_list("id", flat=True),
             ).order_by("start_time")
             if events:
                 subject = "Weekly events"
                 context = {"user": user, "events": events}
                 message = render_to_string("events/events_weekly_notice.html", context)
                 send_mail(subject, message, None, [user.email])
示例#2
0
def show_events(context, events, user=None):
    request = context.get("request")
    if user:
        return {
            "events": events,
            "interested_in_events": (
                events.filter(start_time__gte=get_today()) |
                events.filter(start_time__lt=get_today(),end_time__gte=get_today())
            ).filter(votes__user=user).order_by('start_time'),
            "past_events": (
                events.filter(start_time__lte=get_today(), end_time__lte=get_today()) |
                events.filter(start_time__lte=get_today(), end_time=None)
            ).order_by('-start_time'),
            "coming_events": (
                events.filter(start_time__gte=get_today()) |
                events.filter(start_time__lt=get_today(),end_time__gte=get_today())
            ).exclude(votes__user=user).order_by('start_time'),
            "attending_events": (
                events.filter(start_time__gte=get_today()) |
                events.filter(start_time__lt=get_today(),end_time__gte=get_today())
            ).filter(attendance__user=user, attendance__status='attending').order_by('start_time'),
            "request": request,
        }
    else:
        if request.user.is_anonymous():
            return {
                "events": events,
                "interested_in_events": None,
                "past_events": (
                    events.filter(start_time__lte=get_today(), end_time__lte=get_today()) |
                    events.filter(start_time__lte=get_today(), end_time=None)
                ).order_by('-start_time'),
                "coming_events": (
                    events.filter(start_time__gte=get_today()) |
                    events.filter(start_time__lt=get_today(),end_time__gte=get_today())
                ).order_by('start_time'),
                "attending_events": None,
                "request": request,
            }
        else:
            return {
                "events": events,
                "interested_in_events": (
                    events.filter(start_time__gte=get_today()) |
                    events.filter(start_time__lt=get_today(),end_time__gte=get_today())
                ).filter(votes__user=request.user).order_by('start_time'),
                "past_events": (
                    events.filter(start_time__lte=get_today(), end_time__lte=get_today()) |
                    events.filter(start_time__lte=get_today(), end_time=None)
                ).order_by('-start_time'),
                "coming_events": (
                    events.filter(start_time__gte=get_today()) |
                    events.filter(start_time__lt=get_today(),end_time__gte=get_today())
                ).exclude(votes__user=request.user).order_by('start_time'),
                "attending_events": (
                    events.filter(start_time__gte=get_today()) |
                    events.filter(start_time__lt=get_today(),end_time__gte=get_today())
                ).filter(attendance__user=request.user, attendance__status='attending').order_by('start_time'),
                "request": request,
            }