Exemplo n.º 1
0
def show_counters(pif):
    pif.render.print_html()
    pif.restrict('a')
    pif.render.set_page_extra(pif.render.reset_button_js)

    res = pif.dbh.depref('counter', pif.dbh.fetch_counters())
    sortorder = pif.form.get_str('s', 'id')
    revorder = pif.form.get_int('r')
    res.sort(key=lambda x: x[sortorder])
    if revorder:
        res.reverse()

    columns = ['id', 'value', 'timestamp', 'health']
    headers = dict(zip(columns, ['ID', 'Value', 'Timestamp', 'Health']))
    lsection = dict(
        columns=columns,
        range=[{
            'entry': useful.printablize(res)
        }],
        note='',
        headers={
            col: pif.render.format_link(
                '?s=' + col +
                '&r=1' if col == sortorder and not revorder else '',
                headers[col])
            for col in columns
        })
    return pif.render.format_template('simplelistix.html',
                                      llineup=dict(section=[lsection]))
Exemplo n.º 2
0
    def pub_ent(pub):
	ret = pub.todict()
	ret.update(ret['base_id'])
	if not useful.search_match(sobj, ret['rawname']):
	    return None
	ret['name'] = '<a href="pub.cgi?id=%s">%s</a>' % (ret['id'], ret['rawname'].replace(';', ' '))
	ret['description'] = useful.printablize(ret['description'])
	if (os.path.exists(os.path.join(pif.render.pic_dir, ret['id'].lower() + '.jpg')) or
		glob.glob(os.path.join(pif.render.pic_dir, '?_' + ret['id'].lower() + '_*.jpg')) or
		glob.glob(os.path.join(pif.render.pic_dir, '?_' + ret['id'].lower() + '.jpg'))):
	    ret['picture'] = mbdata.comment_icon['c']
	return ret
Exemplo n.º 3
0
def single_publication(pif, pub_id):
    man = pif.dbh.fetch_publication(pub_id).first
    if not man:
	raise useful.SimpleError("That publication was not found.")
    # should just use man.section_id
    sec = get_section_by_model_type(pif, man.base_id.model_type)
    pif.set_page_info(sec.page_info.id)
    man['casting_type'] = 'Publication'
    man['name'] = man['base_id.rawname'].replace(';', ' ')
    imgs = pub_images(pif, pub_id.lower())
    relateds = make_relateds(pif, 'pub.' + mbdata.model_type_names[man['base_id.model_type']].lower(), pub_id, imgs)

    left_bar_content = ''
    if pif.is_allowed('a'):  # pragma: no cover
        left_bar_content += '<p><b><a href="%s">Base ID</a><br>\n' % pif.dbh.get_editor_link('base_id', {'id': pub_id})
        left_bar_content += '<a href="%s">Publication</a><br>\n' % pif.dbh.get_editor_link('publication', {'id': pub_id})
        left_bar_content += '<a href="traverse.cgi?d=%s">Library</a><br>\n' % pif.render.pic_dir.replace('pic', 'lib')
	left_bar_content += '<a href="upload.cgi?d=%s&n=%s&c=%s">Product Upload</a><br>\n' % (pif.render.pic_dir.replace('pic', 'lib'), pub_id, pub_id)

    upper_box = ''
    if imgs:
	upper_box += pif.render.format_image_link_image(imgs[0], link_largest=mbdata.IMG_SIZ_LARGE)
