Example #1
0
def announceGlean(request, glean_id):
    glean = get_object_or_404(GleanEvent, pk=glean_id)
    profile = request.user.profile
    if (not request.user.has_perm('announce.uniauth') and
            profile.member_organization != glean.member_organization):
        return HttpResponseRedirect(
            reverse('gleanevent:detailglean', args=(glean_id,)))
    if not glean.happened():
        empty_announcements = Announcement.objects.filter(
            title='', message='', sent=False)
        for ann in empty_announcements:
            if not ann.active():
                ann.delete()
        query = Template.objects.filter(
            member_organization=profile.member_organization, default=True)
        if query.exists():
            def_template = query.get()
            new_save = Announcement(
                title=glean.title,
                message='',
                glean=glean,
                member_organization=profile.member_organization,
                template=def_template)
            new_save.save()
            new_save.populate_recipients()
            return HttpResponseRedirect(
                reverse('announce:combinedannounce', args=(new_save.id,)))
        else:
            return HttpResponse(
                'no default template selected! You need a template'
                ' to announce a glean!')
    else:
        return HttpResponseRedirect(
            reverse('gleanevent:detailglean', args=(glean_id,))
        )
Example #2
0
def create_announcement(**kwargs):
    if 'glean' in kwargs and 'member_organization' in kwargs:
        announce = Announcement(**kwargs)
    elif 'glean' in kwargs:
        memorg = create_memorg()
        announce = Announcement(member_organization=memorg, **kwargs)
    elif 'member_organization' in kwargs:
        glean = create_glean()
        announce = Announcement(glean=glean, **kwargs)
    else:
        glean = create_glean()
        memorg = create_memorg()
        announce = Announcement(
            glean=glean, member_organization=memorg, **kwargs)
    announce.save()
    return announce