Mercurial > public > sg101
changeset 277:d424b8bae71d
Fixing #128 and #129. Add elsewhere weblinks to search content. Add support for haystack's get_update_field() method.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 02 Oct 2010 23:24:39 +0000 |
parents | 8a46843c258f |
children | 2a795fd602a4 |
files | gpp/bio/admin.py gpp/bio/models.py gpp/bio/search_indexes.py gpp/downloads/admin.py gpp/downloads/models.py gpp/downloads/search_indexes.py gpp/forums/models.py gpp/forums/search_indexes.py gpp/news/admin.py gpp/news/models.py gpp/news/search_indexes.py gpp/podcast/admin.py gpp/podcast/models.py gpp/podcast/search_indexes.py gpp/templates/search/indexes/bio/userprofile_text.txt gpp/templates/search/search.html gpp/weblinks/admin.py gpp/weblinks/forms.py gpp/weblinks/models.py gpp/weblinks/search_indexes.py |
diffstat | 20 files changed, 117 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/bio/admin.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/bio/admin.py Sat Oct 02 23:24:39 2010 +0000 @@ -21,7 +21,7 @@ 'user__email') exclude = ('profile_html', 'signature_html') list_display = ('__unicode__', 'user_is_active', 'get_status_display', 'status_date') - readonly_fields = ('status', 'status_date') + readonly_fields = ('status', 'status_date', 'update_date') list_filter = ('status', ) date_hierarchy = 'status_date' inlines = (BadgeOwnerInline, )
--- a/gpp/bio/models.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/bio/models.py Sat Oct 02 23:24:39 2010 +0000 @@ -2,13 +2,14 @@ Contains models for the bio application. I would have picked profile for this application, but that is already taken, apparently. """ - +import datetime import os.path from django.db import models from django.contrib.auth.models import User from django.conf import settings from django.core.cache import cache +from django.template.loader import render_to_string from core.markup import SiteMarkup @@ -90,6 +91,7 @@ choices=USER_STATUS_CHOICES) status_date = models.DateTimeField(auto_now_add=True) badges = models.ManyToManyField(Badge, through="BadgeOwnership") + update_date = models.DateTimeField(db_index=True, blank=True) def __unicode__(self): return self.user.username @@ -98,6 +100,7 @@ ordering = ('user__username', ) def save(self, *args, **kwargs): + update_date = datetime.datetime.now() sm = SiteMarkup() self.profile_html = sm.convert(self.profile_text) self.signature_html = sm.convert(self.signature) @@ -134,8 +137,9 @@ return self.user.username def search_summary(self): - return u"\n".join((self.location, self.occupation, self.interests, - self.profile_text, self.signature)) + text = render_to_string('search/indexes/bio/userprofile_text.txt', + {'object': self}); + return text class UserProfileFlag(models.Model):
--- a/gpp/bio/search_indexes.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/bio/search_indexes.py Sat Oct 02 23:24:39 2010 +0000 @@ -12,5 +12,8 @@ def get_queryset(self): return UserProfile.objects.filter(user__is_active=True) + def get_updated_field(self): + return 'update_date' + site.register(UserProfile, UserProfileIndex)
--- a/gpp/downloads/admin.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/downloads/admin.py Sat Oct 02 23:24:39 2010 +0000 @@ -24,6 +24,7 @@ list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 'size') ordering = ('date_added', ) raw_id_fields = ('user', ) + readonly_fields = ('update_date', ) actions = ('approve_downloads', ) @@ -61,6 +62,7 @@ ordering = ('-date_added', ) search_fields = ('title', 'description', 'user__username') raw_id_fields = ('user', ) + readonly_fields = ('update_date', ) save_on_top = True
--- a/gpp/downloads/models.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/downloads/models.py Sat Oct 02 23:24:39 2010 +0000 @@ -56,8 +56,9 @@ html = models.TextField(blank=True) file = models.FileField(upload_to=download_path) user = models.ForeignKey(User) - date_added = models.DateTimeField() + date_added = models.DateTimeField(db_index=True) ip_address = models.IPAddressField('IP Address') + update_date = models.DateTimeField(db_index=True, blank=True) class Meta: abstract = True @@ -80,6 +81,10 @@ def save(self, *args, **kwargs): if not self.pk: self.date_added = datetime.datetime.now() + self.update_date = self.date_added + else: + self.update_date = datetime.datetime.now() + self.html = site_markup(self.description) super(PendingDownload, self).save(*args, **kwargs) @@ -103,6 +108,12 @@ return ('downloads-details', [str(self.id)]) def save(self, *args, **kwargs): + if not self.pk: + self.date_added = datetime.datetime.now() + self.update_date = self.date_added + else: + self.update_date = datetime.datetime.now() + self.html = site_markup(self.description) super(Download, self).save(*args, **kwargs)
--- a/gpp/downloads/search_indexes.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/downloads/search_indexes.py Sat Oct 02 23:24:39 2010 +0000 @@ -13,5 +13,8 @@ def get_queryset(self): return Download.public_objects.all() + def get_updated_field(self): + return 'update_date' + site.register(Download, DownloadIndex)
--- a/gpp/forums/models.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/forums/models.py Sat Oct 02 23:24:39 2010 +0000 @@ -243,8 +243,8 @@ """ topic = models.ForeignKey(Topic, related_name='posts') user = models.ForeignKey(User, related_name='posts') - creation_date = models.DateTimeField(auto_now_add=True) - update_date = models.DateTimeField(null=True) + creation_date = models.DateTimeField(db_index=True) + update_date = models.DateTimeField(db_index=True) body = models.TextField() html = models.TextField() user_ip = models.IPAddressField(blank=True, default='', null=True) @@ -269,6 +269,10 @@ return self.summary() def save(self, *args, **kwargs): + if not self.id: + self.creation_date = datetime.datetime.now() + self.update_date = self.creation_date + self.html = site_markup(self.body) super(Post, self).save(*args, **kwargs) @@ -279,7 +283,7 @@ self.topic.delete() def has_been_edited(self): - return self.update_date is not None + return self.update_date > self.creation_date def touch(self): """Call this function to indicate the post has been edited."""
--- a/gpp/forums/search_indexes.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/forums/search_indexes.py Sat Oct 02 23:24:39 2010 +0000 @@ -14,5 +14,8 @@ return Post.objects.filter( topic__forum__in=Forum.objects.public_forums()) + def get_updated_field(self): + return 'update_date' + site.register(Post, PostIndex)
--- a/gpp/news/admin.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/news/admin.py Sat Oct 02 23:24:39 2010 +0000 @@ -22,6 +22,7 @@ search_fields = ('title', 'short_text', 'long_text') date_hierarchy = 'date_submitted' actions = ('approve_story', ) + readonly_fields = ('update_date', ) def approve_story(self, request, qs): for pending_story in qs: @@ -31,7 +32,7 @@ category=pending_story.category, short_text=pending_story.short_text, long_text=pending_story.long_text, - date_submitted=datetime.datetime.now(), + date_submitted=pending_story.date_submitted, allow_comments=pending_story.allow_comments, tags=pending_story.tags, front_page_expiration=pending_story.front_page_expiration) @@ -49,6 +50,7 @@ list_filter = ('date_submitted', 'category') search_fields = ('title', 'short_text', 'long_text') date_hierarchy = 'date_submitted' + readonly_fields = ('update_date', ) class Media: js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
--- a/gpp/news/models.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/news/models.py Sat Oct 02 23:24:39 2010 +0000 @@ -36,6 +36,7 @@ allow_comments = models.BooleanField(default=True) tags = TagField() front_page_expiration = models.DateField(null=True, blank=True) + update_date = models.DateTimeField(db_index=True, blank=True) class Meta: abstract = True @@ -46,7 +47,11 @@ def save(self, *args, **kwargs): if not self.pk: - self.date_submitted = datetime.datetime.now() + if not self.date_submitted: + self.date_submitted = datetime.datetime.now() + self.update_date = self.date_submitted + else: + self.update_date = datetime.datetime.now() super(PendingStory, self).save(*args, **kwargs) @@ -73,6 +78,15 @@ verbose_name = 'news story' verbose_name_plural = 'news stories' + def save(self, *args, **kwargs): + if not self.pk: + self.date_submitted = datetime.datetime.now() + self.update_date = self.date_submitted + else: + self.update_date = datetime.datetime.now() + + super(Story, self).save(*args, **kwargs) + def can_comment_on(self): now = datetime.datetime.now() delta = now - self.date_submitted
--- a/gpp/news/search_indexes.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/news/search_indexes.py Sat Oct 02 23:24:39 2010 +0000 @@ -9,5 +9,8 @@ author = CharField(model_attr='submitter') pub_date = DateTimeField(model_attr='date_submitted') + def get_updated_field(self): + return 'update_date' + site.register(Story, StoryIndex)
--- a/gpp/podcast/admin.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/podcast/admin.py Sat Oct 02 23:24:39 2010 +0000 @@ -6,6 +6,8 @@ from podcast.models import Channel from podcast.models import Item +class ItemAdmin(admin.ModelAdmin): + readonly_fields = ('update_date', ) admin.site.register(Channel) -admin.site.register(Item) +admin.site.register(Item, ItemAdmin)
--- a/gpp/podcast/models.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/podcast/models.py Sat Oct 02 23:24:39 2010 +0000 @@ -1,7 +1,12 @@ -"""Models for the podcast application.""" +""" +Models for the podcast application. + +""" +import datetime from django.db import models + EXPLICIT_CHOICES = ( ('yes', 'Yes'), ('no', 'No'), @@ -42,10 +47,11 @@ enclosure_length = models.IntegerField() enclosure_type = models.CharField(max_length=32) guid = models.CharField(max_length=255) - pubdate = models.DateTimeField() + pubdate = models.DateTimeField(db_index=True) duration = models.CharField(max_length=16) keywords = models.CharField(max_length=255) explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) + update_date = models.DateTimeField(db_index=True, blank=True) @models.permalink def get_absolute_url(self): @@ -59,6 +65,15 @@ verbose_name = 'podcast' verbose_name_plural = 'podcasts' + def save(self, *args, **kwargs): + if not self.id: + if not self.pubdate: + self.pubdate = datetime.datetime.now() + self.update_date = self.pubdate + else: + self.update_date = datetime.datetime.now() + super(Item, self).save(*args, **kwargs) + def search_title(self): return "%s: %s" % (self.title, self.subtitle)
--- a/gpp/podcast/search_indexes.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/podcast/search_indexes.py Sat Oct 02 23:24:39 2010 +0000 @@ -9,5 +9,8 @@ author = CharField(model_attr='author') pub_date = DateTimeField(model_attr='pubdate') + def get_updated_field(self): + return 'update_date' + site.register(Item, ItemIndex)
--- a/gpp/templates/search/indexes/bio/userprofile_text.txt Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/templates/search/indexes/bio/userprofile_text.txt Sat Oct 02 23:24:39 2010 +0000 @@ -5,3 +5,7 @@ {{ object.interests }} {{ object.profile_text }} {{ object.signature }} +{% for website in object.user.website_profiles.all %} +{{ website.name }} +{{ website.url }} +{% endfor %}
--- a/gpp/templates/search/search.html Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/templates/search/search.html Sat Oct 02 23:24:39 2010 +0000 @@ -6,7 +6,7 @@ <form method="get" action="."> <table> <tr> - <td><input type="text" name="q" id="id_q" /></td> + <td><input type="text" name="q" id="id_q" size="48" /></td> <td><input type="submit" value="Search" /></td> </tr> </table> @@ -27,7 +27,14 @@ </fieldset> {% if query %} - <h3>Results</h3> + <h3>Results for "{{ query }}" page {{ page.number }} of {{ page.paginator.num_pages }}</h3> + + {% if page.paginator.count %} + <p> + <strong>{{ page.paginator.count }} hit{{ page.paginator.count|pluralize }}</strong> + </p> + {% endif %} + {% if page.object_list %} <dl> {% for result in page.object_list %}
--- a/gpp/weblinks/admin.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/weblinks/admin.py Sat Oct 02 23:24:39 2010 +0000 @@ -18,6 +18,7 @@ list_display = ('title', 'url', 'user', 'category', 'date_added') raw_id_fields = ('user', ) actions = ('approve_links', ) + readonly_fields = ('update_date', ) def approve_links(self, request, qs): for pending_link in qs: @@ -42,6 +43,7 @@ ordering = ('-date_added', ) search_fields = ('title', 'description', 'url', 'user__username') raw_id_fields = ('user', ) + readonly_fields = ('update_date', ) save_on_top = True
--- a/gpp/weblinks/forms.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/weblinks/forms.py Sat Oct 02 23:24:39 2010 +0000 @@ -20,4 +20,4 @@ class Meta: model = PendingLink - exclude = ('user', 'date_added') + exclude = ('user', 'date_added', 'update_date')
--- a/gpp/weblinks/models.py Thu Sep 30 00:06:04 2010 +0000 +++ b/gpp/weblinks/models.py Sat Oct 02 23:24:39 2010 +0000 @@ -36,7 +36,8 @@ url = models.URLField(verify_exists=False, db_index=True) description = models.TextField(blank=True) user = models.ForeignKey(User) - date_added = models.DateField() + date_added = models.DateTimeField(db_index=True) + update_date = models.DateTimeField(db_index=True, blank=True) class Meta: abstract = True @@ -57,6 +58,16 @@ def __unicode__(self): return self.title + def save(self, *args, **kwargs): + if not self.pk: + if not self.date_added: + self.date_added = datetime.datetime.now() + self.update_date = self.date_added + else: + self.update_date = datetime.datetime.now() + + super(Link, self).save(*args, **kwargs) + @models.permalink def get_absolute_url(self): return ('weblinks-link_detail', [str(self.id)]) @@ -81,6 +92,10 @@ def save(self, *args, **kwargs): if not self.pk: self.date_added = datetime.datetime.now() + self.update_date = self.date_added + else: + self.update_date = datetime.datetime.now() + super(PendingLink, self).save(*args, **kwargs)