#    else:
#	upper_box += pif.render.format_image_link_image(img, link_largest=mbdata.IMG_SIZ_LARGE)
    if man['base_id.description']:
	upper_box += '<br>' if upper_box else ''
	upper_box += useful.printablize(man['base_id.description'])

    lran = [{'id': 'ran', 'entry':
	[{'text': pif.render.format_image_link_image(img[img.rfind('/') + 1:])} for img in sorted(imgs)] if imgs else
	[{'text': pif.render.format_image_link_image(pub_id)}]
    } if len(imgs) > 1 else {}]
    if relateds:
	lran.append({'id': 'related', 'entry': relateds, 'name': 'Related Models'})
    llineup = {'id': pub_id, 'name': '', 'section': [{'id': 'sec', 'range': lran, 'columns': 4}], 'columns': 4}

    pif.render.set_button_comment(pif, 'id=%s' % pub_id)
    pif.render.format_matrix_for_template(llineup)
    context = {
	'title': man.get('name', ''),
	'note': '',
	'type_id': 'p_' + sec.id,
	#'icon_id': pub_id,
	'vehicle_type': '',
	'rowspan': 5 if upper_box else 4,
	'left_bar_content': left_bar_content,
	'upper_box': upper_box,
	'llineup': llineup,
    }
    return pif.render.format_template('pub.html', **context)
Exemplo n.º 4
0
 def fmt_pub(ent, pdir=None):
     pdir = pdir if pdir else pic_dir
     ldir = pdir.replace('pic', 'lib')
     # ent: id, description, country, first_year, model_type
     cy, post = fmt_cy(ent)
     _, floc = pif.render.find_image_file(ent['id'], largest='e', pdir=pdir)
     _, lloc = pif.render.find_image_file(ent['id'], largest='e', pdir=ldir)
     # floc = pdir + '/' + ent['id'] + '.jpg'
     # lloc = floc.replace('/pic/', '/lib/')
     if floc:
         if ent['model_type']:
             url = 'pub.cgi?id=' + ent['id']
         else:
             url = '/' + pdir + '/' + floc
     else:
         url = '/' + ldir + '/' + lloc
     if not useful.search_match(sobj, ent['description']):
         return ''
     name = useful.printablize(ent['description'])
     if ent['first_year']:
         name += ' (' + ent['first_year'] + ')'
     if pif.is_allowed('ma'):
         if ent['model_type']:
             post += ' ' + pif.render.format_link(
                 pif.dbh.get_editor_link('publication', {'id': ent['id']}),
                 '<i class="fas fa-edit"></i>')
         else:
             post += ' ' + pif.render.format_link(
                 '/cgi-bin/mass.cgi?type=ads&id=%s&description=%s&year=%s&country=%s'
                 %
                 (ent['id'], useful.url_quote(
                     ent['description'], plus=True), ent['first_year'], cy),
                 '<i class="far fa-plus-square"></i>')
         if floc:
             post += ' ' + pif.render.format_link(
                 '/cgi-bin/imawidget.cgi?d=%s&f=%s' %
                 (pdir, floc), '<i class="fas fa-paint-brush"></i>')
         elif lloc:
             post += ' ' + pif.render.format_link(
                 '/cgi-bin/imawidget.cgi?d=%s&f=%s' %
                 (ldir, lloc), '<i class="fas fa-paint-brush"></i>')
         post += ' ' + pif.render.format_link(
             '/cgi-bin/upload.cgi?d=%s&n=%s' %
             (ldir, ent['id']), '<i class="fas fa-upload"></i>')
         name = ent['id'] + ' - ' + name
     if floc:
         return pif.render.format_link(url, name) + post
     return name + post
