示例#1
0
文件: event.py 项目: UCF/unify-events
def bulk_action(request):
    if request.method == 'POST':
        action_0 = request.POST['bulk-action_0']
        action_1 = request.POST['bulk-action_1']

        if action_0 == action_1 == 'empty':
            messages.error(request, 'No action selected.')
            return success_previous_view_redirect(request, reverse('dashboard'))

        action = action_0
        if action == 'empty':
            action = action_1

        if action not in ['submit-to-main', 'posted', 'pending', 'delete']:
            messages.error(request, 'Unrecognized action selected %s.' % action)
            return success_previous_view_redirect(request, reverse('dashboard'))

        # remove duplicates
        event_ids = list(set(request.POST.getlist('object_ids', [])))

        for event_id in event_ids:
            try:
                event = Event.objects.get(pk=event_id)
            except Event.DoesNotExist, e:
                # The subscription event may not exist anymore since
                # the original event has been deleted, thus deleting
                # the subscription events. Log and fail gracefully.
                log.error(str(e))
                continue

            if not request.user.is_superuser and event.calendar not in request.user.calendars:
                messages.error(request, 'You do not have permissions to modify Event %s' % event.title)
                continue

            if action == 'submit-to-main':
                submit_event_to_main(request, event_id)

            elif action == 'posted':
                update_event_state(request, event_id, State.posted)

            elif action == 'pending':
                update_event_state(request, event_id, State.pending)

            elif action == 'delete':
                try:
                    event.delete()
                except Exception, e:
                    log.error(str(e))
                    messages.error(request, 'Unable to delete Event %s.' % event.title)
示例#2
0
def bulk_action(request):
    if request.method == 'POST':
        action_0 = request.POST['bulk-action_0']
        action_1 = request.POST['bulk-action_1']

        if action_0 == action_1 == 'empty':
            messages.error(request, 'No action selected.')
            return success_previous_view_redirect(request, reverse('location-list'))

        action = action_0
        if action == 'empty':
            action = action_1

        if action not in ['approve', 'review', 'delete']:
            messages.error(request, 'Unrecognized action selected %s.' % action)
            return success_previous_view_redirect(request, reverse('location-list'))

        # remove duplicates
        location_ids = request.POST.getlist('object_ids')

        for location_id in location_ids:
            try:
                location = Location.objects.get(pk=location_id)
            except Location.DoesNotExist, e:
                log.error(str(e))
                continue

            if not request.user.is_superuser:
                messages.error(request, 'You do not have permissions to modify Location %s' % location.comboname)
                continue

            if action == 'approve':
                # approve the location
                try:
                    location.reviewed = True
                    location.save()
                except Exception, e:
                    log.error(str(e))
                    messages.error(request, 'Unable to set Location %s to Approved.' % location.comboname)

            elif action == 'review':
                # Set all Locations to Reviewed
                try:
                    location.reviewed = False
                    location.save()
                except Exception, e:
                    log.error(str(e))
                    messages.error(request, 'Unable to set Location %s to Review.' % location.comboname)
示例#3
0
def merge(request, category_from_id=None, category_to_id=None):
    """
    View for merging the category into another category.
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden('You cannot perform this action.')

    if category_from_id and category_to_id:
        category_from = get_object_or_404(Category, pk=category_from_id)
        category_to = get_object_or_404(Category, pk=category_to_id)

        events = category_from.events.all()
        if events.count() > 0:
            try:
                for event in events:
                    event.category = category_to
                    event.save()
                category_from.delete()
            except Exception, e:
                log.error(str(e))
                messages.error(request, 'Merging category failed.')
            else:
                messages.success(request, 'Category successfully merged.')
        else:
            messages.error(request, 'Cannot merge this category: category has no events. Delete this category instead of merging.')
        return success_previous_view_redirect(request, reverse('category-list'))
示例#4
0
def merge(request, location_from_id=None, location_to_id=None):
    """
    View for merging the location into another location.
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden('You cannot perform this action.')

    if location_from_id and location_to_id:
        location_from = get_object_or_404(Location, pk=location_from_id)
        location_to = get_object_or_404(Location, pk=location_to_id)

        event_instances = location_from.event_instances.filter(parent=None)
        if event_instances.count() > 0:
            try:
                for event_instance in event_instances:
                    event_instance.location = location_to
                    event_instance.save()
                location_from.delete()
            except Exception, e:
                log.error(str(e))
                messages.error(request, 'Merging location failed.')
            else:
                messages.success(request, 'Location successfully merged.')
        else:
            messages.error(request, 'Cannot merge this location: location has no events. Delete this location instead of merging.')
        return success_previous_view_redirect(request, reverse('location-list'))
示例#5
0
文件: tag.py 项目: UCF/unify-events
def merge(request, tag_from_id=None, tag_to_id=None):
    """
    View for merging the tag into another tag.
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden('You cannot perform this action.')

    if tag_from_id and tag_to_id:
        tag_from = get_object_or_404(Tag, pk=tag_from_id)
        tag_to = get_object_or_404(Tag, pk=tag_to_id)

        events = Event.objects.filter(tags__name__in=[tag_from.name])
        try:
            for event in events:
                event.tags.add(tag_to)
                event.save()
            tag_from.delete()
        except Exception, e:
            log.error(str(e))
            messages.error(request, 'Merging tag failed.')
        else:
            messages.success(request, 'Tag successfully merged.')
        return success_previous_view_redirect(request, reverse('tag-list'))
示例#6
0
            error = True
            storage.used = False
            break

        if not error:
            message = ''
            if action == 'approve':
                message = 'Locations successfully Approved.'
            elif action == 'posted':
                message = 'Locations successfully moved to Review.'
            elif action == 'delete':
                message = 'Locations successfully deleted.'

            messages.success(request, message)

        return success_previous_view_redirect(request, reverse('location-list'))
    raise Http404


@login_required
def merge(request, location_from_id=None, location_to_id=None):
    """
    View for merging the location into another location.
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden('You cannot perform this action.')

    if location_from_id and location_to_id:
        location_from = get_object_or_404(Location, pk=location_from_id)
        location_to = get_object_or_404(Location, pk=location_to_id)
示例#7
0
文件: event.py 项目: UCF/unify-events
def submit_to_main(request, pk=None):
    """
    View to submit the event to the main calendar.
    """
    event = submit_event_to_main(request, pk)
    return success_previous_view_redirect(request, reverse('dashboard', kwargs={'pk': event.calendar.id}))
示例#8
0
文件: event.py 项目: UCF/unify-events
def update_state(request, pk=None, state=None):
    """
    View to update the state of the event.
    """
    event = update_event_state(request, pk, state)
    return success_previous_view_redirect(request, reverse('dashboard', kwargs={'pk': event.calendar.id}))
示例#9
0
文件: event.py 项目: UCF/unify-events
            break

        if not error:
            message = ''
            if action == 'submit-to-main':
                message = 'Events successfully submitted to the Main Calendar.'
            elif action == 'posted':
                message = 'Events successfully added to Posted.'
            elif action == 'pending':
                message = 'Events successfully moved to Pending.'
            elif action == 'delete':
                message = 'Events successfully deleted.'

            messages.success(request, message)

        return success_previous_view_redirect(request, reverse('dashboard'))
    raise Http404


@login_required
def cancel_uncancel(request, pk=None):
    event = get_object_or_404(Event, pk=pk)

    # Get original event
    original_event = event
    if event.created_from:
        event = event.created_from

    if not request.user.is_superuser and event.calendar not in request.user.calendars:
        return HttpResponseForbidden('You cannot modify the specified event.')