コード例 #1
0
ファイル: views.py プロジェクト: aschuster3/gtphipsi
def edit_announcement(request, id):
    """Render and process a form to modify an existing announcement.

    Required parameters:
        - id    =>  the unique ID of the announcement to edit (as an integer)

    If 'delete=true' appears in the request's query string, the announcement will be deleted.

    """
    log_page_view(request, 'Edit Announcement')
    announcement = get_object_or_404(Announcement, id=id)
    profile = request.user.get_profile()
    if announcement.user != request.user and not profile.is_admin():
        return HttpResponseRedirect(reverse(
            'forbidden'))  # only admins may edit other people's announcements
    if request.method == 'POST':
        form = AnnouncementForm(request.POST, instance=announcement)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('announcements'))
    else:
        if 'delete' in request.GET and request.GET['delete'] == 'true':
            text = announcement.text
            announcement.delete()
            log.info('%s (%s) deleted announcement \'%s\'',
                     request.user.username, request.user.get_full_name(), text)
            return HttpResponseRedirect(reverse('announcements'))
        form = AnnouncementForm(instance=announcement)
    return render(request,
                  'chapter/edit_announcement.html', {
                      'form': form,
                      'id': announcement.id
                  },
                  context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: will2dye4/gtphipsi
def edit_announcement(request, id):
    """Render and process a form to modify an existing announcement.

    Required parameters:
        - id    =>  the unique ID of the announcement to edit (as an integer)

    If 'delete=true' appears in the request's query string, the announcement will be deleted.

    """
    log_page_view(request, "Edit Announcement")
    announcement = get_object_or_404(Announcement, id=id)
    profile = request.user.get_profile()
    if announcement.user != request.user and not profile.is_admin():
        return HttpResponseRedirect(reverse("forbidden"))  # only admins may edit other people's announcements
    if request.method == "POST":
        form = AnnouncementForm(request.POST, instance=announcement)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("announcements"))
    else:
        if "delete" in request.GET and request.GET["delete"] == "true":
            text = announcement.text
            announcement.delete()
            log.info("%s (%s) deleted announcement '%s'", request.user.username, request.user.get_full_name(), text)
            return HttpResponseRedirect(reverse("announcements"))
        form = AnnouncementForm(instance=announcement)
    return render(
        request,
        "chapter/edit_announcement.html",
        {"form": form, "id": announcement.id},
        context_instance=RequestContext(request),
    )
コード例 #3
0
ファイル: views.py プロジェクト: will2dye4/gtphipsi
def add_announcement(request):
    """Render and process a form to create a new announcement.

    This function will email all users who have elected to be notified of new announcements and also all potentials
    who have submitted information cards and elected to subscribe to chapter updates.

    """
    log_page_view(request, "Add Announcement")
    if request.method == "POST":
        form = AnnouncementForm(request.POST)
        if form.is_valid():
            announcement = form.save(commit=False)
            announcement.user = request.user
            announcement.save()
            recipients = UserProfile.all_emails_with_bit(STATUS_BITS["EMAIL_NEW_ANNOUNCEMENT"])
            if announcement.public:
                recipients += InformationCard.all_subscriber_emails()
            date = "" if announcement.date is None else "[%s] " % announcement.date.strftime("%B %d, %Y")
            message = EmailMessage(
                _("notify.announcement.subject"),
                _(
                    "notify.announcement.body",
                    args=(announcement.user.get_profile().common_name(), date, announcement.text, settings.URI_PREFIX),
                ),
                to=["*****@*****.**"],
                bcc=recipients,
            )
            message.send()
            log.info(
                "%s (%s) added a new announcement: '%s'",
                request.user.username,
                request.user.get_full_name(),
                announcement.text,
            )
            return HttpResponseRedirect(reverse("announcements"))
    else:
        form = AnnouncementForm()
    return render(request, "chapter/add_announcement.html", {"form": form}, context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: aschuster3/gtphipsi
def add_announcement(request):
    """Render and process a form to create a new announcement.

    This function will email all users who have elected to be notified of new announcements and also all potentials
    who have submitted information cards and elected to subscribe to chapter updates.

    """
    log_page_view(request, 'Add Announcement')
    if request.method == 'POST':
        form = AnnouncementForm(request.POST)
        if form.is_valid():
            announcement = form.save(commit=False)
            announcement.user = request.user
            announcement.save()
            recipients = UserProfile.all_emails_with_bit(
                STATUS_BITS['EMAIL_NEW_ANNOUNCEMENT'])
            if announcement.public:
                recipients += InformationCard.all_subscriber_emails()
            date = ('' if announcement.date is None else '[%s] ' %
                    announcement.date.strftime('%B %d, %Y'))
            message = EmailMessage(
                _('notify.announcement.subject'),
                _('notify.announcement.body',
                  args=(announcement.user.get_profile().common_name(), date,
                        announcement.text, settings.URI_PREFIX)),
                to=['*****@*****.**'],
                bcc=recipients)
            message.send()
            log.info('%s (%s) added a new announcement: \'%s\'',
                     request.user.username, request.user.get_full_name(),
                     announcement.text)
            return HttpResponseRedirect(reverse('announcements'))
    else:
        form = AnnouncementForm()
    return render(request,
                  'chapter/add_announcement.html', {'form': form},
                  context_instance=RequestContext(request))