Exemplo n.º 5
0
def edit_multiple(pif, good=None):
    table_info = pif.dbh.table_info['link_line']
    page_id = ''
    sec_id = pif.form.get_str('sec', '')
    if pif.form.get_str('as'):
        linklines = pif.dbh.fetch_link_lines(flags=config.FLAG_LINK_LINE_ASSOCIABLE, order="display_order")
    elif sec_id == 'new':
        linklines = pif.dbh.fetch_link_lines(flags=config.FLAG_LINK_LINE_NEW)
    elif sec_id == 'nonf':
        linklines = pif.dbh.fetch_link_lines(
            where="last_status is not Null and last_status != 'H200' and link_type in ('l','s') "
                  "and page_id != 'links.rejects' and page_id != 'links.trash' and (flags & 32)=0")
    elif pif.form.get_str('stat'):
        wheres = ["page_id != 'links.rejects' and page_id != 'links.trash'" if good else
                  "page_id='links.rejects' or page_id='links.trash'",
                  "last_status is NULL" if pif.form.get_str('stat') == 'None' else
                  "last_status='%s'" % pif.form.get_str('stat')]
        linklines = pif.dbh.fetch_link_lines(where=wheres, order='id')
    elif sec_id:
        linklines = pif.dbh.fetch_link_lines(where="section_id='%s'" % sec_id, order="display_order")
        section = pif.dbh.fetch_section(sec_id)
        page_id = section['page_id']
    else:
        linklines = pif.dbh.fetch_link_lines(where="page_id='%s'" % pif.form.get_str('page_id'), order="display_order")
    pif.render.message(len(linklines), 'lines')

    entries = [{'text': col} for col in table_info['columns']]
    for link in linklines:
        pif.dbh.depref('link_line', link)
        for col in table_info['columns']:
            val = link.get(col, '')
            if col == 'id':
                entries.append({'text': '<a href="?id=' + str(val) + '">' + str(val) + '</a>'})
            elif col == 'url':
                entries.append({'text': '<a href="%s">%s</a>' % (val, val)})
            else:
                entries.append({'text': useful.printablize(val)})
    footer = pif.render.format_button("add", "edlinks.cgi?page_id=%s&sec=%s&add=1" % (page_id, sec_id))

    llineup = {
        'id': 'tl', 'name': 'Edit Link', 'columns': len(table_info['columns']),
        'section': [{'id': 's', 'name': '', 'range': [{'entry': entries}]}],
        'footer': footer,
    }
    pif.render.format_matrix_for_template(llineup)
    return pif.render.format_template('simplematrix.html', llineup=llineup)
Exemplo n.º 6
0
def show_counters(pif):
    pif.render.print_html()
    pif.restrict('a')
    pif.render.set_page_extra(pif.render.reset_button_js)

    res = pif.dbh.depref('counter', pif.dbh.fetch_counters())
    sortorder = pif.form.get_str('s', 'id')
    revorder = pif.form.get_int('r')
    res.sort(key=lambda x: x[sortorder])
    if revorder:
        res.reverse()

    columns = ['id', 'value', 'timestamp', 'health']
    headers = dict(zip(columns, ['ID', 'Value', 'Timestamp', 'Health']))
    lsection = dict(columns=columns, range=[{'entry': useful.printablize(res)}], note='',
	headers={col: pif.render.format_link('?s=' + col +
	'&r=1' if col == sortorder and not revorder else '', headers[col]) for col in columns})
    return pif.render.format_template('simplelistix.html', llineup=dict(section=[lsection]))
Exemplo n.º 7
0
 def pub_ent(pub):
     ret = pub.todict()
     ret.update(ret['base_id'])
     if not useful.search_match(sobj, ret['rawname']):
         return None
     ret['name'] = '<a href="pub.cgi?id=%s">%s</a>' % (
         ret['id'], ret['rawname'].replace(';', ' '))
     ret['description'] = useful.printablize(ret['description'])
     if (os.path.exists(
             os.path.join(pif.render.pic_dir, ret['id'].lower() + '.jpg'))
             or glob.glob(
                 os.path.join(pif.render.pic_dir,
                              '?_' + ret['id'].lower() + '_*.jpg'))
             or glob.glob(
                 os.path.join(pif.render.pic_dir,
                              '?_' + ret['id'].lower() + '.jpg'))):
         ret['picture'] = mbdata.comment_icon['c']
     return ret
