コード例 #1
0
class ContactFB(Contact):
    facebook_id = models.CharField(max_length=150, db_index=True)
    first_name = models.CharField(max_length=50,
                                  null=True,
                                  blank=True,
                                  db_index=True)
    last_name = models.CharField(max_length=50,
                                 null=True,
                                 blank=True,
                                 db_index=True)
    objects = CacheBotManager()

    class Meta:
        unique_together = (('owner', 'facebook_id'))


#    def save(self, *args, **kwargs):
#        if not self.name and (self.first_name or self.last_name):
#            self.name = ("%s %s" % (self.first_name, self.last_name)).strip()
#        super(Contact,self).save(*args, **kwargs)
#        return self

    def send_invite(self):
        self.invited = True
        self.create_date = datetime.now()

        self.save()

    def key(self):
        return 'fb_' + str(self.id)

    key = property(key)
コード例 #2
0
class Place(models.Model):
    owner = models.ForeignKey(User, related_name="places", db_index=True)
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=200)
    objects = CacheBotManager()

    class Meta:
        app_label = 'places'
コード例 #3
0
class Zip_Prox(models.Model):
    zip = models.ForeignKey(Zip, related_name='zip_prox', db_index=True)
    prox_zip = models.ForeignKey(Zip, related_name='+', db_index=True)
    dst = models.CharField(max_length=5)

    objects = CacheBotManager()

    class Meta:
        app_label = 'places'
コード例 #4
0
class MessagePreferenceDefaults(models.Model):
    type = models.CharField(_('Message Type'), max_length=40)
    send = models.BooleanField(_('Send?'))
    objects = CacheBotManager()

    class Meta:
        verbose_name = _("message preference default")
        verbose_name_plural = _("message preference defaults")
        unique_together = ("type", )
        app_label = 'notify'
コード例 #5
0
ファイル: models.py プロジェクト: bopopescu/pd
class Zip_School_Prox(models.Model):
    zip = models.ForeignKey(Zip, related_name='school_prox', db_index=True)
    school = models.ForeignKey(School, related_name='+', db_index=True)
    dst = models.CharField(max_length=5)
    name = models.CharField(max_length=100, null=True, blank=True)

    class Meta:
        unique_together = ("zip", "school")

    objects = CacheBotManager()
コード例 #6
0
ファイル: models.py プロジェクト: bopopescu/pd
class Album(models.Model):
    title = models.CharField(_('title'), max_length=101)
    date_added = models.DateTimeField(_('date published'),
                                      default=datetime.now)
    created_by = models.ForeignKey(User,
                                   related_name='albums',
                                   null=True,
                                   blank=True,
                                   db_index=True)
    description = models.TextField(_('description'), blank=True)
    comments = generic.GenericRelation(Comment)

    content_type = models.ForeignKey(ContentType, null=True, blank=True)
    object_id = models.IntegerField(null=True, blank=True)
    owner = generic.GenericForeignKey('content_type', 'object_id')

    objects = CacheBotManager()

    class Meta:
        app_label = 'photos'
        ordering = ['-date_added']
        get_latest_by = 'date_added'
        verbose_name = _('gallery')
        verbose_name_plural = _('galleries')

    def can_view_album(self, user):
        if not user.is_authenticated():
            return False

        owner = self.owner
        return owner.can_view_photo(user)

    def can_upload_photo(self, user):
        if not user.is_authenticated():
            return False
        owner = self.owner
        return owner.can_upload_photo(user)

    def can_delete_photo(self, user):
        if not user.is_authenticated():
            return False

        owner = self.owner
        return owner.can_upload_photo(user)

    def owner_name(self):
        return self.owner.name

    def set_profile_language(self):
        if not user.is_authenticated():
            return False

        return self.owner.set_profile_language()

    owner_name = property(owner_name)
コード例 #7
0
class FriendSuggestion(models.Model):
    child = models.ForeignKey(Child,
                              related_name="suggested_friends",
                              db_index=True)
    suggested_child = models.ForeignKey(Child, related_name="+")
    why = models.IntegerField(null=True,
                              blank=True,
                              choices=SUGGEST_WHY_CHOICES)
    active = models.BooleanField(default=True)

    objects = CacheBotManager()
