12 | | return u"%s comments" % self._site.name |
| 14 | if isinstance(obj, type): |
| 15 | # Feed is filtered according to a ContentType (Model class). |
| 16 | subtitle = u' on all %s' % unicode(obj._meta.verbose_name_plural) |
| 17 | elif isinstance(obj, Model): |
| 18 | # Feed is filtered according to a model instance. |
| 19 | subtitle = u' on "%s"' % obj |
| 20 | elif isinstance(obj, type(None)): |
| 21 | # Feed is not filtered. |
| 22 | subtitle = u'' |
| 23 | return u"%s comments%s" % (self._site.name, subtitle) |
37 | | return item.submit_date |
38 | | No newline at end of file |
| 54 | return item.submit_date |
| 55 | |
| 56 | def get_object(self, bits): |
| 57 | """ |
| 58 | Allows the comment feed to be filtered according to |
| 59 | a particular ContentType or object based on URL bits. |
| 60 | |
| 61 | Feed URLs will have a scheme similar to this, depending on your URLCONF: |
| 62 | /feeds/comments/ (All comments) |
| 63 | /feeds/comments/<app>.<model>/ (Comments for a particular ContentType) |
| 64 | /feeds/comments/<app>.<model>/<pk>/ (Comments for a specific object) |
| 65 | """ |
| 66 | comment_model = comments.get_model() |
| 67 | if len(bits) == 0: |
| 68 | # No extra parameters were provided (default feed). |
| 69 | return None |
| 70 | if len(bits) >= 1: |
| 71 | try: |
| 72 | # First, determine the ContentType. |
| 73 | app_name, model_name = bits[0].split('.') |
| 74 | content_type = ContentType.objects.get(app_label=app_name, name=model_name) |
| 75 | except ValueError: |
| 76 | # Parameters were not in proper format, or were not a ContentType. |
| 77 | raise comment_model.DoesNotExist |
| 78 | if len(bits) == 1: |
| 79 | # User wants a feed for an entire ContentType. |
| 80 | return content_type.model_class() |
| 81 | elif len(bits) == 2: |
| 82 | try: |
| 83 | # User wants a feed for a specfic instance of ContentType. |
| 84 | return content_type.get_object_for_this_type(pk=bits[1]) |
| 85 | except: |
| 86 | raise comment_model.DoesNotExist |
| 87 | # Anything else is invalid. |
| 88 | raise comment_model.DoesNotExist |