diff --git a/generators/category.py b/generators/category.py index ca16953..e023fee 100644 --- a/generators/category.py +++ b/generators/category.py @@ -10,7 +10,7 @@ class Category(Index): nb_pages = 0 cur_article = 0 articles_per_page = 0 - filename = 'category' + filename = 'index' cur_category = None def createCategory(self, articles, dom, root, node): @@ -52,20 +52,24 @@ class Category(Index): for category in categories: self.cur_category = category - self.filename = category.name_slug filename = self.filename + '.html' articles = Article.objects.filter(category__exact=category).order_by('-creation_date') self.nb_pages = 0 self.cur_page = 0 + self.cur_article = 0 + if articles.count() > self.articles_per_page: self.nb_pages = articles.count() / self.articles_per_page + if not os.path.exists(output + '/category/' + category.name_slug): + os.mkdir(output + '/category/' + category.name_slug) + while self.cur_page <= self.nb_pages: #print 'Generate ' + filename nodes = dom.getElementsByTagName("*") self.parse(hooks, articles, dom, nodes[0]) - self.writeIfNotTheSame(output + '/category/' + filename, nodes[0].toxml('utf8')) + self.writeIfNotTheSame(output + '/category/' + category.name_slug + '/' + filename, nodes[0].toxml('utf8')) self.cur_page = self.cur_page + 1 filename = self.filename + str(self.cur_page) + '.html' dom = parse(src + '/_category.html') @@ -78,7 +82,7 @@ class Category(Index): self.addReport('Removing unused ' + filename) os.unlink(filename) self.cur_page = self.cur_page + 1 - filename = output + '/category/' + self.filename + str(self.cur_page) + '.html' + filename = output + '/category/' + category.name_slug + '/' + self.filename + str(self.cur_page) + '.html' if not self.somethingWrote: self.addReport('Nothing changed') diff --git a/models.py b/models.py index 58173d1..2b92ece 100644 --- a/models.py +++ b/models.py @@ -148,29 +148,8 @@ class Category(models.Model): def remove(self, blog): blog.create_paths() - output = blob.output_path - cur_cat = 0 - while True: - found = False - filename = output + '/category/' - if cur_cat == 0: - filename = filename + self.name_slug + '.html' - else: - filename = filename + self.name_slug + str(cur_cat) + '.html' - if os.path.exists(filename): - os.unlink(filename) - found = True - filename = filename + '.gz' - if os.path.exists(filename): - os.unlink(filename) - found = True - if not found: - break - cur_cat = cur_cat + 1 - - filename = output + '/category/' - if len(os.listdir(filename)) == 0: - os.rmdir(filename) + output = blog.output_path + '/category/' + self.name_slug + shutil.rmtree(output) class Tag(models.Model): diff --git a/views.py b/views.py index bf1a99a..1b08d0b 100644 --- a/views.py +++ b/views.py @@ -139,8 +139,11 @@ def edit_category(request, category_id): if 'cancel' in request.POST: return HttpResponseRedirect('/category') if 'edit' in request.POST and request.user.is_superuser: + name = category.name form = CategoryForm(request.POST, instance=category) # A form bound to the POST data if form.is_valid(): # All validation rules pass + if category.name != name: + category.remove() form.save() else: form = CategoryForm(instance=category) # An unbound form @@ -295,7 +298,7 @@ def edit_article(request, article_id): if 'edit' in request.POST: form = ArticleForm(request.POST, instance=article) # A form bound to the POST data if form.is_valid(): # All validation rules pass - if title != article.title: + if title != form.title: article.remove() form.save() # Process the data in form.cleaned_data