Пример #1
0
def update_moderation_message(page, message):
    """This is bit special.. It updates last page state made from current user
    for given page. Its called after page is saved - page state is created when
    page gets saved (in signal), so this might have a concurrency issue, but 
    probably will work in 99,999%.
    
    If any page state isn't found in last UPDATE_TOLERANCE seconds, a new state
    will be created instead of affecting old message.    
    """

    UPDATE_TOLERANCE = 30 # max in last 30 seconds

    from cms.utils.permissions import get_current_user
    user = get_current_user()
    created = timezone.now() - datetime.timedelta(seconds=UPDATE_TOLERANCE)
    try:
        state = page.pagemoderatorstate_set.filter(user=user, created__gt=created).order_by('-created')[0]
    except IndexError:
        state = None
    if not state or state.message:
        # If no state was found or it already has a message, create a new one
        state = PageModeratorState(user=user, page=page, action=PageModeratorState.ACTION_CHANGED)

    state.message = message
    state.save()
Пример #2
0
def page_changed(page, old_page=None, force_moderation_action=None):
    """Called from page post save signal. If page already had pk, old version
    of page is provided in old_page argument.
    """
    # get user from thread locals
    from cms.utils.permissions import get_current_user
    user = get_current_user()

    force_moderation_action = force_moderation_action or getattr(page, 'force_moderation_action', None)
    if force_moderation_action:
        PageModeratorState(user=user, page=page, action=force_moderation_action).save()
        return

    if not old_page:
        # just newly created page
        PageModeratorState(user=user, page=page, action=PageModeratorState.ACTION_ADD).save()

    if (old_page is None and page.published) or \
        (old_page and not old_page.published == page.published):
        action = page.published and PageModeratorState.ACTION_PUBLISH or PageModeratorState.ACTION_UNPUBLISH
        PageModeratorState(user=user, page=page, action=action).save()

    if ((old_page and not old_page.moderator_state == page.moderator_state) or not old_page) \
        and page.requires_approvement():
        # update_moderation_message can be called after this :S -> recipient will not
        # see the last message
        mail_approvement_request(page, user)
Пример #3
0
def approve_page(request, page):
    """Main approving function. Two things can happen here, depending on user
    level:
    
    1.) User is somewhere in the approvement path, but not on the top. In this
    case just mark this page as approved by this user.
    
    2.) User is on top of approvement path. Draft page with all dependencies 
    will be `copied` to public model, page states log will be cleaned.  
    
    """
    moderation_level, moderation_required = get_test_moderation_level(page, request.user, False)
    if not moderator_should_approve(request, page):
        # escape soon if there isn't any approval required by this user
        try:    # it is possible publisher_public doesn't exist - first time publish
            if page.get_absolute_url() != page.publisher_public.get_absolute_url():
                page.publish()
            else:
                return
        except:
            return
    if not moderation_required:
        # this is a second case - user can publish changes
        if page.pagemoderatorstate_set.get_delete_actions().count():
            # it is a delete request for this page!!
            page.delete_with_public()
        else:
            page.publish()
    else:
        # first case - just mark page as approved from this user
        PageModeratorState(user=request.user, page=page, action=PageModeratorState.ACTION_APPROVE).save() 
Пример #4
0
def page_changed(page, old_page=None, force_moderation_action=None):
    """Called from page post save signal. If page already had pk, old version
    of page is provided in old_page argument.
    """
    # Only record changes on the draft version
    if not page.publisher_is_draft:
        return
    # get user from thread locals
    from cms.utils.permissions import get_current_user
    user = get_current_user()

    if force_moderation_action:
        PageModeratorState(user=user, page=page, action=force_moderation_action).save()
        page.save() # sets the page to dirty
        return

    if not old_page:
        # just newly created page
        PageModeratorState(user=user, page=page, action=PageModeratorState.ACTION_ADD).save()
Пример #5
0
def update_moderation_message(page, message):
    """This is bit special.. It updates last page state made from current user
    for given page. Its called after page is saved - page state is created when
    page gets saved (in signal), so this might have a concurrency issue, but 
    probably will work in 99,999%.
    
    If any page state is'nt found in last UPDATE_TOLERANCE seconds, a new state
    will be created instead of affecting old message.    
    """
    
    UPDATE_TOLERANCE = 30 # max in last 30 seconds
    
    user = get_current_user()
    created = datetime.datetime.now() - datetime.timedelta(seconds=UPDATE_TOLERANCE)
    try:
        state = page.pagemoderatorstate_set.filter(user=user, created__gt=created).order_by('-created')[0]
        # just state without message!!
        assert not state.message  
    except (IndexError, AssertionError):
        state = PageModeratorState(user=user, page=page, action=PageModeratorState.ACTION_CHANGED)
    
    state.message = message
    state.save()