コード例 #8
0
class UserUpdate(models.Model):
    user = models.ForeignKey(User,
                             verbose_name=_('user'),
                             related_name="updates",
                             db_index=True)
    update = models.ForeignKey(Update, db_index=True)
    unseen = models.BooleanField(_('unseen'), default=True)
    archived = models.BooleanField(_('archived'), default=False)
    added = models.DateTimeField(_('added'), null=True, blank=True)

    objects = CacheBotManager()

    class Meta:
        ordering = ["-added"]
        app_label = 'notify'
コード例 #9
0
ファイル: models.py プロジェクト: bopopescu/pd
class Account(models.Model):
    
    user = models.ForeignKey(User, unique=True, verbose_name=_("user"))
    
    timezone = TimeZoneField(_("timezone"))
    language = models.CharField(_("language"),
        max_length = 10,
        choices = settings.LANGUAGES,
        default = settings.LANGUAGE_CODE
    )
    objects = CacheBotManager()

    
    def __unicode__(self):
        return self.user.username
コード例 #10
0
class MessagePreference(models.Model):
    """
    Indicates, for a given user, whether to send notifications
    of a given type to a given medium.
    """

    user = models.ForeignKey(User, verbose_name=_('user'))
    type = models.CharField(_('Message Type'), max_length=40)
    send = models.BooleanField(_('Send?'))
    objects = CacheBotManager()

    class Meta:
        verbose_name = _("message preference")
        verbose_name_plural = _("message preferences")
        unique_together = ("user", "type")
        app_label = 'notify'
コード例 #11
0
ファイル: models.py プロジェクト: bopopescu/pd
class School(models.Model):
    gsid = models.CharField(max_length=15, db_index=True, unique=True)
    name = models.CharField(max_length=100, db_index=True)
    type = models.CharField(max_length=50, null=True, blank=True)
    city = models.CharField(max_length=100, null=True, blank=True)
    state = models.CharField(max_length=2,
                             null=True,
                             blank=True,
                             db_index=True)
    zip = models.CharField(max_length=8, null=True, blank=True, db_index=True)
    lat = models.CharField(max_length=15, null=True, blank=True)
    lon = models.CharField(max_length=15, null=True, blank=True)
    district_name = models.CharField(max_length=50, null=True, blank=True)
    street = models.CharField(max_length=50, null=True, blank=True)
    phone = models.CharField(max_length=20, null=True, blank=True)
    level = models.CharField(max_length=20, null=True, blank=True)
    gsurl = models.CharField(max_length=300, null=True, blank=True)

    pd = models.BooleanField(default=False)

    objects = CacheBotManager()

    def summary(self):
        summary = ''
        if self.city is not None:
            summary = summary + self.city + "'s"

        summary = summary + ' ' + self.name

        if self.level is not None:
            summary = summary + ' serves grades ' + self.level

        if self.district_name is not None and len(self.district_name) > 0:
            summary = summary + ' in the ' + self.district_name

        summary = summary + '.'

        return summary

    summary = property(summary)

    def short_name(self):
        if len(self.name) > 20:
            return self.name[0:17] + "..."
        return self.name

    short_name = property(short_name)
コード例 #12
0
ファイル: models.py プロジェクト: bopopescu/pd
class Photo(ImageModel):
    caption = models.CharField(max_length=201)
    original_image = models.ImageField(upload_to='photos')
    date_added = models.DateTimeField(_('date added'), default=datetime.now)
    album = models.ForeignKey(Album, related_name='photos', db_index=True)

    comments = generic.GenericRelation(Comment)

    objects = CacheBotManager()

    class IKOptions:
        spec_module = 'photos.specs'
        cache_dir = 'photos/'
        image_field = 'original_image'
        preprocessor_spec = Original

    class Meta:
        app_label = 'photos'
        ordering = ['-date_added']
        get_latest_by = 'date_added'
        verbose_name = _("photo")
        verbose_name_plural = _("photos")

    def mp(self):
        return self.prof125.url

    def sp(self):
        return self.prof50.url

    def can_view_photo(self, user):
        if not user.is_authenticated():
            return False

        owner = self.album.owner
        return owner.can_view_photo(user)

    def can_view_comments(self, user):

        return self.can_view_photo(user)

    def can_delete_photo(self, user):
        if not user.is_authenticated():
            return False

        owner = self.album.owner
        return owner.can_upload_photo(user)
