def get(self, **kwargs): pages = Page.all() result = pages.fetch(20) context = { 'pages': result, } return self.render_response('admin/page/index.html', **context)
def get(self, slug=None, **kwargs): language = self.get_locale() page = Page.get_page_by_slug(slug, language=language) context = { 'page': page, 'language': language, } if page is None: return self.redirect_to('notfound') return self.render_response('pages/show.html', **context)
def post(self, page_id=None, **kwargs): """Handle submitted form data""" # validate form if self.form.validate(): title = self.form.title.data content = self.form.content.data live = self.form.live.data language = self.form.language.data # saving edited if page_id: page = Page.get_by_id(page_id) page.title = title page.content = content page.live = live page.language = language # creating new else: page = Page(title=title, content=content, live=live, language=language) if page.put(): return redirect('admin/page') return self.get(**kwargs)
def get(self, page_id=None, **kwargs): """Return a page to edit or an empty form to create""" template = 'admin/page/new.html' context = { 'form': self.form, } # render edit if page_id is not None: page = Page.get_by_id(page_id) if page: self.form = PageForm(obj=page) context.update({ 'form': self.form }) template = 'admin/page/edit.html' else: return redirect('admin/page/') # render new return self.render_response(template, **context)
def get(self, page_id=None, **kwargs): """Return a page to edit or an empty form to create""" template = 'admin/page/new.html' context = { 'form': self.form, } # render edit if page_id is not None: page = Page.get_by_id(page_id) if page: self.form = PageForm(obj=page) context.update({'form': self.form}) template = 'admin/page/edit.html' else: return redirect('admin/page/') # render new return self.render_response(template, **context)
def mapala_pages(BLOCKCHAIN): url = MAPALA_URL + 'index?blockchain=%s' % BLOCKCHAIN # запрашивает с мапалы только отсутствующие в базе страницы data = requests.get(url).json() for article in data['allModels']: if any(key not in article for key in ['title', 'author', 'body']): continue try: author = author_define(article.get('author'), True) try: article['meta'] = json.loads(article['meta']) except json.decoder.JSONDecodeError: article['meta'] = {} try: tags = [tag.lower() for tag in article.get('meta').get('tags')] except: tags = None position = None if 'coordinates' in article[ 'meta'] and article['meta']['coordinates'] != '': try: position = Point( article['meta']['coordinates'].split(',')[0], article['meta']['coordinates'].split(',')[1]) except: position = None position_text = '' if 'location' in article['meta']: position_text = article['meta']['location'] if Page.objects.filter(author=author).exists(): continue else: page = Page(author_id=author.id, title=article.get('title')) page.created_at = aware_date_mapala(article.get('created_at')) page.updated_at = aware_date_mapala(article.get('updated_at')) page.body = article.get('body') page.image = article.get('meta').get('image') page.parent_permlink = article.get('parent_permlink') try: page.miniature = article['meta']['image'][0] except KeyError: pass if BLOCKCHAIN == 'golos': page.locale = 'ru' else: page.locale = 'en' page.total_payout_value = article.get('total_payout_value') page.total_pending_payout_value = article.get( 'total_pending_payout_value') page.status = 2 page.position = position page.position_text = position_text page.save() create_page_images(page, article) if tags: for tag in tags: page.tags.add(tag_define(tag)) voters = json.loads(article.get('voters')) for v in voters: page.voters.add(author_define(v, True).id) country = article.get('country') city = article.get('city') category = article.get('category') sub_category = article.get('sub_category') for m_t in [ mastertag_define('mapala_places', country), mastertag_define(country, city), mastertag_define('mapala_categories', category), mastertag_define(category, sub_category) ]: if m_t: page.master_tag = m_t page.save() get_comments_for(page, page.permlink) except StopIteration as e: print('Warning: ', e) return True