def make_adds(pif, mod_id, var_id=''): photo_credits = {x['photo_credit.name']: x['photographer.name'] for x in pif.dbh.fetch_photo_credits(path='.' + config.IMG_DIR_ADD)} attribute_pictures = pif.dbh.fetch_attribute_pictures(mod_id) attribute_pictures = dict([ (x['attribute_picture.attr_type'].lower() + '_' + x['attribute_picture.mod_id'].lower() + '-' + x['attribute_picture.picture_id'] + '.', x) for x in attribute_pictures if x['attribute_picture.picture_id']]) img_id = (mod_id + ('-' + var_id if var_id else '')).lower() pdir = '.' + (config.IMG_DIR_VAR if var_id else config.IMG_DIR_ADD) adds = var_adds if var_id else mbdata.model_adds outd = [] for add in adds: imgs = pif.render.find_image_list(img_id, wc='-*', prefix=add[0], pdir=pdir) if imgs: elem = {'title': add[1] % {'s': useful.plural(imgs)}, 'entry': [], 'columns': add[3]} for img in imgs: fn = img[:img.find('.')] ent = {'img': pif.render.fmt_img_src(pdir + '/' + img), 'credit': photo_credits.get(fn, '')} for apic in attribute_pictures: # This is terrible and I'm a terrible person but I don't want to think too much right now. if apic in img and attribute_pictures[apic]['attribute_picture.description']: if attribute_pictures[apic]['attribute.title']: ent['desc'] = "%(attribute.title)s: %(attribute_picture.description)s" % attribute_pictures[apic] else: ent['desc'] = "%(attribute_picture.description)s" % attribute_pictures[apic] elem['entry'].append(ent) outd.append(elem) return outd
def make_boxes(pif, mod_id, box_types, mack_nums): mod_id = box_types[0]['box_type.mod_id'] base_box_types = [box['box_type.box_type'][0] for box in box_types] box_fmt = "<b>%s style box</b><br>%s" #<br>%s entries" # rewrite this. glob for alternate boxes. well, maybe. entries = [{ 'desc': pif.render.format_link('boxart.cgi', txt='%s style box' % box_type, args={ 'mod': mod_id, 'ty': box_type }), 'img': pif.render.format_link('boxart.cgi', txt=pif.render.format_image_sized( [mod_id + '-' + box_type], pdir=config.IMG_DIR_BOX, required=True), args={ 'mod': mod_id, 'ty': box_type }), } for box_type in sorted(list(set(base_box_types)))] elem = { 'title': 'Box Style%(s)s' % { 's': useful.plural(entries) }, 'entry': entries, 'columns': 2 } return elem
def show_adds(pif, mod_id, var_id=''): photo_credits = {x['photo_credit.name']: x['photographer.name'] for x in pif.dbh.fetch_photo_credits(path='.' + config.IMG_DIR_ADD)} attribute_pictures = pif.dbh.fetch_attribute_pictures(mod_id) attribute_pictures = dict([ (x['attribute_picture.attr_type'].lower() + '_' + x['attribute_picture.mod_id'].lower() + '-' + x['attribute_picture.picture_id'] + '.', x) for x in attribute_pictures if x['attribute_picture.picture_id']]) img_id = (mod_id + ('-' + var_id if var_id else '')).lower() pdir = '.' + (config.IMG_DIR_VAR if var_id else config.IMG_DIR_ADD) adds = var_adds if var_id else mbdata.model_adds ostr = '' for add in adds: imgs = pif.render.find_image_list(img_id, wc='-*', prefix=add[0], pdir=pdir) if imgs: ostr += '<h3>%s</h3>\n' % add[1] % {'s': useful.plural(imgs)} for img in imgs: ostr += '<table><tr><td class="center">' ostr += pif.render.fmt_img_src(pdir + '/' + img) + '<br>' fn = img[:img.find('.')] if fn in photo_credits: ostr += '<div class="credit">Photo credit: %s</div>' % photo_credits[fn] for apic in attribute_pictures: # This is terrible and I'm a terrible person but I don't want to think too much right now. if apic in img and attribute_pictures[apic]['attribute_picture.description']: if attribute_pictures[apic]['attribute.title']: ostr += "%(attribute.title)s: %(attribute_picture.description)s" % attribute_pictures[apic] else: ostr += "%(attribute_picture.description)s" % attribute_pictures[apic] ostr += '</td></tr></table>' ostr += '<p>\n' return ostr
def add_new_link(pif, dictCats, listRejects): reasons = [] ostr = "<hr>" #'columns': ['id', 'page_id', 'section_id', 'display_order', 'flags', 'link_type', 'country', 'url', 'name', 'description', 'note'], all_links, highest_disp_order = read_all_links(pif) link = {} try: link['url'] = url = pif.form.get_str('url', '') link['section_id'] = pif.form.get_str('cat', '') link['page_id'] = 'links.' + dictCats[link['section_id']] link['display_order'] = highest_disp_order[(link.get('page_id', 'unknown'), link.get('section_id', 'unknown'))] + 1 except: reasons.extend([ "Some information was missing.", "The request was badly formed.", "The request was not made by the supplied web form."]) link['flags'] = config.FLAG_LINK_LINE_NEW if pif.is_allowed('a'): # pragma: no cover link['flags'] = 0 link['link_type'] = 'l' link['name'] = pif.form.get_str('name', '') link['country'] = pif.form.get_str('country', '') link['description'] = pif.form.get_str('desc', '') link['note'] = pif.remote_addr + '/' + pif.remote_host + '. ' + pif.form.get_str('note', '') url = fix_url(url) for reject in listRejects: if url.find(reject) >= 0: reasons.append("The URL is on a banned list.") if url in all_links and not pif.form.get('dup'): reasons.append("The site has already been submitted.") if url.find('://') < 0: reasons.append("The URL is not properly formed.") if (link['description'].find('<') >= 0) or (link['name'].find('<') >= 0): reasons.extend("The description text or the notes text contains HTML.") if (link['description'].find('\n') >= 0) or (link['name'].find('\n') >= 0): reasons.extend([ "The request was badly formed.", "The request was not made by the supplied web form."]) if link['country'] == 'US': link['country'] = '' #str = 'l|' + url + '|' + tag + '|' + dlm + '|' + cmt if reasons: ostr += "<b>The site submitted is being rejected. Sorry.</b><br>\n" ostr += "Possible reason%s:<ul>\n" % useful.plural(reasons) for reason in reasons: ostr += "<li>" + reason + '\n' ostr += "</ul>If your submission has to do with sex, drugs, hotel reservations or ringtones, please go away and never come back. Seriously.<p>\n" ostr += "Feel free to use your browser's BACK button to fix your entry, then resubmit; or,\n" ostr += "if you think this rejection was in error, you can send email. Just don't hope for too much.\n" open(os.path.join(config.LOG_ROOT, 'trash.log'), 'a+').write(str(link) + '\n') else: link['id'] = pif.dbh.insert_link_line(link) ostr += "Your suggestion has been sent to the site administrators. Thank you.<br>" check_link(pif, link) return ostr
def do_tree_page(pif, dblist): ostr = '' for llist in dblist: cmd = llist.get_arg() if cmd == 'dir': pif.render.pic_dir = llist.get_arg() elif cmd == 'render': ostr += useful.render_file(pif.render.pic_dir + '/' + llist.get_arg()) elif cmd == 'p': ostr += '<p>\n' elif cmd == 's': ostr += '<p>\n<b id="%s"><u>' % llist[1] if llist[2]: ostr += ' %s - ' % llist[2] ostr += '%s</u></b><br>\n' % llist[3] elif cmd == 'm': desc = '' if llist[2]: desc += ('<b>%s</b> ' % llist[2]) if llist[3] and not llist[3][0].isupper(): desc += " - " desc += llist[3] if llist[1].endswith('p'): desc = '<b>%s</b>' % desc #ostr += render_tree(pif, llist[1]) + desc #ostr += '<br>\n' ostr += tree_row(render_tree(pif, llist[1]), desc) elif cmd == 'n': ostr += tree_row( render_tree(pif, llist[1]), '<font color="#666600"><i>%s</i></font>' % llist[2]) elif cmd == 'a': ostr += tree_row( render_tree(pif, llist[1]), pif.render.format_image_as_link([llist[2]], llist[3], also={'target': '_showpic'})) elif cmd == 'e': flist = sorted( glob.glob(pif.render.pic_dir + '/' + llist[2] + "*.jpg")) if flist: ostr += '<font color="blue">' ostr += tree_row(render_tree( pif, llist[1]), ('<i>Example%s:</i>\n' % useful.plural(flist)) + show_pic(pif, flist)) ostr += '</font>\n' return ostr
def make_adds(pif, mod_id, var_id=''): photo_credits = { x['photo_credit.name']: x['photographer.name'] for x in pif.dbh.fetch_photo_credits(path='.' + config.IMG_DIR_ADD) } attribute_pictures = pif.dbh.fetch_attribute_pictures(mod_id) attribute_pictures = dict([ (x['attribute_picture.attr_type'].lower() + '_' + x['attribute_picture.mod_id'].lower() + '-' + x['attribute_picture.picture_id'] + '.', x) for x in attribute_pictures if x['attribute_picture.picture_id'] ]) img_id = (mod_id + ('-' + var_id if var_id else '')).lower() pdir = '.' + (config.IMG_DIR_VAR if var_id else config.IMG_DIR_ADD) adds = var_adds if var_id else mbdata.model_adds outd = [] for add in adds: imgs = pif.render.find_image_list(img_id, wc='-*', prefix=add[0], pdir=pdir) if imgs: elem = { 'title': add[1] % { 's': useful.plural(imgs) }, 'entry': [], 'columns': add[3] } for img in imgs: fn = img[:img.find('.')] ent = { 'img': pif.render.fmt_img_src(pdir + '/' + img), 'credit': photo_credits.get(fn, '') } for apic in attribute_pictures: # This is terrible and I'm a terrible person but I don't want to think too much right now. if apic in img and attribute_pictures[apic][ 'attribute_picture.description']: if attribute_pictures[apic]['attribute.title']: ent['desc'] = "%(attribute.title)s: %(attribute_picture.description)s" % attribute_pictures[ apic] else: ent['desc'] = "%(attribute_picture.description)s" % attribute_pictures[ apic] elem['entry'].append(ent) outd.append(elem) return outd
def make_boxes(pif, mod_id, box_types, mack_nums): mod_id = box_types[0]['box_type.mod_id'] base_box_types = [box['box_type.box_type'][0] for box in box_types] box_fmt = "<b>%s style box</b><br>%s" #<br>%s entries" # rewrite this. glob for alternate boxes. well, maybe. entries = [ {'desc': pif.render.format_link('boxart.cgi', txt='%s style box' % box_type, args={'mod': mod_id, 'ty': box_type}), 'img': pif.render.format_link('boxart.cgi', txt=pif.render.format_image_sized([mod_id + '-' + box_type], pdir=config.IMG_DIR_BOX, required=True), args={'mod': mod_id, 'ty': box_type}), } for box_type in sorted(list(set(base_box_types)))] elem = {'title': 'Box Style%(s)s' % {'s': useful.plural(entries)}, 'entry': entries, 'columns': 2} return elem
def show_adds(pif, mod_id, var_id=''): photo_credits = { x['photo_credit.name']: x['photographer.name'] for x in pif.dbh.fetch_photo_credits(path='.' + config.IMG_DIR_ADD) } attribute_pictures = pif.dbh.fetch_attribute_pictures(mod_id) attribute_pictures = dict([ (x['attribute_picture.attr_type'].lower() + '_' + x['attribute_picture.mod_id'].lower() + '-' + x['attribute_picture.picture_id'] + '.', x) for x in attribute_pictures if x['attribute_picture.picture_id'] ]) img_id = (mod_id + ('-' + var_id if var_id else '')).lower() pdir = '.' + (config.IMG_DIR_VAR if var_id else config.IMG_DIR_ADD) adds = var_adds if var_id else mbdata.model_adds ostr = '' for add in adds: imgs = pif.render.find_image_list(img_id, wc='-*', prefix=add[0], pdir=pdir) if imgs: ostr += '<h3>%s</h3>\n' % add[1] % {'s': useful.plural(imgs)} for img in imgs: ostr += '<table><tr><td class="center">' ostr += pif.render.fmt_img_src(pdir + '/' + img) + '<br>' fn = img[:img.find('.')] if fn in photo_credits: ostr += '<div class="credit">Photo credit: %s</div>' % photo_credits[ fn] for apic in attribute_pictures: # This is terrible and I'm a terrible person but I don't want to think too much right now. if apic in img and attribute_pictures[apic][ 'attribute_picture.description']: if attribute_pictures[apic]['attribute.title']: ostr += "%(attribute.title)s: %(attribute_picture.description)s" % attribute_pictures[ apic] else: ostr += "%(attribute_picture.description)s" % attribute_pictures[ apic] ostr += '</td></tr></table>' ostr += '<p>\n' return ostr
def do_tree_page(pif, dblist): ostr = '' for llist in dblist: cmd = llist.get_arg() if cmd == 'dir': pif.render.pic_dir = llist.get_arg() elif cmd == 'render': ostr += useful.render_file(pif.render.pic_dir + '/' + llist.get_arg()) elif cmd == 'p': ostr += '<p>\n' elif cmd == 's': ostr += '<p>\n<b id="%s"><u>' % llist[1] if llist[2]: ostr += ' %s - ' % llist[2] ostr += '%s</u></b><br>\n' % llist[3] elif cmd == 'm': desc = '' if llist[2]: desc += ('<b>%s</b> ' % llist[2]) if llist[3] and not llist[3][0].isupper(): desc += " - " desc += llist[3] if llist[1].endswith('p'): desc = '<b>%s</b>' % desc #ostr += render_tree(pif, llist[1]) + desc #ostr += '<br>\n' ostr += tree_row(render_tree(pif, llist[1]), desc) elif cmd == 'n': ostr += tree_row(render_tree(pif, llist[1]), '<font color="#666600"><i>%s</i></font>' % llist[2]) elif cmd == 'a': ostr += tree_row(render_tree(pif, llist[1]), pif.render.format_image_as_link([llist[2]], llist[3], also={'target': '_showpic'})) elif cmd == 'e': flist = sorted(glob.glob(pif.render.pic_dir + '/' + llist[2] + "*.jpg")) if flist: ostr += '<font color="blue">' ostr += tree_row(render_tree(pif, llist[1]), ('<i>Example%s:</i>\n' % useful.plural(flist)) + show_pic(pif, flist)) ostr += '</font>\n' return ostr
def add_new_link(pif, dictCats, listRejects): reasons = [] ostr = "<hr>" # columns: [id page_id section_id display_order flags link_type country url name description note] all_links, highest_disp_order = read_all_links(pif) link = {} try: link['url'] = url = pif.form.get_str('url', '') link['section_id'] = pif.form.get_str('cat', '') link['page_id'] = 'links.' + dictCats[link['section_id']] link['display_order'] = highest_disp_order[ (link.get('page_id', 'unknown'), link.get('section_id', 'unknown'))] + 1 except Exception: reasons.extend([ "Some information was missing.", "The request was badly formed.", "The request was not made by the supplied web form."]) link['flags'] = config.FLAG_LINK_LINE_NEW if pif.is_allowed('a'): # pragma: no cover link['flags'] = 0 link['link_type'] = 'l' link['name'] = pif.form.get_str('name', '') link['country'] = pif.form.get_str('country', '') link['description'] = pif.form.get_str('desc', '') link['note'] = pif.remote_addr + '/' + pif.remote_host + '. ' + pif.form.get_str('note', '') url = fix_url(url) for reject in listRejects: if url.find(reject) >= 0: reasons.append("The URL is on a banned list.") if url in all_links and not pif.form.get('dup'): reasons.append("The site has already been submitted.") if url.find('://') < 0: reasons.append("The URL is not properly formed.") if (link['description'].find('<') >= 0) or (link['name'].find('<') >= 0): reasons.extend("The description text or the notes text contains HTML.") if (link['description'].find('\n') >= 0) or (link['name'].find('\n') >= 0): reasons.extend([ "The request was badly formed.", "The request was not made by the supplied web form."]) if link['country'] == 'US': link['country'] = '' # str = 'l|' + url + '|' + tag + '|' + dlm + '|' + cmt if reasons: ostr += "<b>The site submitted is being rejected. Sorry.</b><br>\n" ostr += "Possible reason%s:<ul>\n" % useful.plural(reasons) for reason in reasons: ostr += "<li>" + reason + '\n' ostr += ( "</ul>If your submission has to do with sex, drugs, hotel reservations or ringtones, " "please go away and never come back. Seriously.<p>\n" "Feel free to use your browser's BACK button to fix your entry, then resubmit; or,\n" "if you think this rejection was in error, you can send email. Just don't hope for too much.\n") open(os.path.join(config.LOG_ROOT, 'trash.log'), 'a+').write(str(link) + '\n') else: link['id'] = pif.dbh.insert_link_line(link) ostr += "Your suggestion has been sent to the site administrators. Thank you.<br>" check_link(pif, link) return ostr