コード例 #13
0
ファイル: invites.py プロジェクト: bopopescu/pd
class InviteDesign(models.Model):
    subject = models.CharField(max_length=140,
                               db_index=True,
                               null=True,
                               blank=True)
    html = models.TextField(_("Design HTML"))
    title = models.CharField(max_length=100, db_index=True)
    description = models.TextField(_("Design Description"),
                                   null=True,
                                   blank=True)
    small_image = models.URLField(max_length=200, null=True, blank=True)
    big_image = models.URLField(max_length=200, null=True, blank=True)

    objects = CacheBotManager()

    class Meta:
        app_label = 'playdates'
コード例 #14
0
class MessageContent(models.Model):
    # friend_request, photo_tagged, added_child, etcc.
    type = models.CharField(_('Message Type'), max_length=40)
    # update , message, email, fbpost
    medium = models.CharField(_('Medium'),
                              max_length=20,
                              choices=MESSAGE_MEDIA)
    # subject vs body - some message types don't need a subject
    part = models.CharField(_('Message Part'),
                            max_length=20,
                            choices=MESSAGE_PARTS)
    # actual django content template string.
    content = models.TextField(_("Content"))
    objects = CacheBotManager()

    class Meta:
        unique_together = ("type", "medium", "part")
        app_label = 'notify'
コード例 #15
0
class Update(Message):
    owner = models.ForeignKey(User,
                              verbose_name=_('user'),
                              related_name="my_updates",
                              db_index=True)
    message = models.TextField(_('message'))
    update_type = models.CharField(_('update type'),
                                   max_length=10,
                                   choices=UPDATE_TYPES,
                                   default="general")
    when = models.DateTimeField(_('added'), default=datetime.datetime.now)
    added = models.DateTimeField(_('added'), default=datetime.datetime.now)
    archived = models.BooleanField(_('archived'), default=False)
    deleted = models.BooleanField(_('deleted'), default=False)

    medium = 'update'

    objects = CacheBotManager()

    def __unicode__(self):
        return self.message

    def archive(self):
        self.archived = True
        self.save()

    def is_unseen(self):
        """
        returns value of self.unseen but also changes it to false.

        Use this in a template to mark an unseen notice differently the first
        time it is shown.
        """
        unseen = self.unseen
        if unseen:
            self.unseen = False
            self.save()
        return unseen

    class Meta:
        ordering = ["-added"]
        verbose_name = _("update")
        verbose_name_plural = _("updates")
        app_label = 'notify'
コード例 #16
0
ファイル: models.py プロジェクト: bopopescu/pd
class Occurrence(models.Model):
    event = models.ForeignKey(Event, verbose_name=_("event"))
    start = models.DateTimeField(_("start"))
    end = models.DateTimeField(_("end"))
    cancelled = models.BooleanField(_("cancelled"), default=False)
    original_start = models.DateTimeField(_("original start"))
    original_end = models.DateTimeField(_("original end"))

    objects = CacheBotManager()

    class Meta:
        verbose_name = _("occurrence")
        verbose_name_plural = _("occurrences")
        app_label = 'schedule'

    def moved(self):
        return self.original_start != self.start or self.original_end != self.end

    moved = property(moved)
