def manage_entries(options, selection, approved): """Manage pending entries""" approved_text = 'approved' if approved else 'pending' with Session() as session: if selection == 'all': entries = plugin_pending_approval.list_pending_entries( session=session, approved=not approved) else: try: entry = plugin_pending_approval.get_entry_by_id( session, selection) if entry.approved is approved: console( colorize('red', 'ERROR: ') + 'Entry with ID %s is already %s' % (entry.id, approved_text)) sys.exit(1) except NoResultFound: console('Pending entry with ID %s does not exist' % selection) sys.exit(1) else: entries = [entry] if not entries: console('All entries are already %s' % approved_text) return for entry in entries: if entry.approved is not approved: console('Setting pending entry with ID %s status to %s' % (entry.id, approved_text)) entry.approved = approved
def get(self, entry_id, session=None): """Get a pending entry by ID""" try: entry = get_entry_by_id(session, entry_id) except NoResultFound: raise NotFoundError('No pending entry with ID %s' % entry_id) return jsonify(entry.to_dict())
def get(self, entry_id, session=None): """Get a pending entry by ID""" try: entry = get_entry_by_id(session, entry_id) except NoResultFound: raise NotFoundError("No pending entry with ID %s" % entry_id) return jsonify(entry.to_dict())
def delete(self, entry_id, session=None): """Delete a pending entry""" try: entry = get_entry_by_id(session, entry_id) except NoResultFound: raise NotFoundError("No pending entry with ID %s" % entry_id) session.delete(entry) return success_response("successfully deleted entry with ID %s" % entry_id)
def delete(self, entry_id, session=None): """Delete a pending entry""" try: entry = get_entry_by_id(session, entry_id) except NoResultFound: raise NotFoundError('No pending entry with ID %s' % entry_id) session.delete(entry) return success_response('successfully deleted entry with ID %s' % entry_id)
def put(self, entry_id, session=None): """Approve/Reject the status of a pending entry""" try: entry = get_entry_by_id(session, entry_id) except NoResultFound: raise NotFoundError("No pending entry with ID %s" % entry_id) data = request.json approved = data["operation"] == "approve" operation_text = "approved" if approved else "pending" if entry.approved is approved: raise BadRequest("Entry with id {} is already {}".format(entry_id, operation_text)) entry.approved = approved session.commit() rsp = jsonify(entry.to_dict()) rsp.status_code = 201 return rsp
def put(self, entry_id, session=None): """Approve/Reject the status of a pending entry""" try: entry = get_entry_by_id(session, entry_id) except NoResultFound: raise NotFoundError('No pending entry with ID %s' % entry_id) data = request.json approved = data['operation'] == 'approve' operation_text = 'approved' if approved else 'pending' if entry.approved is approved: raise BadRequest('Entry with id {} is already {}'.format( entry_id, operation_text)) entry.approved = approved session.commit() rsp = jsonify(entry.to_dict()) rsp.status_code = 201 return rsp
def manage_entries(options, selection, approved): """Manage pending entries""" approved_text = 'approved' if approved else 'pending' with Session() as session: if selection == 'all': entries = list_pending_entries(session=session, approved=not approved) else: try: entry = get_entry_by_id(session, selection) if entry.approved is approved: console(colorize('red', 'ERROR: ') + 'Entry with ID %s is already %s' % (entry.id, approved_text)) sys.exit(1) except NoResultFound: console('Pending entry with ID %s does not exist' % selection) sys.exit(1) else: entries = [entry] if not entries: console('All entries are already %s' % approved_text) return for entry in entries: if entry.approved is not approved: console('Setting pending entry with ID %s status to %s' % (entry.id, approved_text)) entry.approved = approved