Example #1
0
def trigger_scheduled_tasks():
    # today
    dayofmonth = datetime.today().day
    dayofweek = datetime.today().weekday()
    hour = datetime.today().hour
    minute = datetime.today().minute

    # get list of tasks that should run under this host
    query = """
        (dayofmonth:{} OR dayofmonth:None) AND
        (dayofweek:{} OR dayofweek:None) AND
        (hour:{} OR hour:None) AND
        (minute:{} OR minute:None)
    """.format(dayofmonth, dayofweek, hour, minute)
    ret = es.list(HOST, 'core_task', 'schedule', query)

    for schedule in ret:
        # check if instance exists
        query = """
            task_id:{} AND
            created:[now-1m TO now+1m]
        """.format(schedule['task_id'])
        instance = es.list(HOST, 'core_task', 'instance', query)
        if len(instance) > 0:
            continue  # task already triggered
        # create instance
        es.create(
            HOST, 'core_task', 'instance', '', {
                "task_id": schedule['task_id'],
                "status": "WAITING",
                "login": "******",
                "created": es.now()
            })
        es.flush(HOST, 'core_task')
Example #2
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # keep pagination
    p["q"] = tools.get('q', '*')
    # pagination
    p["from"] = int(tools.get('from', 0))
    p["size"] = int(tools.get('size', p['c']['page_size']))
    # sort
    p['sort_field'] = tools.get('sort_field', p['c']['sort_field'])
    p['sort_dir'] = tools.get('sort_field', p['c']['sort_dir'])

    # load post
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # check ACL
    valid_acl = False
    if not p['post'].get('acl_readonly') and not p['post'].get('acl_edit'):
        valid_acl = True
    if p['login'] == p['post'].get('created_by'): valid_acl = True
    if p['post'].get('acl_readonly'):
        if p['login'] in p['post'].get('acl_readonly'): valid_acl = True
        if 'EVERYONE' in p['post'].get('acl_readonly'): valid_acl = True
    if p['post'].get('acl_edit'):
        if p['login'] in p['post'].get('acl_edit'): valid_acl = True
        if 'EVERYONE' in p['post'].get('acl_edit'): valid_acl = True
    if not valid_acl:
        return tools.alert('permission not granted')

    # return json format
    if tools.get("json"):
        callback = tools.get("callback")
        if not callback:
            return json.dumps(p['post'])
        else:
            return "{}({})".format(callback, json.dumps(p['post']))

    # get comment list
    query = "post_id:{}".format(post_id)
    option = "size=100&sort=created:desc"
    p['comment_list'] = es.list(host, index, 'comment', query, option)

    # increase visit count
    if not p['post'].get("viewed"): p['post']["viewed"] = 0
    p['post']["viewed"] += 1
    es.update(host, index, 'post', post_id, p['post'])

    # field_list
    p['field_list'] = es.list(host, index, 'field', "visible:view",
                              "size=1000&sort=order_key:asc")

    return render_template("post/post/view.html", p=p)
Example #3
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # load post
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    p['original'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # init workflow
    wf = tools.get('wf', 'edit')
    p['workflow'] = workflow.init(wf, host, index)

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['id']] = field

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec (p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit: pass
        except Exception, e:
            raise
Example #4
0
def get(p):
    index = tools.get('index')
    id = tools.get('id')
    if not index or not id:
        return tools.alert('invalid id or index')

    # find config with matching index
    configs = es.list(p['host'], 'core_nav', 'config',
        "name:'index' AND value:'{}'".format(index))
    if not len(configs) > 0:
        return tools.alert('site not found')

    # get site id
    navigation_id = configs[0]['id'].split('_')[0]
    navigation = es.get(p['host'], 'core_nav', 'navigation', navigation_id)
    site = es.get(p['host'], 'core_nav', 'site', navigation['site_id'])

    # form url
    url = '{}/{}'.format(site.get('name'), navigation.get('name'))
    url = "{}/post/view/{}".format(url, id)
    # when navigation or site is empty then it contains double slash 
    url = url.replace("//", "/")
    url = urlparse.urljoin(request.url_root, url)

    return tools.redirect(url)
Example #5
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # init workflow
    wf = tools.get("wf", 'comment_edit')
    p['workflow'] = workflow.init(wf, host, index)

    # load comment
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # comment_id
    comment_id = tools.get("id")
    p['comment'] = next((x for x in p['post']['comment'] if x['id'] == comment_id), None)
    if not p['comment']:
        return tools.alert('not valid comment_id - {}'.format(comment_id))

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['name']] = field['id']

    # update comment
    p['comment']['updated'] = es.now()
    p['comment']['updated_by'] = p['login']
    p['comment']['comment'] = tools.get("comment")

    es.update(host, index, 'post', post_id, p['post'])
    es.flush(host, index)

    return tools.redirect(request.referrer)