コード例 #17
0
ファイル: models.py プロジェクト: bopopescu/pd
class Adult_Child(models.Model):
    adult = models.ForeignKey(User,
                              related_name='attached_children',
                              db_index=True)
    child = models.ForeignKey(Child,
                              related_name='attached_adults',
                              db_index=True)
    relation = models.CharField(max_length=5, choices=RELATION_TYPES)
    can_edit_profile = models.BooleanField(_("Can Edit Child Profile"),
                                           default=False)
    can_view_schedule = models.BooleanField(_("Can View Child Schedule"),
                                            default=False)
    can_edit_schedule = models.BooleanField(_("Can Edit Child Schedule"),
                                            default=False)
    can_view_playlist = models.BooleanField(_("Can View Child Playlist"),
                                            default=False)
    can_edit_playlist = models.BooleanField(_("Can Edit Child Playlist"),
                                            default=False)
    can_view_photos = models.BooleanField(_("Can View Photos"), default=False)
    can_upload_photos = models.BooleanField(_("Can Upload Photos"),
                                            default=False)
    access_role = models.CharField(_("Access Role"),
                                   max_length=10,
                                   choices=ACCESS_ROLES,
                                   default='admin',
                                   null=False)
    can_display_child = models.BooleanField(_("Show Child on Profile?"),
                                            default=False)

    objects = CacheBotManager()

    def set_admin_perms(self):
        self.can_edit_profile = self.can_view_schedule = self.can_edit_schedule = self.can_view_playlist = self.can_edit_playlist = True
        self.can_view_photos = self.can_upload_photos = self.can_display_child = True
        self.access_role = 'admin'

    def is_admin(self):
        if self.access_role == 'admin':
            return True
        return False

    is_admin = property(is_admin)
コード例 #18
0
class Zip(models.Model):
    zip = models.CharField(max_length=10, db_index=True, unique=True)
    state = models.CharField(max_length=2)
    lat = models.CharField(max_length=10)
    lon = models.CharField(max_length=10)
    city = models.CharField(max_length=50,
                            null=True,
                            blank=True,
                            db_index=True)
    state_full = models.CharField(max_length=50,
                                  null=True,
                                  blank=True,
                                  db_index=True)
    objects = CacheBotManager()

    class Meta:
        app_label = 'places'

    def __str__(self):
        return self.city + ' ' + self.state
コード例 #19
0
class ContactEmail(Contact):
    first_name = models.CharField(max_length=50,
                                  null=True,
                                  blank=True,
                                  db_index=True)
    last_name = models.CharField(max_length=50,
                                 null=True,
                                 blank=True,
                                 db_index=True)
    import_job = models.IntegerField(null=True, blank=True, db_index=True)
    email = models.EmailField(db_index=True)
    objects = CacheBotManager()

    class Meta:
        unique_together = (('owner', 'email'))

    def save(self, *args, **kwargs):
        if not self.name and (self.first_name or self.last_name):
            self.name = ("%s %s" % (self.first_name, self.last_name)).strip()
        super(Contact, self).save(*args, **kwargs)
        return self

    def send_invite(self):
        self.invited = True
        self.create_date = datetime.now()

        JoinInvitationEmail.objects.send_invitation(self.owner,
                                                    self,
                                                    self.email,
                                                    message=None)

        self.save()

    def key(self):
        return 'ce_' + str(self.id)

    key = property(key)
コード例 #20
0
ファイル: test_models.py プロジェクト: bopopescu/pd
class UniqueModel(models.Model):
    text = models.CharField(max_length=50, unique=True)
    objects = CacheBotManager(cache_get=True)
コード例 #21
0
ファイル: test_models.py プロジェクト: bopopescu/pd
class GenericModel(models.Model):
    text = models.CharField(max_length=50)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    obj = generic.GenericForeignKey('content_type', 'object_id')
    objects = CacheBotManager(cache_get=True)
