Example #1
0
def entry_list_add(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 `{}`, creating'.format(options.list_name))
            entry_list = plugin_entry_list.EntryListList(name=options.list_name)
            session.add(entry_list)
        session.merge(entry_list)
        session.commit()
        title = options.entry_title
        entry = {'title': options.entry_title, 'url': options.url}
        db_entry = plugin_entry_list.get_entry_by_title(list_id=entry_list.id, title=title, session=session)
        if db_entry:
            console("Entry with the title `{}` already exist with list `{}`. Will replace identifiers if given".format(
                title, entry_list.name))
            output = 'Successfully updated entry `{}` to entry list `{}` '.format(title, entry_list.name)
        else:
            console("Adding entry with title `{}` to list `{}`".format(title, entry_list.name))
            db_entry = plugin_entry_list.EntryListEntry(entry=entry, entry_list_id=entry_list.id)
            session.add(db_entry)
            output = 'Successfully added entry `{}` to entry list `{}` '.format(title, entry_list.name)
        if options.attributes:
            console('Adding attributes to entry `{}`'.format(title))
            for identifier in options.attributes:
                for k, v in identifier.items():
                    entry[k] = v
            db_entry.entry = entry
        console(output)
Example #2
0
 def post(self, session=None):
     """ Create a new entry list """
     data = request.json
     name = data.get('name')
     entry_list = el.get_list_by_exact_name(name=name, session=session)
     if entry_list:
         return {'status': 'error',
                 'message': "list with name '%s' already exists" % name}, 500
     entry_list = el.EntryListList(name=name)
     session.add(entry_list)
     session.commit()
     resp = jsonify(entry_list.to_dict())
     resp.status_code = 201
     return resp
Example #3
0
 def post(self, session=None):
     """ Create a new entry list """
     data = request.json
     name = data.get('name')
     new_list = False
     try:
         el.get_list_by_exact_name(name=name, session=session)
     except NoResultFound:
         new_list = True
     if not new_list:
         raise Conflict('list with name \'%s\' already exists' % name)
     entry_list = el.EntryListList(name=name)
     session.add(entry_list)
     session.commit()
     resp = jsonify(entry_list.to_dict())
     resp.status_code = 201
     return resp