Exemplo n.º 8
0
def edit_multiple(pif):
    table_info = pif.dbh.table_info['link_line']
    page_id = ''
    sec_id = pif.form.get_str('sec', '')
    if pif.form.get_bool('as'):
        linklines = pif.dbh.fetch_link_lines(flags=config.FLAG_LINK_LINE_ASSOCIABLE, order="display_order")
    elif sec_id == 'new':
        linklines = pif.dbh.fetch_link_lines(flags=config.FLAG_LINK_LINE_NEW)
    elif sec_id == 'nonf':
        linklines = pif.dbh.fetch_link_lines(where="last_status is not Null and last_status != 'H200' and link_type in ('l','s') and page_id != 'links.rejects' and page_id != 'links.trash' and (flags & 32)=0")
    elif pif.form.get_str('stat'):
	if pif.form.get_str('stat') == 'None':
	    linklines = pif.dbh.fetch_link_lines(where="last_status is NULL", order='id')
	else:
	    linklines = pif.dbh.fetch_link_lines(where="last_status='%s'" % pif.form.get_str('stat'), order='id')
    elif sec_id:
        linklines = pif.dbh.fetch_link_lines(where="section_id='%s'" % sec_id, order="display_order")
        section = pif.dbh.fetch_section(sec_id)
        page_id = section['page_id']
    else:
        linklines = pif.dbh.fetch_link_lines(where="page_id='%s'" % pif.form.get_str('page_id'), order="display_order")
    pif.render.message(len(linklines), 'lines')

    entries = [{'text': col} for col in table_info['columns']]
    for link in linklines:
	pif.dbh.depref('link_line', link)
	for col in table_info['columns']:
	    val = link.get(col, '')
	    if col == 'id':
		entries.append({'text': '<a href="?id=' + str(val) + '">' + str(val) + '</a>'})
	    elif col == 'url':
		entries.append({'text': '<a href="%s">%s</a>' % (val, val)})
	    else:
		entries.append({'text': useful.printablize(val)})
    footer = pif.render.format_button("add", "edlinks.cgi?page_id=%s&sec=%s&add=1" % (page_id, sec_id))

    llineup = {'id': 'tl', 'name': 'Edit Link', 'columns': len(table_info['columns']),
	'section': [{'id': 's', 'name': '',
	    'range': [{'entry': entries}]}],
	'footer': footer,
    }
    pif.render.format_matrix_for_template(llineup)
    return pif.render.format_template('simplematrix.html', llineup=llineup)
Exemplo n.º 9
0
 def fmt_pub(ent, pdir=None):
     pdir = pdir if pdir else pic_dir
     # ent: id, description, country, first_year, model_type
     cy, post = fmt_cy(ent)
     floc = '.' + pdir + '/' + ent['id'] + '.jpg'
     lloc = floc.replace('/pic/', '/lib/')
     url = pdir + '/' + ent['id'] + '.jpg'
     name = useful.printablize(ent['description'])
     if ent.get('first_year'):
         name += ' (' + ent['first_year'] + ')'
     if pif.is_allowed('ma'):
         if ent.get('model_type'):
             post += ' ' + pif.render.format_link(
                 pif.dbh.get_editor_link('publication', {'id': ent['id']}),
                 '<i class="fas fa-edit"></i>')
         else:
             post += ' ' + pif.render.format_link(
                 '/cgi-bin/mass.cgi?type=ads&id=%s&description=%s&year=%s&country=%s'
                 % (ent['id'], urllib.quote_plus(
                     ent['description']), ent.get('first_year', ''), cy),
                 '<i class="far fa-plus-square"></i>')
         if os.path.exists(floc):
             post += ' ' + pif.render.format_link(
                 '/cgi-bin/imawidget.cgi?d=.%s&f=%s' %
                 (pdir, ent['id'] + '.jpg'),
                 '<i class="fas fa-paint-brush"></i>')
         elif os.path.exists(lloc):
             post += ' ' + pif.render.format_link(
                 '/cgi-bin/imawidget.cgi?d=.%s&f=%s' %
                 (pdir.replace('pic', 'lib'), ent['id'] + '.jpg'),
                 '<i class="fas fa-paint-brush"></i>')
         post += ' ' + pif.render.format_link(
             '/cgi-bin/upload.cgi?d=.%s&n=%s' %
             (lib_dir, ent['id'] + '.jpg'), '<i class="fas fa-upload"></i>')
         name = ent['id'] + ' - ' + name
     files.append(ent['id'] + '.jpg')
     if os.path.exists(floc):
         return pif.render.format_link(url, name) + post
     return name + post
