def add(request): theredirect = models.Redirect() form_class = REDIRECT_EDIT_HANDLER.get_form_class(models.Redirect) if request.POST: form = form_class(request.POST, request.FILES) if form.is_valid(): theredirect = form.save(commit=False) theredirect.site = request.site theredirect.save() messages.success( request, _("Redirect '{0} added.").format(theredirect.title)) return redirect('wagtailredirects_index') else: messages.error( request, _("The redirect could not be created due to errors.")) edit_handler = REDIRECT_EDIT_HANDLER(instance=theredirect, form=form) else: form = form_class() edit_handler = REDIRECT_EDIT_HANDLER(instance=theredirect, form=form) return render(request, "wagtailredirects/add.html", { 'edit_handler': edit_handler, })
def handleArticle(self, current_page): #print('ARTICLE:', repr(current_page.title)) if self.pass_num == 0: models.articles.save( models.Article(id=current_page['id'], title=current_page['title'], revision_id=current_page['revision_id'])) elif self.pass_num == 1: aid = models.articles.resolve_title(current_page['title']) wikitext__ = utils.unescape_html(current_page['text']) redirect = wikitext.parse_redirect(wikitext__) if redirect: redirect_dest_title, dest_frag, redirect_label = redirect article = models.articles[aid] if redirect_dest_title in models.articles: dest_id = models.articles.resolve_title( redirect_dest_title) else: dest_id = None #print('Broken REDIRECT FROM ', repr(current_page['title']), ' TO ', repr(redirect), file=parse_log) #print(repr(redirect_dest_title), file=parse_log) print >> parse_log, repr(redirect_dest_title) article.redirect = models.Redirect(dest_id, dest_frag, redirect_label) models.articles.save(article) else: #do not parse/allow links if there is a redirect. If there is a redirect, links are meaningless. besides, parse_links does not work properly with redirects. for link_dest_title, dest_frag, link_label, snippet in wikitext.parse_links( wikitext__): lid = self.num_links + 1 #0 is an invalid key #assert lid not in models.links if link_dest_title in models.articles: dest_id = models.articles.resolve_title( link_dest_title) else: dest_id = None #print('Broken LINK FROM ', repr(current_page['title']), ' TO ', repr((link_dest_title, dest_frag, link_label)), file=parse_log) #print(repr(link_dest_title), file=parse_log) print >> parse_log, repr(link_dest_title) models.links.save( models.Link(src_id=aid, dest_id=dest_id, dest_fragment=dest_frag, label=link_label, snippet=snippet, id=lid)) self.num_links += 1 ''' if lid > len(models.links): ... else: self.num_links += 1 #skip ''' self.num_articles += 1 if self.num_articles % 1000 == 0: #print(self.num_articles, self.num_links) print self.num_articles, self.num_links