コード例 #22
0
class PlaydateInviteUser(PlaydateInvite):
    playdate = models.ForeignKey(Playdate, related_name="user_invites", db_index=True)
    to_user = models.ForeignKey(User, db_index=True)
    to_child = models.ForeignKey(Child, db_index=True)
    organizer_child = models.ForeignKey(Child, related_name='my_user_invitees')
    is_user = True
    childview = None
    type = 'user'

    objects = CacheBotManager()

    class Meta:
        app_label='playdates'
        unique_together = ("playdate","to_child")


    def is_organizer(self):
        if self.to_user == self.playdate.organizer:
            return True
        return False
    is_organizer = property(is_organizer)

    def to(self):
        return self.to_user.get_profile().name

    to = property(to)


    def child(self):
        return self.to_child.first_name

    def possessive(self):
        return self.to_user.get_profile().possessive

    possessive = property(possessive)

    def playdate_url(self):
        return 'http://'+settings.WWW_HOST+reverse("view_playdate", kwargs={"playdate_id":self.playdate_id})
    playdate_url = property(playdate_url)

    def accept_and_notify(self, notify=True):
        changed = self.accept()

        if changed:
            self.notify_organizer(notify, 'playdate_attendance_confirmed')
    
            ctx = {
                   'invitee': self.to_user,
                   'invitee_child':self.to_child,
                   'organizer': self.playdate.organizer,
                   'playdate':self.playdate,
                   'type':self.type,
                   'invite':self,
            }
    
            self.phone = self.to_user.get_profile().phone
    
            self.playdate.notify_invitees(ctx, 'notify_attendees_accept', [ (self.type, self.id, self), ])


    def invite_invitee(self, message_type):
        ctx = {
            'actor': self.playdate.organizer.get_profile(),
            'actor_child': self.organizer_child,
            'actee':self.to_user.get_profile(),
            'actee_child':self.to_child,
            'message':self.playdate.details,
            'playdate':self.playdate,
            'playdate_url':self.playdate_url,
        }

        create_message(self.playdate.organizer, self.to_user, message_type, ctx, category='Playdate Request', associated_item=self.playdate.id)

        send_invite_email(self.to_user.email, self.playdate.invite_design, ctx)


    
    def notify_invitee(self, notify, ctx, message_type):
        if not notify:
            return True

        ctx.update({ 
          'this_invite':self,            
        })


        create_message(self.playdate.organizer, self.to_user, message_type, ctx, respond=False)

        email_pref = get_message_preference(self.to_user, 'playdate_attendee_related')

        if email_pref:
            send_email(self.to_user.email, message_type, ctx)        

    def notify_organizer(self, notify, message_type):

        if not notify:
            return True
        
        ctx = {
            'actor':self.to_user.get_profile(),
            'actor_child':self.to_child,
            'actee': self.playdate.organizer.get_profile(),
            'actee_child': self.organizer_child,
            'response':self.response,
            'playdate':self.playdate,
            'active_invite':self,
        }

        create_message(self.to_user, self.playdate.organizer, message_type, ctx, respond=False)

        email_pref = get_message_preference(self.playdate.organizer, 'playdate_host_related')

        if email_pref:
            send_email(self.playdate.organizer.email, message_type, ctx)
コード例 #23
0
class PlaydateInviteEmail(PlaydateInvite):
    playdate = models.ForeignKey(Playdate, related_name="email_invites", db_index=True)
    email = models.EmailField(db_index=True)
    token = models.CharField(max_length=30)
    name = models.CharField(max_length=50, null=True, blank=True)
    organizer_child = models.ForeignKey(Child, related_name='my_email_invitees')
    is_user = False
    type = 'email'
    objects = CacheBotManager()

    class Meta:
        app_label='playdates'
        unique_together = ("playdate","email")

    def to(self):
        return self.email
    to = property(to)


    def playdate_url(self):
        return 'http://'+settings.WWW_HOST+reverse("view_playdate_with_token", kwargs={"playdate_id":self.playdate_id,"token":self.token})
    playdate_url = property(playdate_url)

    def assign_token(self):
        import os
        return (os.urandom(10).encode('hex'))


    def accept_and_notify(self, notify=True):
        changed = self.accept()

        if changed:
            self.notify_organizer(notify, 'playdate_attendance_confirmed')
    
            ctx = {
                   'invite': self,
                   'email': self.email,
                   'organizer': self.playdate.organizer,
                   'playdate':self.playdate,
                   'type':self.type,
            }
    
            self.playdate.notify_invitees(ctx, 'notify_attendees_accept', [ (self.type, self.id, self), ])



    def invite_invitee(self, message_type):
        ctx = {
            'email': self.email,
            'actor': self.playdate.organizer.get_profile(),
            'actor_child': self.organizer_child,
            'message':self.playdate.details,
            'playdate':self.playdate,
            'invite_id':self.id,
            'token':self.token,
            'playdate_url':self.playdate_url,

        }

        
        send_invite_email(self.email, self.playdate.invite_design, ctx)


    
    def notify_invitee(self, notify, ctx, message_type):
        if not notify:
            return True

        ctx.update({ 
          'this_invite':self,            
        })

        send_email(self.email, message_type, ctx)
        


    def notify_organizer(self, notify, message_type):

        if not notify:
            return True
        
        ctx = {
            'email': self.email,
            'actee': self.playdate.organizer.get_profile(),
            'actee_child': self.organizer_child,
            'response':self.response,
            'playdate':self.playdate,
            'active_invite':self,
        }

        create_message_anon(self.playdate.organizer, message_type, ctx)

        email_pref = get_message_preference(self.playdate.organizer, 'playdate_host_related')

        if email_pref:
            send_email(self.playdate.organizer.email, message_type, ctx)
