(request, pk)
return ajax_success(msg="changed herald state", icon=herald.icon, tmpl=tmpl, state=herald.get_status_display())
Update the given herald status, moderators action only.
Update the given herald status, moderators action only.
Update the given herald status moderators action only .
def herald_update(request, pk):
    """
    Update the given herald status, moderators action only.
    """

    herald = SharedLink.objects.filter(pk=pk).first()
    user = request.user

    if not herald:
        return ajax_error(msg="Herald not found")

    status = request.POST.get('status')
    mapper = dict(accept=SharedLink.ACCEPTED, decline=SharedLink.DECLINED)
    status = mapper.get(status)

    if status is None:
        return ajax_error(msg="Invalid status.")

    # If herald is already published, do not accept again.
    if herald.published:
        return ajax_error(msg=f"submission is already published.")

    # Update fields only when change is detected.
    if status != herald.status:
        herald.status = status
        herald.editor = user
        herald.lastedit_date = util.now()

    context = dict(story=herald, user=request.user)
    tmpl = loader.get_template(template_name='herald/herald_item.html')
    tmpl = tmpl.render(context)

    SharedLink.objects.filter(pk=herald.pk).update(status=herald.status, editor=herald.editor,
                                                   lastedit_date=herald.lastedit_date)

    logmsg = f"{herald.get_status_display().lower()} herald story {herald.url[:100]}"
    auth.db_logger(user=herald.editor, target=herald.author, text=logmsg)

    return ajax_success(msg="changed herald state", icon=herald.icon, tmpl=tmpl, state=herald.get_status_display())
def herald_update ( request , pk ) : herald = SharedLink . objects . filter ( pk = pk ) . first ( ) user = request . user if not herald : return ajax_error ( msg = "Herald not found" ) status = request . POST . get ( 'status' ) mapper = dict ( accept = SharedLink . ACCEPTED , decline = SharedLink . DECLINED ) status = mapper . get ( status ) if status is None : return ajax_error ( msg = "Invalid status." ) # If herald is already published, do not accept again. if herald . published : return ajax_error ( msg = f"submission is already published." ) # Update fields only when change is detected. if status != herald . status : herald . status = status herald . editor = user herald . lastedit_date = util . now ( ) context = dict ( story = herald , user = request . user ) tmpl = loader . get_template ( template_name = 'herald/herald_item.html' ) tmpl = tmpl . render ( context ) SharedLink . objects . filter ( pk = herald . pk ) . update ( status = herald . status , editor = herald . editor , lastedit_date = herald . lastedit_date ) logmsg = f"{herald.get_status_display().lower()} herald story {herald.url[:100]}" auth . db_logger ( user = herald . editor , target = herald . author , text = logmsg ) return ajax_success ( msg = "changed herald state" , icon = herald . icon , tmpl = tmpl , state = herald . get_status_display ( ) )