def __create_app(self): """ Create a new app with name, shortname and description passed in constructor and with category_id = 1 and return app.id. Or return the app.id from the app registered in pybossa database. :returns: app.id :rtype: int """ apps = pbclient.find_app(short_name=self.short_name) if not len(apps) == 0: app = apps[0] msg = '{app_name} app is already registered in the DB'.format(app_name=app.name.encode('utf-8', 'replace')) logger.info(unicode(msg, "utf-8")) return app.id else: logger.info("The application is not registered in PyBOSSA. Creating it...") ans = pbclient.create_app(name=self.name, short_name=self.short_name, description=self.description) try: if ans: app = pbclient.find_app(short_name=self.short_name)[0] app.info = dict(newtask="%s/app/%s/newtask" % (flask_app.config['PYBOSSA_URL'], self.short_name)) app.category_id = 1 pbclient.update_app(app) return app.id except Exception as ex: logger.error(Meb_apps_exception(4, -1, self.short_name)) raise ex
def set_long_description(self, long_description_text): """ Set app's long description template :arg string long_description_text: content of long description template in string format """ app = pbclient.get_app(self.app_id) app.long_description = long_description_text pbclient.update_app(app)
def set_template(self, template_text): """ Set app's template :arg string template_text: content of template in string format """ app = pbclient.get_app(self.app_id) app.info['task_presenter'] = template_text pbclient.update_app(app)
def set_name(self, name): """ Set app name :arg string name: name of the app """ app = pbclient.get_app(self.app_id) app.name = name pbclient.update_app(app)
def add_app_infos(self, info_values): """ Add new info values to info attribute from this app :arg dict info_values: dict with infos and respectives values to add to the app """ app = pbclient.get_app(self.app_id) if(type(info_values) is dict): for info_key in info_values.keys(): app.info[str(info_key)] = info_values[info_key] else: logger.error(Meb_apps_exception(5, self.app_id, self.short_name)) raise Meb_apps_exception(5, self.app_id, self.short_name) pbclient.update_app(app)
def create_home_app(): try: meb_short_name = "meb_home" apps = pbclient.find_app(short_name=meb_short_name) pyb_app = None if len(apps) != 0: pyb_app = apps[0] else: ans = pbclient.create_app(name="Memória Estatística do Brasil", short_name=meb_short_name, description="Página inicial do MEB.") if ans: pyb_app = pbclient.find_app(short_name=meb_short_name)[0] pbclient.create_task(pyb_app.id, {}) if pyb_app == None: return False new_long_desc_template = meb_util.set_url(urllib2.urlopen( urllib2.Request(app.config['URL_TEMPLATES'] + "/templates/long_description-home.html")), meb_short_name) new_template = meb_util.set_url(urllib2.urlopen( urllib2.Request(app.config['URL_TEMPLATES'] + "/templates/template-home.html")), meb_short_name) pyb_app.info['thumbnail'] = app.config['URL_TEMPLATES'] + "/images/meb_icon.png" pyb_app.category_id = 1 pyb_app.long_description = new_long_desc_template pyb_app.info['task_presenter'] = new_template pbclient.update_app(pyb_app) return True except Exception as e: return False
if template_type: new_template = meb_util.set_url( urllib2.urlopen( urllib2.Request( flask_app.config['URL_TEMPLATES'] + "/templates/" + template_type)), app_short_name) new_long_desc_template = meb_util.set_url( urllib2.urlopen( urllib2.Request( flask_app.config['URL_TEMPLATES'] + "/templates/" + long_desc_type)), app_short_name) app.info['task_presenter'] = new_template app.info['thumbnail'] = app.info['thumbnail'].replace("https://alfa.pybossa.socientize.eu", "https://localhost") app.info['newtask'] = app.info['newtask'].replace("https://alfa.pybossa.socientize.eu", "https://localhost") app.info['newtask'] = app.info['newtask'].replace("http://alfa.pybossa.socientize.eu", "https://localhost") app.info['newtask'] = app.info['newtask'].replace("https://alfa2.pybossa.socientize.eu", "https://localhost") app.info['newtask'] = app.info['newtask'].replace("http://alfa2.pybossa.socientize.eu", "https://localhost") app.long_description = new_long_desc_template book_id = app_short_name[:-4] bookInfo = meb_util.get_archive_book_data(book_id) app.name = bookInfo['title'] + " " + app_name pbclient.update_app(app)