コード例 #24
0
ファイル: test_models.py プロジェクト: bopopescu/pd
class NoCacheModel(models.Model):
    text = models.CharField(max_length=50)
    objects = CacheBotManager(cache_get=False)
コード例 #25
0
class PDActivity(models.Model):
    name = models.CharField(_('Activity Name'), max_length=50)
    objects = CacheBotManager()

    class Meta:
        app_label='playdates'
コード例 #26
0
ファイル: test_models.py プロジェクト: bopopescu/pd
class FirstModel(models.Model):
    text = models.CharField(max_length=50)
    objects = CacheBotManager(cache_get=True)
コード例 #27
0
class Playdate(Activity):
    type = 'playdate'
    organizer = models.ForeignKey(User)

    is_dropoff = models.BooleanField(_("Is this a dropoff"), default=True)        
    phone = models.CharField(_("phone"), max_length=15,null=False, blank=True)

    details = models.TextField(_("Details"), null=True, blank=True)
    max_participants = models.PositiveIntegerField(_("Maximum Number of Participants"), null=True, blank=True)
    expire_option = models.CharField(_("Expiration Option"), max_length=5, choices=EXPIRE_OPTIONS, null=True, blank=True)

    min_participants = models.PositiveIntegerField(_("Maximum Number of Participants"), null=True, blank=True)
    invite_design = models.ForeignKey(InviteDesign, null=True, blank=True)
    address = models.TextField(_("Address"), null=False)
    comments = generic.GenericRelation(Comment)
    photo = models.ForeignKey(Photo, null=True, blank=True, default=settings.DEFAULT_PROFILE_PHOTO_ID, db_index=True) #should be a constant
    album = models.ForeignKey(Album, null=True, blank=True, db_index=True, related_name='+')
    activity = models.ForeignKey(PDActivity, null=True, blank=True, db_index=True, related_name='+')
    status = models.CharField(_("Playdate Status"), max_length=2, choices=STATUS_OPTIONS, default='1')
    create_date = models.DateTimeField(default=datetime.datetime.now, blank=True, null=True)


    deleteable = False

    request_user = None
    _event = None
    _invites = None
    objects = CacheBotManager()


    class Meta:
        app_label='playdates'

    def scheduled(self):
        if self.status == '2':
            return True
        return False

    scheduled = property(scheduled)

    def canceled(self):
        if self.status == '3':
            return True
        return False

    canceled = property(canceled)


    def cancel(self):
        self.status = '3'
        self.save()
