コード例 #1
0
ファイル: models.py プロジェクト: Dpetters/Umeqo
def notify_about_event(instance, notice_type, employers):
    subscribers = Student.objects.filter(subscriptions__in=employers)
    to_users = list(set(map(lambda n: n.user, subscribers)))
    if not instance.is_public:
        to_users = filter(lambda u: Invitee.objects.filter(student = u.student, event=instance).exists(), to_users)
    # Batch the sending by unique groups of subscriptions.
    # This way someone subscribed to A, B, and C gets only one email.
    subscribers_by_user = {}
    employername_table = {}
    for employer in employers:
        employername_table[str(employer.id)] = employer.name
        for to_user in to_users:
            if to_user.student in employer.subscribers.all():
                if to_user.id in subscribers_by_user:
                    subscribers_by_user[to_user.id].append(employer.id)
                else:
                    subscribers_by_user[to_user.id] = [employer.id]
    subscription_batches = {}
    for userid,employerids in subscribers_by_user.items():
        key = ':'.join(map(lambda n: str(n), employerids))
        subscription_batches[key] = userid
    for key,userids in subscription_batches.items():
        employer_names = map(lambda n: employername_table[n], key.split(':'))
        has_word = "has" if len(employer_names)==1 else "have"
        employer_names = english_join(employer_names)
        for to_user in to_users:
            notification.send([to_user], notice_type, {
                'name': to_user.first_name,
                'employer_names': employer_names,
                'has_word': has_word,
                'event': instance,
            })
コード例 #2
0
def notify_about_event(instance, notice_type, employers):
    subscribers = Student.objects.filter(subscriptions__in=employers)
    to_users = list(set(map(lambda n: n.user, subscribers)))
    if not instance.is_public:
        to_users = filter(
            lambda u: Invitee.objects.filter(student=u.student, event=instance)
            .exists(), to_users)
    # Batch the sending by unique groups of subscriptions.
    # This way someone subscribed to A, B, and C gets only one email.
    subscribers_by_user = {}
    employername_table = {}
    for employer in employers:
        employername_table[str(employer.id)] = employer.name
        for to_user in to_users:
            if to_user.student in employer.subscribers.all():
                if to_user.id in subscribers_by_user:
                    subscribers_by_user[to_user.id].append(employer.id)
                else:
                    subscribers_by_user[to_user.id] = [employer.id]
    subscription_batches = {}
    for userid, employerids in subscribers_by_user.items():
        key = ':'.join(map(lambda n: str(n), employerids))
        subscription_batches[key] = userid
    for key, userids in subscription_batches.items():
        employer_names = map(lambda n: employername_table[n], key.split(':'))
        has_word = "has" if len(employer_names) == 1 else "have"
        employer_names = english_join(employer_names)
        for to_user in to_users:
            notification.send(
                [to_user], notice_type, {
                    'name': to_user.first_name,
                    'employer_names': employer_names,
                    'has_word': has_word,
                    'event': instance,
                })
コード例 #3
0
ファイル: views.py プロジェクト: Dpetters/Umeqo
def event_cancel(request, id, extra_context=None):
    if request.method == "POST":
        try:
            event = Event.objects.get(id=id)
        except Event.DoesNotExist:
            raise Http404("Event with id '%s' does not exist." % id)
        else:
            if not admin_of_event(event, request.user):
                raise Http403('You are not allowed to delete this event.')
            event.cancelled = True

            # Notify RSVPS.
            rsvps = map(lambda n: n.student.user,
                        event.rsvp_set.filter(attending=True))
            employers = event.attending_employers.all()
            has_word = "has" if len(employers) == 1 else "have"
            employer_names = english_join(map(lambda n: n.name, employers))
            notification.send(
                rsvps, 'cancelled_event', {
                    'employer_names': employer_names,
                    'has_word': has_word,
                    'event': event
                })

            event.save()

            data = {}
            if event.is_deadline():
                data['type'] = "deadline"
            else:
                data['type'] = "event"
            return HttpResponse(simplejson.dumps(data),
                                mimetype="application/json")
    else:
        try:
            event = Event.objects.get(id=id)
        except Event.DoesNotExist:
            raise Http404("Event with id '%s' does not exist." % id)
        context = {'event': event}
        context.update(extra_context or {})
        return context
コード例 #4
0
ファイル: views.py プロジェクト: Dpetters/Umeqo
def event_cancel(request, id, extra_context = None):
    if request.method == "POST":
        try:
            event = Event.objects.get(id=id)
        except Event.DoesNotExist:
            raise Http404("Event with id '%s' does not exist." % id)
        else:
            if not admin_of_event(event, request.user):
                raise Http403('You are not allowed to delete this event.')
            event.cancelled = True

            # Notify RSVPS.
            rsvps = map(lambda n: n.student.user, event.rsvp_set.filter(attending=True))
            employers = event.attending_employers.all()
            has_word = "has" if len(employers)==1 else "have"
            employer_names = english_join(map(lambda n: n.name, employers))
            notification.send(rsvps, 'cancelled_event', {
                'employer_names': employer_names,
                'has_word': has_word,
                'event': event
            })
            
            event.save()
            
            data = {}
            if event.is_deadline():
                data['type'] = "deadline"
            else:
                data['type'] = "event"
            return HttpResponse(simplejson.dumps(data), mimetype="application/json")
    else:
        try:
            event = Event.objects.get(id=id)
        except Event.DoesNotExist:
            raise Http404("Event with id '%s' does not exist." % id)
        context = {'event':event}
        context.update(extra_context or {})
        return context