Exemplo n.º 10
0
    def fmt_pub(ent, pdir=None):
	pdir = pdir if pdir else pic_dir
	ldir = pdir.replace('pic', 'lib')
	# ent: id, description, country, first_year, model_type
	cy, post = fmt_cy(ent)
	_, floc = pif.render.find_image_file(ent['id'], largest='e', pdir=pdir)
	_, lloc = pif.render.find_image_file(ent['id'], largest='e', pdir=ldir)
	#floc = pdir + '/' + ent['id'] + '.jpg'
	#lloc = floc.replace('/pic/', '/lib/')
	if floc:
	    if ent['model_type']:
		url = 'pub.cgi?id=' + ent['id']
	    else:
		url = '/' + pdir + '/' + floc
	else:
	    url = '/' + ldir + '/' + lloc
	if not useful.search_match(sobj, ent['description']):
	    return ''
	name = useful.printablize(ent['description'])
	if ent['first_year']:
	    name += ' (' + ent['first_year'] + ')'
	if pif.is_allowed('ma'):
	    if ent['model_type']:
		post += ' ' + pif.render.format_link(pif.dbh.get_editor_link('publication', {'id': ent['id']}), '<i class="fas fa-edit"></i>')
	    else:
		post += ' ' + pif.render.format_link(
'/cgi-bin/mass.cgi?type=ads&id=%s&description=%s&year=%s&country=%s' % (ent['id'], useful.url_quote(ent['description'], plus=True), ent['first_year'], cy)
, '<i class="far fa-plus-square"></i>'
)
	    if floc:
		post += ' ' + pif.render.format_link('/cgi-bin/imawidget.cgi?d=%s&f=%s' % (pdir, floc), '<i class="fas fa-paint-brush"></i>')
	    elif lloc:
		post += ' ' + pif.render.format_link('/cgi-bin/imawidget.cgi?d=%s&f=%s' % (ldir, lloc), '<i class="fas fa-paint-brush"></i>')
	    post += ' ' + pif.render.format_link('/cgi-bin/upload.cgi?d=%s&n=%s' % (ldir, ent['id']), '<i class="fas fa-upload"></i>')
	    name = ent['id'] + ' - ' + name
	if floc:
	    return pif.render.format_link(url, name) + post
	return name + post
Exemplo n.º 11
0
def edit_single(pif):
    listCats, listIndices, dictCats, listRejectCats = read_config(pif, True)
    listCats.append(('single', 'single'))
    table_info = pif.dbh.table_info['link_line']
    link_id = pif.form.get_str('id')
    if pif.form.get_bool('save'):
        all_links, highest_disp_order = read_all_links(pif)
        nlink = {x: pif.form.get_str(x) for x in table_info['columns']}
        nlink['flags'] = 0
        if pif.form.get_str('section_id') == 'single':
            pass
        else:
            nlink['page_id'] = 'links.' + dictCats.get(pif.form.get_str('section_id', ''), pif.form.get_str('section_id', ''))
        nlink['display_order'] = highest_disp_order.get((nlink['page_id'], nlink['section_id']), 0) + 1
        for flag in pif.form.get_list('flags'):
            nlink['flags'] += int(flag, 16)
        if nlink['flags'] & config.FLAG_LINK_LINE_NOT_VERIFIABLE:
            nlink['last_status'] = 'NoVer'
        pif.dbh.update_link_line(nlink)
        pif.render.message('<br>record saved<br>')
    elif pif.form.get_bool('test'):
        link = pif.dbh.fetch_link_line(link_id)[0]
        check_link(pif, link)  # don't care about blacklist here, just actual check
    elif pif.form.get_bool('delete'):
        pif.dbh.delete_link_line(link_id)
        return "<br>deleted<br>"
    elif pif.form.get_bool('reject'):
        nlink = {x: pif.form.get_str(x, '') for x in table_info['columns']}
        nlink['page_id'] = 'links.rejects'
        nlink['display_order'] = 1
        nlink['section_id'] = pif.form.get_str('rejects_sec')
        nlink['flags'] = 0
        pif.dbh.update_link_line(nlink)
        pif.render.message('<br>record rejected<br>')
    elif pif.form.get_bool('add'):
        link_id = (#pif.dbh.insert_link_line({'page_id': pif.form.get_str('page_id', ''), 'section_id': pif.form.get_str('sec')})
#        pif.form.set_val('id',
	    pif.dbh.insert_link_line({'page_id': pif.form.get_str('page_id'), 'country': '', 'flags': 1, 'link_type': 'l'}))

    links = pif.dbh.fetch_link_lines(where="id='%s'" % link_id)
    if not links:
	raise useful.SimpleError("That ID wasn't found.")
    link = links[0]
    asslinks = [(0, '')] + [(x['link_line.id'], x['link_line.name']) for x in pif.dbh.fetch_link_lines(flags=config.FLAG_LINK_LINE_ASSOCIABLE)]
    descs = pif.dbh.describe_dict('link_line')

    header = '<form>' + pif.create_token()
    header += '<input type="hidden" name="o_id" value="%s">\n' % link['link_line.id']

    entries = []
    for col in table_info['columns']:
	col_long = 'link_line.' + col
	coltype = descs.get(col).get('type', 'unknown')
	value = useful.printablize(link.get(col_long, ''))
	entries.append({'text': col})
