def tag_add(request): t = Tag() t.x = float(request.GET['x']) t.y = float(request.GET['y']) t.z = float(request.GET['z']) t.name = request.GET['name'] t.description = request.GET['description'] t.save() return HttpResponse(json.dumps({'message': 'ok'}))
def add_tag(request): var = request.POST is_title = bool(int(var['is_title'])) new_tag=Tag() new_tag.name = var['tag_name'] new_tag.description = var['tag_description'] new_tag.is_title = is_title new_tag.save() return HttpResponse("ok");
def load_tags(): """Load tags from exported tags.json.""" try: with open("../userdata/tags.json") as f: tag_export = json.load(f) except FileNotFoundError: logger.warning("File ../userdata/tags.json not found - tags were not imported") return if tag_export["meta"]["api"] != API_FULL_NAME: raise ValueError("Tag export has Version '{}' but should be '{}'".format(tag_export["meta"]["api"], API_FULL_NAME)) logger.info("Adding {} tags...".format(len(tag_export["data"]))) for tag_data in tag_export["data"]: tag = Tag( title=tag_data["title"], slug=tag_data["slug"], url=tag_data["url"], wikidata_id=tag_data["wikidata_id"], ) tag.description = tag_data.get("description", None) tag.wikipedia_title = tag_data.get("wikipedia_title", None) tag.labels = ";".join(tag_data.get("labels", [])) tag.aliases = ";".join(tag_data.get("aliases", [])) tag.image = tag_data.get("image", None) if tag.description is not None and len(tag.description) > 1: # Always start with upper case tag.description = tag.description[0].upper() + tag.description[1:] # Remove non-descriptions if tag.description.startswith("Wikimedia-"): tag.description = None for thesis_id in tag_data["theses"]: tag.theses.append(Thesis.query.get(thesis_id)) yield tag