This repository has been archived by the owner on Nov 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
models.py
55 lines (44 loc) · 2.54 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from django.contrib.contenttypes import generic
from django.db import models
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from facebook.modules.base import Base, AdminBase
class Profile(Base):
""" Base Class for user, group, page, event and application. """
id = models.BigIntegerField(primary_key=True, unique=True, help_text=_('The ID is the facebook page ID'))
_name = models.CharField(max_length=200, blank=True, null=True)
_username = models.CharField(max_length=200, blank=True, unique=True, null=True)
_link = models.URLField(max_length=255, verify_exists=False, blank=True, null=True)
_picture = models.URLField(max_length=500, blank=True, null=True, verify_exists=False, help_text=_('Cached picture of the page'))
_pic_square = models.URLField(max_length=500, blank=True, null=True, verify_exists=False, editable=False)
_pic_small = models.URLField(max_length=500, blank=True, null=True, verify_exists=False, editable=False)
_pic_large = models.URLField(max_length=500, blank=True, null=True, verify_exists=False, editable=False)
_pic_crop = models.URLField(max_length=500, blank=True, null=True, verify_exists=False, editable=False)
# get all posts for the selected profile
# posts = [p.post for p in page.post_throughs.select_related('post').all()]
if 'facebook.modules.connections.post' in settings.INSTALLED_APPS:
post_throughs = generic.GenericRelation('PagePost',
related_name="%(app_label)s_%(class)s_related")
class Meta(Base.Meta):
abstract = True
app_label = 'facebook'
def clean(self):
super(Profile, self).clean()
# Turn empty String into None for Uniqueness check.
self._username = self._username or None
def generate_slug(self):
# username is unique on facebook, but not every object has a username (ie. user have to make themself for pages and profiles)
if self._username:
if len(self._username) >= 50:
self.slug = '%s_%s' % (slugify(self._username)[:29], self.id)
self.slug = slugify(self._username)[:50]
elif self._name:
self.slug = slugify('%s-%s' % (self._name[:29], self.id))
else:
self.slug = slugify(self.id)
class ProfileAdmin(AdminBase):
def pic_img(self, obj):
return '<img src="%s" height="75" />' % obj._picture if obj._picture else ''
pic_img.allow_tags = True
pic_img.short_description = _('Picture')