#	entries.append({'text': '<a href="%s">%s</a>' % (link.get(col_long, ''), link.get(col_long, ''))
#			if col == 'url' else link[col_long]})
	entries.append({'text': '<a href="%s">%s</a>' % (value, value) if col == 'url' else value})
	if col in table_info.get('readonly', []):
	    cell = '&nbsp;<input type="hidden" name="%s" value="%s">' % (col, value)
#       elif col == 'page_id':
#           cell = '&nbsp;<input type="hidden" name="%s" value="%s">' % (col, value)
	elif col == 'section_id':
	    cell = pif.render.format_select('section_id', listCats, selected=value, blank='Please choose one from the list')
	elif col == 'flags':
	    cell = pif.render.format_checkbox("flags", flag_check_names, useful.bit_list(link[col_long]))
	elif col == 'country':
	    cell = pif.render.format_select_country('country', value)
	elif col == 'link_type':
	    cell = pif.render.format_select(col, link_type_names, selected=value)
	elif col == 'associated_link':
	    cell = pif.render.format_select(col, asslinks, selected=value)
	elif coltype.startswith('varchar('):
	    colwidth = int(coltype[8:-1])
	    cell = pif.render.format_text_input(col, colwidth, 64, value=value)
	elif coltype.startswith('int('):
	    if link[col_long] is None:
		value = 0
	    colwidth = int(coltype[4:-1])
	    cell = pif.render.format_text_input(col, colwidth, value=value)
	else:
	    cell = coltype
	entries.append({'text': cell})

    footer = ''.join([
	pif.render.format_button_input("save"),
	pif.render.format_button_input("delete"),
	pif.render.format_button_input("test"),
	pif.render.format_button_input("reject"),
	pif.render.format_select('rejects_sec', listRejectCats, blank='Please choose one from the list'),
	'</form>',
	pif.render.format_button("edit", link=pif.dbh.get_editor_link('link_line', {'id': link_id})),
    ])

    llineup = {'id': 'tl', 'name': 'Edit Link', 'columns': 3, 'widthauto': True,
	'section': [{'id': 's', 'name': '',
	    'range': [{'entry': entries}]}],
	'header': header, 'footer': footer,
    }
    pif.render.format_matrix_for_template(llineup)
    return pif.render.format_template('simplematrix.html', llineup=llineup)