#        self.update_event_plans(self.status)

        ctx = {
               'organizer': self.organizer.get_profile(),
               'playdate':self,
        }

        message_type='playdate_canceled'

        self.notify_attending(ctx, message_type)


    def update_status(self):
        current_status = self.status

        new_status = '1'
        for invite in self.invites:
            if invite.yes and not invite.is_organizer:
                new_status = '2'

        if current_status != new_status:
            self.status = new_status
            self.save()

            if new_status == '2':
                self.update_event_plans(current_status)

    def update_event_plans(self, current_playdate_status):
        attending_children = []
        for invite in self.user_invites.all():
            if invite.yes:
                attending_children.append(invite.to_child_id)

        for ep in self.get_event.children.all():
            if ep.child_id in attending_children:
                ep.remove_availability_for_this_timeslot()

    def status_verbose(self):
        if self.status == '1':
            return 'Pending'
        elif self.status == '2':
            return 'Scheduled'
        elif self.status == '3':
            return 'Cancelled'
        else:
            raise Exception('invalid status')
        

    def save(self, *args, **kwargs):
        new = False
        if not self.id:
            album = Album(title="Playdate Photos", created_by=self.organizer)
            album.save()
            self.album=album;
            new=True
        
        super(Playdate, self).save(*args, **kwargs)
        if new:
            self.album.owner = self
            self.album.save()

    def get_event(self):
        if self._event is None:
            self._event = list(self.event.all())[0]
        
        return self._event

    get_event = property(get_event)

    def start(self):        
        return self.get_event.start
    
    start = property(start)
    
    def end(self):
        return self.get_event.end
    
    end = property(end)


    def set_profile_pic(self, np):
        self.photo=np
        self.save()

    def can_view_photo(self, user):
        can_view_children = {}
        for ac in user.get_profile().view_photo_children:
            can_view_children[ac.child_id] = True
            
        for u in self.user_invites.all():
            if u.to_child_id in can_view_children:
                return True
        return False


    def can_upload_photo(self, user):
        if not user.is_authenticated():
            return False
        can_upload_children = {}
        for ac in user.get_profile().upload_photo_children:
            can_upload_children[ac.child_id] = True

        for u in self.user_invites.all():
            if u.to_child_id in can_upload_children:
                return True

        return False

    def set_profile_language(self):
        return 'set as playdate album photo'

    
    def invites(self):
        if self._invites is None:
            self._invites = list(chain(self.user_invites.select_related('to_child','to_user','to_child__photo','to_child__album','to_child__school','to_user___profile_cache','to_user___profile_cache__photo','to_user___profile_cache__album').all(), 
                     self.email_invites.all(),
                     self.fb_invites.select_related('facebook_contact').all()))
        return self._invites


    def invites_list(self):
        return self.invites
    
    invites = property(invites)
                  
    def response_breakdown(self):
        response = {}

        for invite in self.invites_list():
            if not invite.current_status in response:
                response[invite.current_status] = [] 
            response[invite.current_status].append(invite)        
        return response
        
    def direct_url(self):
        return 'http://' + settings.WWW_HOST + reverse("view_playdate", kwargs={"playdate_id":self.id})

    direct_url = property(direct_url)

    def summary(self):
        summary_text = 'Playdate'
        if self.status == '1':
            summary_text = 'Pending Playdate'
        elif self.status == '2':
            summary_text = 'Confirmed Playdate'
        elif self.status == '3':
            summary_text = 'Cancelled Playdate'

        return(summary_text)
    
    def title(self):
        return("Playdate - " + self.event.start.strftime("%B %d, %Y"))

    title = property(title)

    name = property(title)

    def summary_body(self):
        return(self.details +" click <a href='"+ reverse("view_playdate", kwargs={"playdate_id":self.id}) +"'>here</a> for more details" )


    def notify_invitees(self, ctx, message_type, exclude_list = []):
        exclude_hash = { 'email': {}, 'facebook': {}, 'user': {} }

        dedupe_hash = { 'email': {}, 'facebook': {}, 'user': {} }
        for (type, id, obj) in exclude_list:
            exclude_hash[type][id] = obj
            dedupe_hash[type][obj.to] = True 
        
        for invite in self.invites:
            if invite.id in exclude_hash[invite.type]:
                continue

            if invite.type == 'user' and invite.to_user == self.organizer:
                continue

            if invite.to in dedupe_hash[invite.type]:
                continue
            else:
                dedupe_hash[invite.type][invite.to]=True

            ctx.update({ 'active_invite':invite,  })
            invite.notify_invitee(True, ctx, message_type)

    def notify_attending(self, ctx, message_type, exclude_list = []):
        exclude_hash = { 'email': {}, 'facebook': {}, 'user': {} }

        dedupe_hash = { 'email': {}, 'facebook': {}, 'user': {} }

        for (type, id, obj) in exclude_list:
            exclude_hash[type][id] = True
        
        for invite in self.invites:
            if invite.id in exclude_hash[invite.type]:
                continue

            if invite.type == 'user' and invite.to_user == self.organizer:
                continue

            if invite.to in dedupe_hash[invite.type]:
                continue
            else:
                dedupe_hash[invite.type][invite.to]=True

            if invite.yes:
                ctx.update({ 'active_invite':invite,  })
                invite.notify_invitee(True, ctx, message_type)


    def can_view_comments(self,user):
        return True
