def entry_list_show(options): with Session() as session: try: entry_list = get_list_by_exact_name(options.list_name, session=session) except NoResultFound: console('Could not find entry list with name {}'.format(options.list_name)) return try: entry = get_entry_by_id(entry_list.id, int(options.entry), session=session) except NoResultFound: console( 'Could not find matching entry with ID {} in list `{}`'.format(int(options.entry), options.list_name)) return except ValueError: entry = get_entry_by_title(entry_list.id, options.entry, session=session) if not entry: console( 'Could not find matching entry with title `{}` in list `{}`'.format(options.entry, options.list_name)) return header = ['Field name', 'Value'] table_data = [header] for k, v in sorted(entry.entry.items()): table_data.append([k, str(v)]) table = TerminalTable(options.table_type, table_data, wrap_columns=[1]) table.table.justify_columns[0] = 'center' try: console(table.output) except TerminalTableError as e: console('ERROR: %s' % str(e))
def entry_list_show(options): with Session() as session: try: entry_list = get_list_by_exact_name(options.list_name, session=session) except NoResultFound: console('Could not find entry list with name {}'.format(options.list_name)) return try: entry = get_entry_by_id(entry_list.id, int(options.entry), session=session) except NoResultFound: console( 'Could not find matching entry with ID {} in list `{}`'.format(int(options.entry), options.list_name)) return except ValueError: entry = get_entry_by_title(entry_list.id, options.entry, session=session) if not entry: console( 'Could not find matching entry with title `{}` in list `{}`'.format(options.entry, options.list_name)) return console('Showing fields for entry ID {}'.format(options.list_name)) console('-' * 79) for k, v in sorted(entry.entry.items()): console('{}: {}'.format(k.upper(), v))
def entry_list_del(options): with Session() as session: try: entry_list = get_list_by_exact_name(options.list_name) except NoResultFound: console("Could not find entry list with name `{}`".format(options.list_name)) return try: db_entry = get_entry_by_id(entry_list.id, int(options.entry), session=session) except NoResultFound: console( "Could not find matching entry with ID {} in list `{}`".format(int(options.entry), options.list_name) ) return except ValueError: db_entry = get_entry_by_title(entry_list.id, options.entry, session=session) if not db_entry: console( "Could not find matching entry with title `{}` in list `{}`".format( options.entry, options.list_name ) ) return console("Removing entry `%s` from list %s" % (db_entry.title, options.list_name)) session.delete(db_entry)
def entry_list_show(options): with Session() as session: try: entry_list = plugin_entry_list.get_list_by_exact_name(options.list_name, session=session) except NoResultFound: console('Could not find entry list with name {}'.format(options.list_name)) return try: entry = plugin_entry_list.get_entry_by_id(entry_list.id, int(options.entry), session=session) except NoResultFound: console( 'Could not find matching entry with ID {} in list `{}`'.format(int(options.entry), options.list_name)) return except ValueError: entry = plugin_entry_list.get_entry_by_title(entry_list.id, options.entry, session=session) if not entry: console( 'Could not find matching entry with title `{}` in list `{}`'.format(options.entry, options.list_name)) return header = ['Field name', 'Value'] table_data = [header] for k, v in sorted(entry.entry.items()): table_data.append([k, str(v)]) try: table = TerminalTable(options.table_type, table_data, wrap_columns=[1]) table.table.justify_columns[0] = 'center' console(table.output) except TerminalTableError as e: console('ERROR: %s' % str(e))
def entry_list_show(options): with Session() as session: try: entry_list = get_list_by_exact_name(options.list_name, session=session) except NoResultFound: console('Could not find entry list with name {}'.format( options.list_name)) return try: entry = get_entry_by_id(entry_list.id, int(options.entry), session=session) except NoResultFound: console( 'Could not find matching entry with ID {} in list `{}`'.format( int(options.entry), options.list_name)) return except ValueError: entry = get_entry_by_title(entry_list.id, options.entry, session=session) if not entry: console( 'Could not find matching entry with title `{}` in list `{}`' .format(options.entry, options.list_name)) return console('Showing fields for entry ID {}'.format(options.list_name)) console('-' * 79) for k, v in sorted(entry.entry.items()): console('{}: {}'.format(k.upper(), v))
def entry_list_del(options): with Session() as session: try: entry_list = get_list_by_exact_name(options.list_name) except NoResultFound: console('Could not find entry list with name `{}`'.format( options.list_name)) return try: db_entry = get_entry_by_id(entry_list.id, int(options.entry), session=session) except NoResultFound: console( 'Could not find matching entry with ID {} in list `{}`'.format( int(options.entry), options.list_name)) return except ValueError: db_entry = get_entry_by_title(entry_list.id, options.entry, session=session) if not db_entry: console( 'Could not find matching entry with title `{}` in list `{}`' .format(options.entry, options.list_name)) return console('Removing entry `%s` from list %s' % (db_entry.title, options.list_name)) session.delete(db_entry)
def get(self, list_id, entry_id, session=None): """ Get an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find entry with id %d in list %d' % (entry_id, list_id)}, 404 return jsonify(entry.to_dict())
def get(self, list_id, entry_id, session=None): """ Get an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: raise NotFoundError('could not find entry with id %d in list %d' % (entry_id, list_id)) return jsonify(entry.to_dict())
def get(self, list_id, entry_id, session=None): """ Get an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find entry with id %d in list %d' % (entry_id, list_id)}, 404 return jsonify(entry.to_dict())
def delete(self, list_id, entry_id, session=None): """ Delete an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: raise NotFoundError('could not find entry with id %d in list %d' % (entry_id, list_id)) log.debug('deleting movie %d', entry.id) session.delete(entry) return success_response('successfully deleted entry %d' % entry.id)
def delete(self, list_id, entry_id, session=None): """ Delete an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find entry with id %d in list %d' % (entry_id, list_id)}, 404 log.debug('deleting movie %d', entry.id) session.delete(entry) return {}
def delete(self, list_id, entry_id, session=None): """ Delete an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find entry with id %d in list %d' % (entry_id, list_id)}, 404 log.debug('deleting movie %d', entry.id) session.delete(entry) return {}
def put(self, list_id, entry_id, session=None): """ Sets entry object's entry data """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find entry with id %d in list %d' % (entry_id, list_id)}, 4044 data = request.json entry.entry = data session.commit() return jsonify(entry.to_dict())
def put(self, list_id, entry_id, session=None): """ Sets entry object's entry data """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'could not find entry with id %d in list %d' % (entry_id, list_id)}, 4044 data = request.json entry.entry = data session.commit() return jsonify(entry.to_dict())
def get(self, list_id, entry_id, session=None): """ Get an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: raise NotFoundError('could not find entry with id %d in list %d' % (entry_id, list_id)) return jsonify(entry.to_dict())
def delete(self, list_id, entry_id, session=None): """ Delete an entry by list ID and entry ID """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: raise NotFoundError('could not find entry with id %d in list %d' % (entry_id, list_id)) log.debug('deleting movie %d', entry.id) session.delete(entry) return success_response('successfully deleted entry %d' % entry.id)
def put(self, list_id, entry_id, session=None): """ Sets entry object's entry data """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: raise NotFoundError('could not find entry with id %d in list %d' % (entry_id, list_id)) data = request.json entry.entry = data if data.get('title'): entry.title = data['title'] if data.get('original_url'): entry.original_url = data['original_url'] session.commit() resp = jsonify(entry.to_dict()) resp.status_code = 201 return resp
def put(self, list_id, entry_id, session=None): """ Sets entry object's entry data """ try: entry = el.get_entry_by_id(list_id=list_id, entry_id=entry_id, session=session) except NoResultFound: raise NotFoundError('could not find entry with id %d in list %d' % (entry_id, list_id)) data = request.json entry.entry = data if data.get('title'): entry.title = data['title'] if data.get('original_url'): entry.original_url = data['original_url'] session.commit() resp = jsonify(entry.to_dict()) resp.status_code = 201 return resp