annotate oembed/models.py @ 943:cf9918328c64
Haystack tweaks for Django 1.7.7.
I had to upgrade to Haystack 2.3.1 to get it to work with Django
1.7.7. I also had to update the Xapian backend. But I ran into
problems.
On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms
are greater than 245 chars (or something) when indexing. So I created
a custom field that would simply omit terms greater than 64 chars and
used this field everywhere I previously used a CharField.
Secondly, the custom search form was broken now. Something changed in
the Xapian backend and exact searches stopped working. Fortunately the
auto_query (which I was using originally and broke during an upgrade)
started working again. So I cut the search form back over to doing an
auto_query. I kept the form the same (3 fields) because I didn't want
to change the form and I think it's better that way.
author |
Brian Neal <bgneal@gmail.com> |
date |
Wed, 13 May 2015 20:25:07 -0500 |
parents |
d3f6e9cb1f39 |
children |
4da4e32b314c |
rev |
line source |
bgneal@285
|
1 """
|
bgneal@285
|
2 Models for the oembed application.
|
bgneal@285
|
3 """
|
bgneal@285
|
4 import datetime
|
bgneal@285
|
5
|
bgneal@285
|
6 from django.db import models
|
bgneal@285
|
7
|
bgneal@285
|
8
|
bgneal@285
|
9 class Provider(models.Model):
|
bgneal@285
|
10 """
|
bgneal@285
|
11 This model described an oEmbed provider.
|
bgneal@285
|
12 """
|
bgneal@285
|
13 JSON, XML = range(2)
|
bgneal@285
|
14 FORMAT_CHOICES = (
|
bgneal@285
|
15 (JSON, "json"),
|
bgneal@285
|
16 (XML, "xml"),
|
bgneal@285
|
17 )
|
bgneal@285
|
18
|
bgneal@285
|
19 name = models.CharField(max_length=128)
|
bgneal@572
|
20 api_endpoint = models.URLField(max_length=255, verbose_name='API endpoint')
|
bgneal@285
|
21 url_regex = models.CharField(max_length=255, verbose_name='URL regex')
|
bgneal@285
|
22 format = models.IntegerField(choices=FORMAT_CHOICES)
|
bgneal@285
|
23
|
bgneal@285
|
24 def __unicode__(self):
|
bgneal@285
|
25 return self.name
|
bgneal@285
|
26
|
bgneal@285
|
27
|
bgneal@285
|
28 class Oembed(models.Model):
|
bgneal@285
|
29 """
|
bgneal@285
|
30 This model represents stored embedded content retrieved from an oEmbed
|
bgneal@285
|
31 provider.
|
bgneal@285
|
32 """
|
bgneal@285
|
33 PHOTO, VIDEO, LINK, RICH = range(4)
|
bgneal@285
|
34 MEDIA_TYPE_CHOICES = (
|
bgneal@285
|
35 (PHOTO, "photo"),
|
bgneal@285
|
36 (VIDEO, "video"),
|
bgneal@285
|
37 (LINK, "link"),
|
bgneal@285
|
38 (RICH, "rich"),
|
bgneal@285
|
39 )
|
bgneal@285
|
40
|
bgneal@572
|
41 url = models.URLField(max_length=255, db_index=True)
|
bgneal@285
|
42 type = models.IntegerField(choices=MEDIA_TYPE_CHOICES)
|
bgneal@285
|
43 title = models.CharField(max_length=255, blank=True, default='')
|
bgneal@285
|
44 width = models.IntegerField()
|
bgneal@285
|
45 height = models.IntegerField()
|
bgneal@285
|
46 html = models.TextField()
|
bgneal@285
|
47 date_added = models.DateTimeField()
|
bgneal@285
|
48
|
bgneal@285
|
49 def __unicode__(self):
|
bgneal@911
|
50 desc = self.title if self.title else self.url
|
bgneal@911
|
51 return u"<oembed {}: {}>".format(self.pk, desc)
|
bgneal@285
|
52
|
bgneal@285
|
53 def save(self, *args, **kwargs):
|
bgneal@285
|
54 if not self.pk:
|
bgneal@285
|
55 self.date_added = datetime.datetime.now()
|
bgneal@285
|
56
|
bgneal@285
|
57 super(Oembed, self).save(*args, **kwargs)
|
bgneal@285
|
58
|