def _item_dict(self, content_item): base_type = self._base_type(content_item.type) url = config.url + "/" + self.types[content_item.type]["view_url"].replace("<url>", content_item.type_key) + "/" if "view_url" in self.types[content_item.type] else None formatter = self.types[content_item.type]["type"].get_formatter() format = lambda: dict({ "title" : formatter.get_title(content_item), "image" : formatter.get_image(content_item), "description" : formatter.get_description(content_item, url), "text" : formatter.get_text(content_item, url), }, **formatter.get_dict(content_item, url)) if formatter.is_context_dependent(content_item): formatter_output = format() else: formatter_output = cache.get_cache("content_item_%d" % content_item.id).get(key="formatter_output", createfunc=format) return dict({ "id" : content_item.id, "type" : content_item.type, "type_key" : content_item.type_key, "started_at" : content_item.started_at, "created_at" : content_item.created_at, "comments" : content_item.comments, "tags" : content_item.tags, "permissions" : [k for k in ContentItem.__dict__.keys() if k.startswith("permissions_") and isinstance(getattr(ContentItem, k), int) and content_item.permissions & getattr(ContentItem, k)], "base_type" : base_type, "url" : url, }, **formatter_output)
def execute_admin_edit(self, request, id): c = db.query(ContentItem).get(id) if c is None: raise NotFound() editor = self.types[c.type]["type"].get_editor() if request.method == "POST": c.type_key = request.form["type_key"] c.started_at = dateutil.parser.parse(request.form["started_at"]) if request.form.get("started_at", "").strip() else None c.created_at = dateutil.parser.parse(request.form["created_at"]) c.permissions = ContentItem.permissions_PUBLIC if "public" in request.form else ContentItem.permissions_NOT_READY c.tags = [] for tag in request.form["tags"].split(","): tag = tag.strip() db_tag = db.query(Tag).filter(Tag.title == tag).first() if db_tag is None: db_tag = Tag() db_tag.url = tag.split(":", 2)[0] if ":" in tag else tag db_tag.title = tag.split(":", 2)[1] if ":" in tag else tag db.add(db_tag) db.flush() c.tags.append(db_tag) data = editor.form_to_db(request, c.data) c.data = None db.flush() c.data = data db.flush() cache.get_cache("content_item_%d" % c.id).remove_value(key="formatter_output") return redirect(request.path) else: form = editor.db_to_form(c.data) return self.render_to_response(request, [ "content/type/%s/edit.html" % (c.type,), "content/type/%s/edit.html" % (self._base_type(c.type),), ], **{ "breadcrumbs" : [u"Редактирование %s" % self.types[c.type]["type"].item_cases[1]], "form" : form, "content_item" : c, "tags" : u",".join([t.title for t in c.tags]), })
def block(request, limit=None): try: links = cache.get_cache("sape", expire=3600).get(key="links", createfunc=load_links) except: links = cache.get_cache("sape", expire=300).get(key="links", createfunc=lambda: {}) if request.path in links: if not hasattr(request, "sape_links_shown"): request.sape_links_shown = 0 slc = links[request.path][request.sape_links_shown : request.sape_links_shown + limit if limit is not None else None] request.sape_links_shown += len(slc) if slc: return { "class" : "sape", "links" : links["__sape_delimiter__"].join(slc), } return None
parser.add_argument('-o', dest='output', help='output pickle containing the pokemon data') parser.add_argument('--version_group', dest='version_group', help='The version group the movesets are based on.', default=VERSION_GROUP) parser.add_argument('--cache', dest='cache', action='store_true', help='If set all data crawled will be cached.') args = parser.parse_args() project = pymap.project.Project(args.project) pokemons = [] cache = pokeapi_cache.get_cache() for species in project.constants['species']: idx = species_to_idx[species] if idx is not None: print(f'Fetching pokemon idx {idx}') pokemon = {} # Process the species information pokemon_species = get_resource(get_url('pokemon-species', idx)[:-1], cache=cache) pokemon['name'] = { lang: get_name(pokemon_species, language=value) for lang, value in language.languages.items()