def update_content_details(id): to_put = [] content = get_content_or_404(id) ref_path = i18n_path(request.forms.get('back', content.path)) if not content.is_editable: response.flash(_('Voting is disabled for content that is being ' 'broadcast')) redirect(ref_path) vote = request.forms.get('vote') if vote not in ['up', 'down']: response.flash(_('There was a problem with the request. Please try ' 'again later.')) redirect(ref_path) if vote == 'up': content.upvotes += 1 to_put.append(Event.create(Event.UPVOTE, content.key)) elif vote == 'down': content.downvotes += 1 to_put.append(Event.create(Event.DOWNVOTE, content.key)) to_put.append(content) ndb.put_multi(to_put) redirect(ref_path)
def update_content_details(id): content = get_content_or_404(id) if not content.is_editable: # Translators, shown when content is not editable (it's on air, etc) response.flash(_('This content is not editable')) redirect(i18n_path(content.path)) errors = {} title = request.forms.getunicode('title', '').strip() license = request.forms.get('license') or None if not content.title and not title: errors['title'] = _('Title cannot be blank') if license and license not in Content.LICENSE_CHOICES: errors['license'] = _('Please select a license from provided choices') if not errors: to_put = [] if title and content.title != title: content.title = title to_put.append(Event.create(Event.TITLE, content.key)) if license and content.license != license: content.license = license to_put.append(Event.create(Event.LICENSE, content.key)) if to_put: # If we have events in to_put list, we also need to put the content to_put.append(content) ndb.put_multi(to_put) response.flash(_('Content has been updated')) redirect(content.path) return dict(vals=request.forms, errors=erorrs, content=content)
def update_content_details(id): to_put = [] content = get_content_or_404(id) ref_path = i18n_path(request.forms.get('back', content.path)) if not content.is_editable: response.flash( _('Voting is disabled for content that is being ' 'broadcast')) redirect(ref_path) vote = request.forms.get('vote') if vote not in ['up', 'down']: response.flash( _('There was a problem with the request. Please try ' 'again later.')) redirect(ref_path) if vote == 'up': content.upvotes += 1 to_put.append(Event.create(Event.UPVOTE, content.key)) elif vote == 'down': content.downvotes += 1 to_put.append(Event.create(Event.DOWNVOTE, content.key)) to_put.append(content) ndb.put_multi(to_put) redirect(ref_path)
def handle_content_edits(): sel = request.params.get('select', '0') == '1' to_put = [] selection = request.forms.getall('selection') if not selection: # Translators, used as error message on broadcast page when there is # no selection to operate on finish_with_message(_('No content selected')) keys = [ndb.Key('Content', key) for key in selection] action = request.forms.get('action') if action == 'status': archive = request.forms.get('archive') or None if archive not in Content.ARCHIVE_CHOICES: finish_with_message(_('Invalid request')) for content in ndb.get_multi(keys): if content.archive != archive: content.archive = archive if archive == None: to_put.append(Event.create(Event.UNBROADCAST, content.key)) else: to_put.append(Event.create(Event.BROADCAST, content.key)) to_put.append(content) ndb.put_multi(to_put) elif action == 'delete': ndb.delete_multi(keys) finish_with_message(_('Broadcast data updated'))