Exemplo n.º 12
0
def edit_single(pif):
    listCats, listIndices, dictCats, listRejectCats = read_config(pif, True)
    listCats.append(('single', 'single'))
    table_info = pif.dbh.table_info['link_line']
    link_id = pif.form.get_str('id')
    if pif.form.get_str('save'):
        all_links, highest_disp_order = read_all_links(pif)
        nlink = {x: pif.form.get_str(x) for x in table_info['columns']}
        nlink['flags'] = 0
        if pif.form.get_str('section_id') == 'single':
            pass
        else:
            nlink['page_id'] = 'links.' + dictCats.get(
                pif.form.get_str('section_id', ''), pif.form.get_str('section_id', ''))
        nlink['display_order'] = highest_disp_order.get((nlink['page_id'], nlink['section_id']), 0) + 1
        for flag in pif.form.get_list('flags'):
            nlink['flags'] += int(flag, 16)
        if nlink['flags'] & config.FLAG_LINK_LINE_NOT_VERIFIABLE:
            nlink['last_status'] = 'NoVer'
        pif.dbh.update_link_line(nlink)
        pif.render.message('<br>record saved<br>')
    elif pif.form.get_str('test'):
        link = pif.dbh.fetch_link_line(link_id)[0]
        check_link(pif, link)  # don't care about blacklist here, just actual check
    elif pif.form.get_str('delete'):
        pif.dbh.delete_link_line(link_id)
        return "<br>deleted<br>"
    elif pif.form.get_str('reject'):
        nlink = {x: pif.form.get_str(x, '') for x in table_info['columns']}
        nlink['page_id'] = 'links.rejects'
        nlink['display_order'] = 1
        nlink['section_id'] = pif.form.get_str('rejects_sec')
        nlink['flags'] = 0
        pif.dbh.update_link_line(nlink)
        pif.render.message('<br>record rejected<br>')
    elif pif.form.get_str('add'):
        link_id = (
            # pif.dbh.insert_link_line(
            #     {'page_id': pif.form.get_str('page_id', ''), 'section_id': pif.form.get_str('sec')})
            # pif.form.set_val('id',
            pif.dbh.insert_link_line(
                {'page_id': pif.form.get_str('page_id'), 'country': '', 'flags': 1, 'link_type': 'l'}))

    links = pif.dbh.fetch_link_lines(where="id='%s'" % link_id)
    if not links:
        raise useful.SimpleError("That ID wasn't found.")
    link = links[0]
    asslinks = [(0, '')] + [(x['link_line.id'], x['link_line.name'])
                            for x in pif.dbh.fetch_link_lines(flags=config.FLAG_LINK_LINE_ASSOCIABLE)]
    descs = pif.dbh.describe_dict('link_line')

    header = '<form>' + pif.create_token()
    header += '<input type="hidden" name="o_id" value="%s">\n' % link['link_line.id']

    entries = []
    for col in table_info['columns']:
        col_long = 'link_line.' + col
        coltype = descs.get(col).get('type', 'unknown')
        value = useful.printablize(link.get(col_long, ''))
        entries.append({'text': col})
        # entries.append({'text': '<a href="%s">%s</a>' % (link.get(col_long, ''), link.get(col_long, ''))
        #                if col == 'url' else link[col_long]})
        entries.append({'text': '<a href="%s">%s</a>' % (value, value) if col == 'url' else value})
        if col in table_info.get('readonly', []):
            cell = '&nbsp;<input type="hidden" name="%s" value="%s">' % (col, value)
        # elif col == 'page_id':
        #     cell = '&nbsp;<input type="hidden" name="%s" value="%s">' % (col, value)
        elif col == 'section_id':
            cell = pif.render.format_select(
                'section_id', listCats, selected=value, blank='Please choose one from the list')
        elif col == 'flags':
            cell = pif.render.format_checkbox("flags", flag_check_names, useful.bit_list(link[col_long]))
        elif col == 'country':
            cell = pif.render.format_select_country('country', value)
        elif col == 'link_type':
            cell = pif.render.format_select(col, link_type_names, selected=value)
        elif col == 'associated_link':
            cell = pif.render.format_select(col, asslinks, selected=value)
        elif coltype.startswith('varchar('):
            colwidth = int(coltype[8:-1])
            cell = pif.render.format_text_input(col, colwidth, 64, value=value)
        elif coltype.startswith('int('):
            if link[col_long] is None:
                value = 0
            colwidth = int(coltype[4:-1])
            cell = pif.render.format_text_input(col, colwidth, value=value)
        else:
            cell = coltype
        entries.append({'text': cell})

    footer = ''.join([
        pif.render.format_button_input("save"),
        pif.render.format_button_input("delete"),
        pif.render.format_button_input("test"),
        pif.render.format_button_input("reject"),
        pif.render.format_select('rejects_sec', listRejectCats, blank='Please choose one from the list'),
        '</form>',
        pif.render.format_button("edit", link=pif.dbh.get_editor_link('link_line', {'id': link_id})),
    ])

    llineup = {
        'id': 'tl', 'name': 'Edit Link', 'columns': 3, 'widthauto': True,
        'section': [{'id': 's', 'name': '', 'range': [{'entry': entries}]}],
        'header': header, 'footer': footer,
    }
    pif.render.format_matrix_for_template(llineup)
    return pif.render.format_template('simplematrix.html', llineup=llineup)
