コード例 #1
0
ファイル: server.py プロジェクト: maebert/cnoms
def get_field_history(user, site, fieldname=None):
    """get the history of one field (for the history slider) (or for all - global slider)"""
    if fieldname:
        entries = Entry.select().where(Entry.user==user,
                                       Entry.site==site,
                                       Entry.fieldname==fieldname).order_by(Entry.created.desc())
    else:
        entries = Entry.select().where(Entry.user==user,
                                       Entry.site==site).order_by(Entry.created.desc())
    data = [{entry.fieldname: entry.value} for entry in entries]
    return json.dumps(data)
コード例 #2
0
ファイル: server.py プロジェクト: maebert/cnoms
def show_template(user, site, template=None, edit=False):
    """render a template with the latest content for an entry"""
    entries = Entry.select().where(Entry.user==user, Entry.site==site).order_by(Entry.created.desc())
    for e in entries:
        print e.fieldname, e.value.replace("\n", "")[:60]
    seen_entries = []
    simple_entries = []
    collections = {}
    items = {}
    for e in entries:
        identifier = "{}_{}".format(e.parent, e.fieldname)
        if not identifier in seen_entries:
            if e.type == "collection" and e.fieldname not in collections:
                collections[e.fieldname] = []
            elif e.type == "item":
                collections.get(e.parent, []).append(e.fieldname)
                items[e.fieldname] = {"__parent": e.parent, "__name": e.fieldname}
            elif e.parent:
                items.get(e.parent, {})[e.fieldname] = e.value
            else:
                simple_entries.append(e)
            seen_entries.append(identifier)

    data = {entry.fieldname: entry.value for entry in simple_entries}
    collections = {k: [items.get(item, {}) for item in kitems] for k, kitems in collections.items()}
    data.update(collections)

    templates_path = app.jinja_loader.searchpath[0]
    if not template:
        template = 'index.html'
    current_template_path = os.path.join(templates_path, user, site, template)
    if not os.path.exists(current_template_path):
        return 'Response(status_code=404)', 404
    template_string = open(current_template_path).read()
    return render_template_string(template_string, __user=user, __site=site, __template=template, cnoms_edit=edit, **data)
コード例 #3
0
ファイル: server.py プロジェクト: maebert/cnoms
def show_user(user):
    """show all information for a user"""
    leads = Entry.select().where(Entry.user==user).group_by(Entry.site)
    sites = []
    for site in leads:
        sites.append({
            "name": site.site,
            "user": site.user,
        })
    return render_template('show_user.html', sites=sites, user=user)
コード例 #4
0
ファイル: server.py プロジェクト: maebert/cnoms
def show_site_admin(user, site):
    """admin view for a site"""

    # get all templates
    templates_path = app.jinja_loader.searchpath[0]
    templates = glob.glob(os.path.join(templates_path, user, site, '*.html'))
    templates = [os.path.basename(t) for t in templates]

    # get all fieldnames
    fields = []
    entries = Entry.select().where(Entry.user==user, Entry.site==site).order_by(Entry.created.desc())
    for entry in entries:
        d = {'type': entry.type, 'fieldname': entry.fieldname, 'value': entry.value}
        if not d in fields:
            fields.append(d)
    return json.dumps({"templates": templates, "fields": fields})