def add_creditline(t, line): assert(len(tlgetall(t, ['Credit line'])) == 0) info = tlgetone(t, infoboxes) for f in otherfieldses: if info.has(f): otherfields = info.get(f) otherfields.value.append(Text(" ")) otherfields.value.append(line) otherfields.value.append(Text("\n")) return info.add("other fields", line)
def can_add_creditline(t, line): if len(tlgetall(t, ['Credit line'])) != 0: return False # Already have a credit line try: geo = tlgetone(t, ['Geograph']) except IndexError: return False except TooManyTemplates: return False geo_author = geo.get(2).value cl_author = line.get('Author').value if canonicalise_name(geo_author) != canonicalise_name(cl_author): # Don't add a credit line with wrong author return False return True
def set_object_location(tree, oloc): if oloc == None: for tl in tlgetall(tree, objtls): tree.remove(tl) return try: replace_templates(tree, oloc, objtls) except IndexError: try: insert_template_after(tree, oloc, loctls) except IndexError: try: insert_template_after(tree, oloc, infoboxes) except IndexError: insert_template_at_start(tree, oloc)
def has_object_location(tree): return len(tlgetall(tree, objtls)) > 0
def insert_template_before(tree, new, names): olds = tlgetall(tree, names) tree.insert_before(olds[0], Wikicode([new, Text("\n")]))
def insert_template_after(tree, new, names): olds = tlgetall(tree, names) tree.insert_after(olds[0], Wikicode([Text("\n"), new]))
def replace_templates(tree, new, names): olds = tlgetall(tree, names) tree.replace(olds[0], new) for o in olds[1:]: tree.remove(o)