Example #6
0
def get(p):
    # proxy list
    option = 'size=10000'
    p['proxy_list'] = es.list(p['host'], 'core_proxy', 'rev_proxy', '*',
                              option)

    return render_template("admin/proxy/default.html", p=p)
Example #7
0
def get(p):
    # load instance
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('invalid task id - {}'.format(task_id))

    # instance list
    query = 'task_id:{}'.format(task_id)
    option = 'size=50'
    if es.count(p['host'], 'core_task', 'instance'):
        option += '&sort=created:desc'
    p['history_list'] = es.list(p['host'], 'core_task', 'instance', query,
                                option)

    for history in p['history_list']:
        # statistics
        query = "instance_id:{}".format(history['id'])
        history['total'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['total']: history['total'] = ''

        query = "instance_id:{} AND status:SUCCESS".format(history['id'])
        history['success'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['success']: history['success'] = ''

        query = "instance_id:{} AND status:ERROR".format(history['id'])
        history['error'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['error']: history['error'] = ''

    return render_template("task/status/history.html", p=p)
Example #8
0
def get(p):
    # get list of roles
    query = "site_id:{}".format(p['site']['id'])
    option = "size=10000&sort=name:asc"
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    # selected role
    role_id = p['nav'][-1]
    p['role'] = es.get(p['host'], 'core_nav', 'role', role_id)
    if not p['role']:
        p['role'] = p['role_list'][0]

    # get permission
    permission_id = "{}_{}".format(p['role']['id'], p['navigation']['id'])
    p['permission'] = es.get(p['host'], 'core_nav', 'permission', permission_id)

    if request.method == "POST":
        doc = { "operations": [x for x in tools.get('operations', []) if x] }

        if not p['permission']:
            # create permission
            es.create(p['host'], 'core_nav', 'permission', permission_id, doc)
        else:
            # edit permission
            es.update(p['host'], 'core_nav', 'permission', permission_id, doc)
        es.flush(p['host'], 'core_nav')

        return tools.redirect(request.referrer)


    return render_template("post/permission/default.html", p=p)
Example #9
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # send out empty post to be compatible with edit form
    p['post'] = {}

    # init workflow
    wf = tools.get("wf", 'create')
    p['workflow'] = workflow.init(wf, host, index)

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['id']] = field

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec(p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit:
            pass
        except Exception, e:
            raise
Example #10
0
def get(p):
    # role list
    query = 'site_id:{}'.format(p['site']['id'])
    option = 'size=1000&sort=name:asc'
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    return render_template("post/role/default.html", p=p)
Example #11
0
def init(wf, host, index):
    # Get Workflow
    query = "name:{}".format(wf)
    option = "size=1"
    ret = es.list(host, index, 'workflow', query, option)
    if len(ret): return ret[0]

    return None
Example #12
0
def waiting_tasks(hostname):
    # get list of tasks that should run under this host
    query = "runat:{} OR runat:anywhere".format(hostname)
    option = "size=10000"
    task_list = es.list(HOST, 'core_task', 'task', query, option)

    # get list of waiting instances
    instances = []
    for task in task_list:
        query = "status:WAITING AND task_id:{}".format(task['id'])
        option = "size=10000"
        instance_list = es.list(HOST, 'core_task', 'instance', query, option)
        for instance in instance_list:
            instance['task'] = task
            instances.append(instance)

    return instances
Example #13
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']
    # get list of workflow
    query = "*"
    option = "size=10000&sort=name:asc"
    p['workflow_list'] = es.list(host, index, 'workflow', query, option)

    return render_template("post/workflow/default.html", p=p)
Example #14
0
def actions(task_id):
    query = "task_id:{} AND enabled:Yes".format(task_id)
    option = "size=10000&sort=order_key:asc"
    actions = es.list(HOST, 'core_task', 'action', query, option)
    for action in actions:
        action['module'] = es.get(HOST, 'core_task', 'module',
                                  action['module_id'])

    return actions
Example #15
0
def get(p):
    p['site_id'] = tools.get('site_id')
    if not p['site_id']: return tools.alert('site id is missing')

    # role list
    query = 'site_id:{}'.format(p['site_id'])
    option = 'size=1000&sort=name:asc'
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    return render_template("admin/role/default.html", p=p)
Example #16
0
def get(p):
    # load task
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('task not found - {}'.format(task_id))

    if request.method == "POST":
        es.update(
            p['host'], 'core_task', 'task', task_id, {
                'navigation_id': p['navigation']['id'],
                'name': tools.get('name'),
                'runat':
                tools.get('runat') if tools.get('runat') else 'anywhere',
                'description': tools.get('description')
            })
        es.flush(p['host'], 'core_task')

        return tools.redirect(request.referrer)

    # load action list
    # when there are no records then the task fails to run
    option = ''
    if es.count(p['host'], 'core_task', 'action'):
        option = 'size=10000&sort=order_key:asc'

    query = 'task_id:{}'.format(p['task']['id'])
    p['action_list'] = es.list(p['host'], 'core_task', 'action', query, option)
    for action in p['action_list']:
        action['module'] = es.get(p['host'], 'core_task', 'module',
                                  action['module_id'])

    # load schedule list
    query = 'task_id:{}'.format(p['task']['id'])
    p['schedule_list'] = es.list(p['host'], 'core_task', 'schedule', query)

    # load task module List
    option = 'size=10000&sort=description:asc'
    p['task_module_list'] = es.list(p['host'], 'core_task', 'module', '*',
                                    option)

    return render_template("task/task/edit.html", p=p)
Example #17
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # notification config
    p['conf'] = notification.get_conf(host)

    # Get notification list
    option = "size=1000&sort=id:asc"
    p['notification_list'] = es.list(host, index, 'notification', '*', option)

    return render_template("post/notification/default.html", p=p)
Example #18
0
def get(p):
    p['site_id'] = tools.get('site_id')
    if not p['site_id']: return tools.alert('site id is missing')

    # get navigation list
    query = 'site_id:{} AND -module_id:1 AND -module_id:2 AND -module_id:3'.format(p['site_id'])
    option = 'size=1000&sort=order_key:asc'
    p['nav_list'] = es.list(p['host'], 'core_nav', 'navigation', query, option)

    # module list
    query = "* AND -name:admin AND -name:auth AND -name:install"
    option = 'size=1000&sort=name:asc'
    p['module_list'] = es.list(p['host'], 'core_nav', 'module', query, option)

    # module list
    for nav in p['nav_list']:
        module = es.get(p['host'], 'core_nav', 'module', nav['module_id'])
        nav['module'] = module

    return render_template("admin/nav/default.html", p=p)
Example #19
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # search keyword
    p["q"] = tools.get('q', '*')
    p["fq"] = tools.get('fq', '*')

    # load field
    field_id = p['nav'][-1]
    p['field'] = es.list(host, index, 'field', '_id:{}'.format(field_id))
    if not p['field']:
        return 'not valid field id - {}'.format(field_id)
    p['field'] = p['field'][0]

    # selected filters
    p['field_list'] = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in p['field_list']:
        filter_field = field['id']
        if field.get('filter_field'):
            filter_field = field['filter_field']
        p['field_map'][field['id']] = filter_field

    p["selected_filter_list"] = {}
    for field in p['field_list']:
        value = tools.get(field['id'])
        if value:
            # filter will come in as ?created_by=lee _or_ cavalier
            values = value.split("_or_")
            p["selected_filter_list"][field['id']] = values

    # search query
    search_query = render_template("post/filter/filter_query.json", p=p)
    try:
        search_url = "{}/{}/post/_search".format(host, index)
        response = http.http_req_json(search_url, "POST", search_query)

    except urllib2.HTTPError, e:
        raise Exception("url: {}\nquery: {}\{}".format(
                search_url, search_query, e.read()))
Example #20
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load history list
    item_id = p['nav'][-1]
    query = "id:{}".format(item_id)
    option = "size=100&sort=created:desc"
    p['history_list'] = es.list(host, index, 'log', query, option)
    if not p['history_list']:
        return tools.alert('not valid id - {}'.format(item_id))

    return render_template("post/history/list.html", p=p)
Example #21
0
def get(p):
    # get data source list
    query = 'navigation_id:{}'.format(p['navigation']['id'])
    option = 'size=10000'
    p['ds_list'] = es.list(p['host'], 'core_data', 'datasource', query, option)

    p['ds'] = {}
    if tools.get('id'):
        p['ds'] = es.get(p['host'], 'core_data', 'datasource', tools.get('id'))
    if not p['ds'] and len(p['ds_list']):
        p['ds'] = p['ds_list'][0]

    return render_template("dataservice/default.html", p=p)
Example #22
0
def get(p):

    # Load Task List
    option = None
    query = 'navigation_id:{}'.format(p['navigation']['id'])
    if es.count(p['host'], 'core_task', 'task'):
        option = 'sort=name:asc'
    p['task_list'] = es.list(p['host'], 'core_task', 'task', query, option)

    # get last instance information
    for task in p['task_list']:
        query = 'task_id:{}'.format(task['id'])
        option = None
        if es.count(p['host'], 'core_task', 'instance'):
            option = 'sort=created:desc'

        ret = es.list(p['host'], 'core_task', 'instance', query, option)
        task['instance'] = {}
        if len(ret):
            task['instance'] = ret[0]

    return render_template("task/task/default.html", p=p)
Example #23
0
def get(p):
    # load instance
    instance_id = p['nav'][-1]
    p['instance'] = es.get(p['host'], 'core_task', 'instance', instance_id)
    if not p['instance']:
        return tools.alert('invalid instance id - {}'.format(instance_id))

    # Search Keyword
    search_keyword = tools.get("search[value]") + "*"

    # Length of the result
    length = tools.get("length")
    if not length: length = 10

    # Offset of the result
    start = tools.get("start")
    if not start: start = 0

    # draw
    draw = tools.get("draw")
    if not draw: draw = 0

    # Apply Search Keyword
    query = "instance_id:{} AND {}".format(instance_id, search_keyword)

    option = 'from={}&size={}&sort=created:desc'.format(start, length)
    # search results
    search_result = es.list(p['host'], 'core_task', 'log', query, option)

    # Get Total number of records
    total = es.count(p['host'], 'core_task', 'log')
    filter_total = es.count(p['host'], 'core_task', 'log', query)

    # Form header
    DataTableJson = {}
    DataTableJson = {
        # draw - this is handshake id which maps the request - response async maps from JS
        "draw":
        int(draw),
        "recordsTotal":
        total,
        "recordsFiltered":
        filter_total,
        "data":
        [[log['action'], log['message'], log['status'], log['created']]
         for log in search_result]
    }

    # Return in JSON format
    return json.dumps(DataTableJson)
Example #24
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load workflow
    workflow_id = p['nav'][-1]
    p['workflow'] = es.get(host, index, 'workflow', workflow_id)
    if not p['workflow']:
        return tools.alert('not valid workflow id - {}'.format(workflow_id))

    # load field list
    p['field_list'] = es.list(host, index, 'field', '*',
                              'size=1000&sort=name:asc')

    # save workflow
    if request.method == "POST":
        return post(p, host, index, p['workflow'])
    # display workflow edit page
    return render_template("post/workflow/edit.html", p=p)
Example #25
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # return search results in jsonp format
    if tools.get("json"):
        callback = tools.get("callback")
        if not callback:
            return json.dumps(p["post_list"])
        else:
            return "{}({})".format(callback, json.dumps(p["post_list"]))

    # Get Visible Fields of List
    option = "size=1000&sort=order_key:asc"
    p['field_list'] = es.list(host, index, 'field', 'visible:list', option)

    # if list exists then load list
    #ListCustom = LoadConfiguration(p["SiteId"], p["NavigationId"], "list")
    #if ListCustom: return render_template(app.jinja_env.from_string(ListCustom), p=p)
    return render_template("post/post/default.html", p=p)
Example #26
0
def get(p):
    # Load Action
    action_id = p['nav'][-1]
    p['action'] = es.get(p['host'], 'core_task', 'action', action_id)
    if not p['action']:
        return tools.alert('not valid action id - {}'.format(action_id))

    if request.method == "POST":
        es.update(
            p['host'], 'core_task', 'action', tools.get('action_id'), {
                'task_id': tools.get('task_id'),
                'module_id': tools.get('module_id'),
                'enabled': tools.get('enabled'),
                'stop': tools.get('stop'),
                'order_key': int(tools.get('order_key')),
                'name': tools.get('name'),
                'description': tools.get('description'),
                'connection': tools.get('connection'),
                'query': tools.get('query')
            })
        es.flush(p['host'], 'core_task')

        return tools.redirect(request.referrer)

    # load module
    p['action']['module'] = es.get(p['host'], 'core_task', 'module',
                                   p['action']['module_id'])

    # load task
    p['task'] = es.get(p['host'], 'core_task', 'task', tools.get('task_id'))

    # task module list
    option = 'size=10000&sort=description:asc'
    p['task_module_list'] = es.list(p['host'], 'core_task', 'module', '*',
                                    option)

    return render_template("task/action/edit.html", p=p)
Example #27
0
def get_login_modules(p):
    query = "*"
    option = 'size=1000&sort=priority:desc'
    return es.list(p['host'], 'core_nav', 'login_module', query, option)
Example #28
0
            return tools.alert('permission not granted')
    ######################################################

    if request.method == "POST":
        return post(p)

    # get list of field
    if p['workflow'] and p['workflow'].get('screen'):
        p['field_list'] = []
        for field in jinja.getlist(p['workflow'].get('screen')):
            f = es.get(host, index, 'field', field)
            p['field_list'].append(f)
    else:
        query = "visible:edit"
        option = "size=10000&sort=order_key:asc"
        p['field_list'] = es.list(host, index, 'field', query, option)

    return render_template("post/post/edit.html",p=p)


def post(p):
    host = p['c']['host']; index = p['c']['index'];

    # get all submitted fields
    p["post"] = {"id": p['nav'][-1]}
    for field in request.form:
        field_info = p['field_map'][field]
        value = tools.get(field)

        # if object then convert to json object
        if field_info.get('handler') == "object":
Example #29
0
def install(host, base_dir):

    # check if search site exists
    sites = es.list(host, 'core_nav', 'site', "name:'search'")
    if not sites:
        # create a site
        site = {'name': 'search', 'display_name': 'Search Engine'}

        es.create(host, 'core_nav', 'site', 'search', site)

        # create a navigation
        navigation = {
            "site_id": 'search',
            "module_id": '10',
            "order_key": 100,
            "is_displayed": '1',
            "name": 'search',
            "display_name": 'Search Engine',
            "new_window": '0'
        }
        es.create(host, 'core_nav', 'navigation', 'searchnav', navigation)

        # set up the site
        config = {'name': 'index', 'value': 'everything'}
        es.create(host, 'core_nav', 'config',
                  'searchnav_{}'.format(config['name']), config)

        config = {'name': 'host', 'value': 'http://localhost:9200'}
        es.create(host, 'core_nav', 'config',
                  'searchnav_{}'.format(config['name']), config)

        config = {
            'name':
            'search_item_template',
            'value':
            """
{% extends "post/search/base.html" %}


{% macro default(post) %}
<table class="table">
  <tr><th class="bg-success">
    <!-- Type -->
    <span class="label label-info">{{ post._index }}</span>
    <!-- Title -->
    <span>
      {% if post.url %}
          <a href="{{post.url}}" target=_blank>
      {% else %}
          <a href="/search/redirect?index={{post._index}}&id={{post.id}}">
      {% endif %}
        <b>{{post.highlight.title|first|safe}}</b>
      </a>
    </span>
  </th></tr>
  <tbody>

    {% if p.field_list|length > 0 %}
    <tr><td>
    {% for field in p.field_list
        if field.id != "title"
          and field.id != "description"
          and post[field.id] %}

        <div class="col-lg-6 col-md-6">
          <label class="col-lg-4 col-md-4 control-label">{{field.name}}</label>
          <div class="col-lg-8 col-md-8">

            {% if field.list_tpl %}
              {{ field.list_tpl|render(p, post)|safe }}

            {% elif field.handler == "file" %}
              <a href="{{p.url}}/file/view/{{post[field.id]}}?id={{post.id}}" target=_blank>
                download
              </a>

            {% elif field.handler == "multiple" %}
              {% for v in post[field.id]|getlist %}
                {% if field.is_filter == "1" %}<a href="{{p.url}}?{{field.name}}={{v|strip}}">{% endif %}
                  {{v|strip}}
                {% if field.is_filter == "1" %}</a>{% endif %}
                {%- if not loop.last %}, {% endif %}

              {% endfor %}

            {% else %}
              {% if field.is_filter == "1" %}<a href="{{p.url}}?{{field.name}}={{ post[field.id] }}">{% endif %}
                {{ post[field.id] }}
              {% if field.is_filter == "1" %}</a>{% endif %}

            {%endif%}

          </div>
        </div>
    {%endfor%}
    </td></tr>
    {% endif %}

    {% if post.highlight.description or post.highlight.content %}
    <tr><td>
      {{post.highlight.description|first|safe}}
      {{post.highlight.content|first|safe}}
    </td></tr>
    {% endif %}

    <tr><td>
      {% if post.url %}
      <a href="{{post.url}}" target=_blank>{{post.url}}</a> -
      {% endif %}
      <small>{{post.created|dt}}</small>
    </td></tr>

  </tbody>
</table>

<br>
{% endmacro %}




{% block search_result %}

{% include "post/search/part/summary.html" %}
{% include "post/search/part/didyoumean.html" %}

{% for post in p.post_list %}
    {{ default(post) }}
{% endfor %}

{% include "post/search/part/pagination.html" %}

{# display create icon when post/create is allowed #}
{% if 'post/create' in p.allowed_operation %}
<div class="col-lg-12 text-right">
  <a href="{{p.url}}/post/create" title="new">
    <button type="button" class="btn btn-xs btn-danger">
      <span class="glyphicon glyphicon-plus"></span> New
    </button>
  </a>
</div>
{% endif %}


{% endblock %}
            """
        }
        es.create(host, 'search', 'config', config['name'], config)
Example #30
0
    # Post action
    if p['workflow'] and p['workflow'].get('postaction'):
        try:
            exec(p['workflow']['postaction'], globals())
            postaction(p)
        except SystemExit:
            pass
        except Exception, e:
            return "{}\n{}".format(e.message, traceback.format_exc())
    ######################################################

    ######################################################
    # notification
    if p['workflow']:
        notifications = es.list(
            host, index, 'notification',
            'workflow:{}'.format(p['workflow'].get('name')))
        for p['notification'] in notifications:
            p['notification']['recipients'] = jinja.getlist(
                p['notification'].get('recipients'))

            if p['notification'] and p['notification'].get('condition'):
                try:
                    exec(p['notification'].get('condition'), globals())
                    ret = condition(p)
                    if ret != True and ret: return ret
                except SystemExit:
                    pass
                except Exception, e:
                    return "{}\n{}".format(e.message, traceback.format_exc())