コード例 #28
0
ファイル: test_models.py プロジェクト: bopopescu/pd
class ThirdModel(models.Model):
    text = models.CharField(max_length=50)
    obj = models.ForeignKey(SecondModel)
    objects = CacheBotManager(cache_get=True)
コード例 #29
0
class PlaydateInviteFB(PlaydateInvite):
    playdate = models.ForeignKey(Playdate, related_name="fb_invites", db_index=True)
    facebook_contact = models.ForeignKey(ContactFB)
    organizer_child = models.ForeignKey(Child, related_name='my_fb_invitees')
    is_user = False
    type = 'facebook'
    
    objects = CacheBotManager()

    class Meta:
        app_label='playdates'
        unique_together = ("playdate","facebook_contact")
        


    def accept_and_notify(self, notify=True):
        changed = self.accept()

        if changed:
            self.notify_organizer(notify, 'playdate_attendance_confirmed')
    
            ctx = {
                   'name':self.to,
                   'organizer': self.playdate.organizer,
                   'playdate':self.playdate,
                   'type':self.type,
            }
    
            self.playdate.notify_invitees(ctx, 'notify_attendees_accept', [ (self.type, self.id, self), ])
    
    
    def to(self):
        return self.facebook_contact.first_name + ' ' + self.facebook_contact.last_name

    to = property(to)

    def notify_invitee(self, notify, ctx, message_type):
        if not notify:
            return True

        # how do you notify facebook users? -- no email address - or is there? - i can collect it when they click through.

        return True

    def playdate_url(self):
        return 'http://'+settings.WWW_HOST+reverse("view_playdate_with_fb", kwargs={"playdate_id":self.playdate_id, "invite_id":self.id })
    playdate_url = property(playdate_url)
   
    def invite_invitee(self, message_type):
    
        ctx = {
            'actor': self.playdate.organizer.get_profile(),
            'actor_child': self.organizer_child,
            'message':self.playdate.details,
            'playdate':self.playdate,
            'invite_id':self.id,
            'contact': self.facebook_contact,
        }


        actee_fb_id = self.facebook_contact.facebook_id
        access_token = list(self.playdate.organizer.fbuser.all())[0].access_token
        args = {
                'link': self.playdate_url,
                'attribution':'Playdation',
                'name':'You Have a Playdate Invite',
                'description':"Playdation is what the other parents and I are now using to schedule our children's playdates.",
                'picture':'http://'+settings.WWW_HOST+'/static/images/feed-invite.png',
                'actions':{'name':'See Your Invite', 'link':self.playdate_url }
                } 

        post_to_other_facebook(access_token,actee_fb_id, message_type, ctx, **args)


    def notify_organizer(self, notify, message_type):

        if not notify:
            return True
        
        ctx = {
            'contact': self.facebook_contact,
            'actee': self.playdate.organizer.get_profile(),
            'actee_child': self.organizer_child,
            'response':self.response,
            'playdate':self.playdate,
            'playdate_url':self.playdate_url,
            'active_invite':self,
        }

        create_message_anon(self.playdate.organizer, message_type, ctx)

        email_pref = get_message_preference(self.playdate.organizer, 'playdate_host_related')

        if email_pref:
            send_email(self.playdate.organizer.email, message_type, ctx)
コード例 #30
0
ファイル: test_models.py プロジェクト: bopopescu/pd
class ManyModel(models.Model):
    text = models.CharField(max_length=50)
    firstmodel = models.ManyToManyField(FirstModel)
    thirdmodel = models.ManyToManyField(ThirdModel)
    objects = CacheBotManager(cache_get=True)