203
196
and due to ``list_display`` limitations."""
204
197
return self.content_object
206
def get_base_data(self, show_dates=True):
207
"""Outputs a Python dictionary representing the most useful bits of
208
information about this particular object instance.
210
This is mostly useful for testing purposes, as the output from
211
the serializer changes from run to run. However, this may end
212
up being useful for JSON and/or XML data exchange going forward
213
and as the serializer system is changed.
217
for markup_choice in MARKUP_CHOICES:
218
if self.markup == markup_choice[0]:
219
markup = markup_choice[1]
222
'content_object': self.content_object,
223
'parent': self.parent,
225
'comment': self.comment,
226
'is_public': self.is_public,
227
'is_approved': self.is_approved,
228
'ip_address': self.ip_address,
229
'markup': force_unicode(markup),
232
to_return['date_submitted'] = self.date_submitted
233
to_return['date_modified'] = self.date_modified
234
to_return['date_approved'] = self.date_approved
238
200
ordering = ('-date_submitted',)
239
201
verbose_name = _('Threaded Comment')
240
202
verbose_name_plural = _('Threaded Comments')
241
203
get_latest_by = 'date_submitted'
244
class FreeThreadedComment(models.Model):
246
A threaded comment which need not be associated with an instance of
247
``django.contrib.auth.models.User``. Instead, it requires minimally a name,
248
and maximally a name, website, and e-mail address. It is given its hierarchy
249
by a nullable relationship back on itself named ``parent``.
251
This ``FreeThreadedComment`` supports several kinds of markup languages,
252
including Textile, Markdown, and ReST.
254
It also includes two Managers: ``objects``, which is the same as the normal
255
``objects`` Manager with a few added utility functions (see above), and
256
``public``, which has those same utility functions but limits the QuerySet to
257
only those values which are designated as public (``is_public=True``).
259
# Generic Foreign Key Fields
260
content_type = models.ForeignKey(ContentType)
261
object_id = models.PositiveIntegerField(_('object ID'))
262
content_object = GenericForeignKey()
265
parent = models.ForeignKey(
266
'self', null=True, blank=True, default=None, related_name='children')
268
# User-Replacement Fields
269
name = models.CharField(_('name'), max_length=128)
270
website = models.URLField(_('site'), blank=True)
271
email = models.EmailField(_('e-mail address'), blank=True)
274
date_submitted = models.DateTimeField(
275
_('date/time submitted'), default=datetime.now)
276
date_modified = models.DateTimeField(
277
_('date/time modified'), default=datetime.now)
278
date_approved = models.DateTimeField(
279
_('date/time approved'), default=None, null=True, blank=True)
282
comment = models.TextField(_('comment'))
283
markup = models.IntegerField(
284
choices=MARKUP_CHOICES, default=DEFAULT_MARKUP, null=True, blank=True)
287
is_public = models.BooleanField(_('is public'), default=True)
288
is_approved = models.BooleanField(_('is approved'), default=False)
291
ip_address = models.GenericIPAddressField(
292
_('IP address'), null=True, blank=True)
294
objects = ThreadedCommentManager()
295
public = PublicThreadedCommentManager()
297
def __unicode__(self):
298
if len(self.comment) > 50:
299
return self.comment[:50] + '...'
300
return self.comment[:50]
302
def save(self, **kwargs):
304
self.markup = DEFAULT_MARKUP
305
self.date_modified = datetime.now()
306
if not self.date_approved and self.is_approved:
307
self.date_approved = datetime.now()
308
super(FreeThreadedComment, self).save()
310
def get_content_object(self, **kwargs):
311
"""Wrapper around the GenericForeignKey due to compatibility reasons
312
and due to ``list_display`` limitations."""
313
return self.content_object
315
def get_base_data(self, show_dates=True):
316
"""Outputs a Python dictionary representing the most useful bits of
317
information about this particular object instance.
319
This is mostly useful for testing purposes, as the output from
320
the serializer changes from run to run. However, this may end
321
up being useful for JSON and/or XML data exchange going forward
322
and as the serializer system is changed.
326
for markup_choice in MARKUP_CHOICES:
327
if self.markup == markup_choice[0]:
328
markup = markup_choice[1]
331
'content_object': self.content_object,
332
'parent': self.parent,
334
'website': self.website,
336
'comment': self.comment,
337
'is_public': self.is_public,
338
'is_approved': self.is_approved,
339
'ip_address': self.ip_address,
340
'markup': force_unicode(markup),
343
to_return['date_submitted'] = self.date_submitted
344
to_return['date_modified'] = self.date_modified
345
to_return['date_approved'] = self.date_approved
349
ordering = ('-date_submitted',)
350
verbose_name = _('Free Threaded Comment')
351
verbose_name_plural = _('Free Threaded Comments')
352
get_latest_by = 'date_submitted'
355
class TestModel(models.Model):
356
"""This model is simply used by this application's test suite as a model to
357
which to attach comments."""
358
name = models.CharField(max_length=5)
359
is_public = models.BooleanField(default=True)
360
date = models.DateTimeField(default=datetime.now)