Exemplo n.º 13
0
def single_publication(pif, pub_id):
    man = pif.dbh.fetch_publication(pub_id).first
    if not man:
        raise useful.SimpleError("That publication was not found.")
    pif.render.pic_dir = picdirs.get(man.base_id.model_type,
                                     pif.render.pic_dir)
    # should just use man.section_id
    sec = get_section_by_model_type(pif, man.base_id.model_type)
    # pif.set_page_info(sec.page_info.id)  # obviously not right but I don't know what is.
    man['casting_type'] = 'Publication'
    man['name'] = man['base_id.rawname'].replace(';', ' ')
    imgs = pub_images(pif, pub_id.lower())
    relateds = make_relateds(
        pif,
        'pub.' + mbdata.model_type_names[man['base_id.model_type']].lower(),
        pub_id, imgs)

    left_bar_content = ''
    if pif.is_allowed('a'):  # pragma: no cover
        left_bar_content += '<p><b><a href="%s">Base ID</a><br>\n' % pif.dbh.get_editor_link(
            'base_id', {'id': pub_id})
        left_bar_content += '<a href="%s">Publication</a><br>\n' % pif.dbh.get_editor_link(
            'publication', {'id': pub_id})
        left_bar_content += '<a href="traverse.cgi?d=%s">Library</a><br>\n' % pif.render.pic_dir.replace(
            'pic', 'lib')
        left_bar_content += '<a href="upload.cgi?d=%s&n=%s&c=%s">Product Upload</a><br>\n' % (
            pif.render.pic_dir.replace('pic', 'lib'), pub_id, pub_id)

    upper_box = ''
    if imgs:
        upper_box += pif.render.format_image_link_image(
            imgs[0], link_largest=mbdata.IMG_SIZ_LARGE)
    # else:
    #     upper_box += pif.render.format_image_link_image(img, link_largest=mbdata.IMG_SIZ_LARGE)
    if man['base_id.description']:
        upper_box += '<br>' if upper_box else ''
        upper_box += useful.printablize(man['base_id.description'])

    lran = [{
        'id':
        'ran',
        'entry':
        [{
            'text': pif.render.format_image_link_image(img[img.rfind('/') +
                                                           1:])
        } for img in sorted(imgs)] if imgs else [{
            'text':
            pif.render.format_image_link_image(pub_id)
        }]
    } if len(imgs) > 1 else {}]
    if relateds:
        lran.append({
            'id': 'related',
            'entry': relateds,
            'name': 'Related Models'
        })
    llineup = {
        'id': pub_id,
        'name': '',
        'section': [{
            'id': 'sec',
            'range': lran,
            'columns': 4
        }],
        'columns': 4
    }

    pif.render.set_button_comment(pif, 'id=%s' % pub_id)
    pif.render.format_matrix_for_template(llineup)
    context = {
        'title': man.get('name', ''),
        'note': '',
        'type_id': 'p_' + sec.id,
        # 'icon_id': pub_id,
        'vehicle_type': '',
        'rowspan': 5 if upper_box else 4,
        'left_bar_content': left_bar_content,
        'upper_box': upper_box,
        'llineup': llineup,
    }
    return pif.render.format_template('pub.html', **context)