From 4fcb99e48c980dfa220d219a093745e58fdf5371 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Fri, 13 May 2011 21:26:29 -0400 Subject: [PATCH] Removed penfield's reliance on the Titled model and marked it as deprecated. --- philo/contrib/penfield/admin.py | 23 ++++++++++--------- philo/contrib/penfield/models.py | 39 ++++++++++++++++++++++++++------ philo/models/base.py | 1 + 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/philo/contrib/penfield/admin.py b/philo/contrib/penfield/admin.py index a897b97..d350303 100644 --- a/philo/contrib/penfield/admin.py +++ b/philo/contrib/penfield/admin.py @@ -15,16 +15,12 @@ class DelayedDateForm(forms.ModelForm): self.fields[self.date_field].required = False -class TitledAdmin(EntityAdmin): +class BlogAdmin(EntityAdmin): prepopulated_fields = {'slug': ('title',)} list_display = ('title', 'slug') -class BlogAdmin(TitledAdmin): - pass - - -class BlogEntryAdmin(TitledAdmin, AddTagAdmin): +class BlogEntryAdmin(AddTagAdmin): form = DelayedDateForm filter_horizontal = ['tags'] list_filter = ['author', 'blog'] @@ -45,6 +41,7 @@ class BlogEntryAdmin(TitledAdmin, AddTagAdmin): }) ) related_lookup_fields = {'fk': raw_id_fields} + prepopulated_fields = {'slug': ('title',)} class BlogViewAdmin(EntityAdmin): @@ -71,11 +68,12 @@ class BlogViewAdmin(EntityAdmin): related_lookup_fields = {'fk': raw_id_fields} -class NewsletterAdmin(TitledAdmin): - pass +class NewsletterAdmin(EntityAdmin): + prepopulated_fields = {'slug': ('title',)} + list_display = ('title', 'slug') -class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin): +class NewsletterArticleAdmin(AddTagAdmin): form = DelayedDateForm filter_horizontal = ('tags', 'authors') list_filter = ('newsletter',) @@ -95,6 +93,7 @@ class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin): }) ) actions = ['make_issue'] + prepopulated_fields = {'slug': ('title',)} def author_names(self, obj): return ', '.join([author.get_full_name() for author in obj.authors.all()]) @@ -108,8 +107,10 @@ class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin): make_issue.short_description = u"Create issue from selected %(verbose_name_plural)s" -class NewsletterIssueAdmin(TitledAdmin): - filter_horizontal = TitledAdmin.filter_horizontal + ('articles',) +class NewsletterIssueAdmin(EntityAdmin): + filter_horizontal = ('articles',) + prepopulated_fields = {'slug': ('title',)} + list_display = ('title', 'slug') class NewsletterViewAdmin(EntityAdmin): diff --git a/philo/contrib/penfield/models.py b/philo/contrib/penfield/models.py index 6955069..a3e3186 100644 --- a/philo/contrib/penfield/models.py +++ b/philo/contrib/penfield/models.py @@ -16,7 +16,7 @@ from philo.contrib.penfield.exceptions import HttpNotAcceptable from philo.contrib.penfield.middleware import http_not_acceptable from philo.contrib.penfield.validators import validate_pagination_count from philo.exceptions import ViewCanNotProvideSubpath -from philo.models import Tag, Titled, Entity, MultiView, Page, register_value_model, TemplateField, Template +from philo.models import Tag, Entity, MultiView, Page, register_value_model, TemplateField, Template from philo.utils import paginate try: @@ -297,7 +297,13 @@ class FeedView(MultiView): abstract=True -class Blog(Entity, Titled): +class Blog(Entity): + title = models.CharField(max_length=255) + slug = models.SlugField(max_length=255) + + def __unicode__(self): + return self.title + @property def entry_tags(self): """ Returns a QuerySet of Tags that are used on any entries in this blog. """ @@ -312,7 +318,9 @@ class Blog(Entity, Titled): register_value_model(Blog) -class BlogEntry(Entity, Titled): +class BlogEntry(Entity): + title = models.CharField(max_length=255) + slug = models.SlugField(max_length=255) blog = models.ForeignKey(Blog, related_name='entries', blank=True, null=True) author = models.ForeignKey(getattr(settings, 'PHILO_PERSON_MODULE', 'auth.User'), related_name='blogentries') date = models.DateTimeField(default=None) @@ -325,6 +333,9 @@ class BlogEntry(Entity, Titled): self.date = datetime.now() super(BlogEntry, self).save(*args, **kwargs) + def __unicode__(self): + return self.title + class Meta: ordering = ['-date'] verbose_name_plural = "blog entries" @@ -562,14 +573,20 @@ class BlogView(FeedView): return [tag.name for tag in item.tags.all()] -class Newsletter(Entity, Titled): - pass +class Newsletter(Entity): + title = models.CharField(max_length=255) + slug = models.SlugField(max_length=255) + + def __unicode__(self): + return self.title register_value_model(Newsletter) -class NewsletterArticle(Entity, Titled): +class NewsletterArticle(Entity): + title = models.CharField(max_length=255) + slug = models.SlugField(max_length=255) newsletter = models.ForeignKey(Newsletter, related_name='articles') authors = models.ManyToManyField(getattr(settings, 'PHILO_PERSON_MODULE', 'auth.User'), related_name='newsletterarticles') date = models.DateTimeField(default=None) @@ -582,6 +599,9 @@ class NewsletterArticle(Entity, Titled): self.date = datetime.now() super(NewsletterArticle, self).save(*args, **kwargs) + def __unicode__(self): + return self.title + class Meta: get_latest_by = 'date' ordering = ['-date'] @@ -591,11 +611,16 @@ class NewsletterArticle(Entity, Titled): register_value_model(NewsletterArticle) -class NewsletterIssue(Entity, Titled): +class NewsletterIssue(Entity): + title = models.CharField(max_length=255) + slug = models.SlugField(max_length=255) newsletter = models.ForeignKey(Newsletter, related_name='issues') numbering = models.CharField(max_length=50, help_text='For example, 04.02 for volume 4, issue 2.') articles = models.ManyToManyField(NewsletterArticle, related_name='issues') + def __unicode__(self): + return self.title + class Meta: ordering = ['-numbering'] unique_together = (('newsletter', 'numbering'),) diff --git a/philo/models/base.py b/philo/models/base.py index 46fa8d5..02d8456 100644 --- a/philo/models/base.py +++ b/philo/models/base.py @@ -36,6 +36,7 @@ class Tag(models.Model): class Titled(models.Model): + # Use of this model is deprecated. title = models.CharField(max_length=255) slug = models.SlugField(max_length=255) -- 2.20.1