def newLabel(lang): """Creates a new label in the given language. Needs an argument: lang: mandatory, language (en/es) Needs a JSON: { "label": "New label" } """ m = LabelModel() return jsonify({"id": m.insertLabel(request.json["label"], lang)})
def getLabels(lang): """Returns labels in the given language (en/es).""" m = LabelModel() return jsonify({"results": m.getLabels(lang)})
def newStuff(): """Returns new stuff for the new stuff control. Accepts request.args: lang=en/es: mandatory section= 1=Blog/2=Media/3=Events/4=Documents/5=Twitter: optional. If absent, sends all sections mixed Returns a JSON in the form: { "news":[{ "id": "1", "wwwuser": "******", "time": "201401101027", "title": "¿El auge del resto? Apuntes sobre la presencia global de América Latina, Asia y el Magreb y Oriente Medio", "link": "http://www.geographica.gs", "section": "Blog", "labels": [ {"id": "1", "label": "IEPG"}, {"id": "2", "label": "Economía"}] }] } TODO: revisar, devuelve unos id un poco raros """ m = HomeModel() l = LabelModel() lang = request.args["lang"] section = int( request.args["section"]) if "section" in request.args else None try: labels = l.getLabels(lang) if section: if section in [1, 2, 3]: stuff = m.newStuffSections(lang, section) elif section == 4: stuff = m.newStuffDocuments(lang) elif section == 5: timeline = helpers.twitterGetLatestTweets() stuff = [] for tweet in timeline: stuff.append({ "id": tweet.id, "time": tweet.created_at, "title": tweet.text, "section": "Twitter", "labels": [], "wwwuser": "******" }) else: e = ElcanoErrorBadNewsSection(section) return (jsonify(e.dict())) else: stuff = m.newStuffAll(lang) except ElcanoError as e: return (jsonify(e.dict())) for s in stuff: lab = [] if s["labels"] != [None]: for l in s["labels"]: for a in labels: if str(a["id"]) == str(l): lab.append(a) s["labels"] = lab s["time"] = str(s["time"].isoformat()) return (jsonify({"results": stuff}))
def getDocumentLabels(lang): """Gets the labels for filters in document catalog. 'lang' must be en/es.""" m = LabelModel() return(jsonify({"results": m.getLabels(lang)}))
def newStuff(): """Returns new stuff for the new stuff control. Accepts request.args: lang=en/es: mandatory section= 1=Blog/2=Media/3=Events/4=Documents/5=Twitter: optional. If absent, sends all sections mixed Returns a JSON in the form: { "news":[{ "id": "1", "wwwuser": "******", "time": "201401101027", "title": "¿El auge del resto? Apuntes sobre la presencia global de América Latina, Asia y el Magreb y Oriente Medio", "link": "http://www.geographica.gs", "section": "Blog", "labels": [ {"id": "1", "label": "IEPG"}, {"id": "2", "label": "Economía"}] }] } TODO: revisar, devuelve unos id un poco raros """ m = HomeModel() l = LabelModel() lang = request.args["lang"] section = int(request.args["section"]) if "section" in request.args else None try: labels = l.getLabels(lang) if section: if section in [1,2,3]: stuff = m.newStuffSections(lang, section) elif section==4: stuff = m.newStuffDocuments(lang) elif section==5: timeline = helpers.twitterGetLatestTweets() stuff = [] for tweet in timeline: stuff.append({ "id" : tweet.id, "time" : tweet.created_at, "title" : tweet.text, "section" : "Twitter", "labels" :[], "wwwuser" : "@rielcano" }) else: e = ElcanoErrorBadNewsSection(section) return(jsonify(e.dict())) else: stuff = m.newStuffAll(lang) except ElcanoError as e: return(jsonify(e.dict())) for s in stuff: lab = [] if s["labels"]!=[None]: for l in s["labels"]: for a in labels: if str(a["id"])==str(l): lab.append(a) s["labels"] = lab s["time"] = str(s["time"].isoformat()) return(jsonify({"results": stuff}))
def getDocumentLabels(lang): """Gets the labels for filters in document catalog. 'lang' must be en/es.""" m = LabelModel() return (jsonify({"results": m.getLabels(lang)}))