Esempio n. 1
0
class Task(CachingModel):
  actor = models.StringProperty()     # ref - the owner of this queue item
  action = models.StringProperty()    # api call we are iterating through
  action_id = models.StringProperty() # unique identifier for this queue item
  args = models.StringListProperty()  # *args
  kw = properties.DictProperty()      # *kw
  expire = properties.DateTimeProperty()
                                      # when our lock will expire
  progress = models.StringProperty()  # a string representing the offset to 
                                      # which we've progressed so far
  created_at = properties.DateTimeProperty(auto_now_add=True)
  
  key_template = 'task/%(actor)s/%(action)s/%(action_id)s'
Esempio n. 2
0
class Subscription(CachingModel):
    """this represents a topic, usually a stream, that a subscriber
     (usually an inbox) would like to receive updates to
  """
    topic = models.StringProperty()  # ref - the stream being subscribed to
    subscriber = models.StringProperty()  # ref - the subscriber (actor)
    target = models.StringProperty()  # where to dump this
    state = models.StringProperty()  # The status of remote subs, see XEP-0060
    # sect 4.2. The 'pending' state is ignored if
    # the target of the subscription is used.
    # The design is for performance: on public
    # entries
    # the state is ignored and listing the
    # subscriptions is a single query; for
    # contacts-only entries the state is used but
    # it is also kept up-to-date regarding buddy
    # relationships, so a single query for
    # state='subscribed' can again be used.
    extra = properties.DictProperty()  # holds a bunch of stuff
    created_at = properties.DateTimeProperty(auto_now_add=True)
    # for ordering someday
    key_template = '%(topic)s/%(target)s'

    def is_subscribed(self):
        # LEGACY COMPAT: the 'or' here is for legacy compat
        return (self.state == 'subscribed' or self.state == None)
Esempio n. 3
0
class DeletedMarkerModel(CachingModel):
    deleted_at = properties.DateTimeProperty()

    def mark_as_deleted(self):
        self.deleted_at = datetime.datetime.utcnow()
        self.put()

    def is_deleted(self):
        return self.deleted_at
Esempio n. 4
0
    def test_datetimeproperty_validate(self):
        p = properties.DateTimeProperty()
        validated = p.validate("2008-01-01 02:03:04")
        self.assertEquals(validated, datetime.datetime(2008, 01, 01, 02, 03,
                                                       04))

        validated = None
        try:
            validated = p.validate("2008-01-01")
        except:
            pass

        self.assertEquals(validated, None)

        p = properties.DateTimeProperty()
        validated = p.validate("2008-01-01 02:03:04.000567")
        self.assertEquals(validated,
                          datetime.datetime(2008, 01, 01, 02, 03, 04, 567))
Esempio n. 5
0
class Presence(CachingModel):
    """This represents all the presence data for an actor at a moment in time.
  extra:
    status - string; message (like an "away message")
    location - string; TODO(tyler): Consider gps / cell / structured data
    availability - string; TODO(tyler): Define structure
  """
    actor = models.StringProperty()  # The actor whose presence this is
    updated_at = properties.DateTimeProperty(auto_now_add=True)
    # The moment we got the update
    uuid = models.StringProperty()
    extra = properties.DictProperty()  # All the rich presence
Esempio n. 6
0
class OAuthAccessToken(CachingModel):
    key_ = models.StringProperty()  # the token key
    secret = models.StringProperty()  # the token secret
    consumer = models.StringProperty()  # the consumer this key is assigned to
    actor = models.StringProperty()  # the actor this key authenticates for
    created_at = properties.DateTimeProperty(auto_now_add=True)
    # when this was created
    perms = models.StringProperty()  # read / write / delete

    key_template = 'oauth/accesstoken/%(key_)s'

    def to_string(self):
        token = oauth.OAuthToken(self.key_, self.secret)
        return token.to_string()
Esempio n. 7
0
class OAuthConsumer(CachingModel):
    key_ = models.StringProperty()  # the consumer key
    secret = models.StringProperty()  # the consumer secret
    actor = models.StringProperty()  # the actor who owns this
    status = models.StringProperty()  # active / pending / inactive
    type = models.StringProperty()  # web / desktop / mobile
    commercial = models.IntegerProperty()  # is this a commercial key?
    app_name = models.StringProperty()  # the name of the app this is for,
    # to be displayed to the user
    created_at = properties.DateTimeProperty(auto_now_add=True)

    key_template = 'oauth/consumer/%(key_)s'

    def url(self):
        return '/api/keys/%s' % self.key_
Esempio n. 8
0
class InboxEntry(CachingModel):
  """This is the inbox index for an entry.

  the index allows us to quickly pull the overview for a user. There may be
  items in the results that are later filtered out - deleted items or items
  whose privacy has changed.
  """
  inbox = models.StringListProperty()   # ref - who this is the inbox for
  stream = models.StringProperty()      # ref - the stream this belongs to
  stream_type = models.StringProperty() # separate because we may filter on it
  entry = models.StringProperty()       # ref - the entry if this is a comment
  created_at = properties.DateTimeProperty()
  uuid = models.StringProperty()
  shard = models.StringProperty()       # an identifier for this portion of
                                        # inboxes

  key_template = 'inboxentry/%(stream)s/%(uuid)s/%(shard)s'

  def stream_entry_keyname(self):
    """Returns the key name of the corresponding StreamEntry"""
    return "%s/%s" % (self.stream, self.uuid)
Esempio n. 9
0
class StreamEntry(DeletedMarkerModel):
    """
  extra :
    title - 
    location - 
    icon - 
    content - 
    entry_stream - 
    entry_stream_type - 
    entry_title - 
    entry_uuid - 
    comment_count - 
  """
    stream = models.StringProperty()  # ref - the stream this belongs to
    owner = models.StringProperty()  # ref - the actor who owns the stream
    actor = models.StringProperty()  # ref - the actor who wrote this
    entry = models.StringProperty()  # ref - the parent of this,
    #       should it be a comment
    uuid = models.StringProperty()
    created_at = properties.DateTimeProperty(auto_now_add=True)
    extra = properties.DictProperty()

    key_template = '%(stream)s/%(uuid)s'

    def url(self, with_anchor=True, request=None, mobile=False):
        if self.entry:
            # TODO bad?
            slug = self.entry.split("/")[-1]
            anchor = "#c-%s" % self.uuid
        else:
            # TODO(termie): add slug property
            slug = self.uuid
            anchor = ""
        path = "/%s/%s" % ('presence', slug)
        if with_anchor:
            path = "%s%s" % (path, anchor)
        return actor_url(_get_actor_urlnick_from_nick(self.owner),
                         _get_actor_type_from_nick(self.owner),
                         path=path,
                         request=request,
                         mobile=mobile)

    def keyname(self):
        """Returns the key name"""
        return self.key().name()

    def title(self):
        """ build a title for this entry, for a presence entry it will just be
    the title, but for a comment it will look like:

    Comment from [commenter nick] on [entry title] by [nick]

    Comment from [commenter nick] on [entry title] by [nick] to #[channel name]
    """

        if not self.is_comment():
            return self.extra.get('title')

        template = "Comment from %(actor)s on %(entry_title)s by %(entry_actor)s"
        actor = _get_actor_urlnick_from_nick(self.actor)
        entry_title = self.extra.get('entry_title')
        entry_actor = _get_actor_urlnick_from_nick(
            self.extra.get('entry_actor'))
        entry_owner_nick = util.get_user_from_topic(self.entry)
        entry_type = _get_actor_type_from_nick(entry_owner_nick)

        v = {
            'actor': actor,
            'entry_title': entry_title,
            'entry_actor': entry_actor,
        }

        if entry_type == 'channel':
            template += ' to #%(channel)s'
            channel = _get_actor_urlnick_from_nick(entry_owner_nick)
            v['channel'] = channel

        return template % v

    def is_comment(self):
        return (self.entry != None)

    def is_channel(self):
        return self.owner.startswith('#')

    def entry_actor(self):
        if self.entry:
            return util.get_user_from_topic(self.entry)
        return None
Esempio n. 10
0
class OAuthNonce(CachingModel):
    nonce = models.StringProperty()  # the nonce
    consumer = models.StringProperty()  # the consumer this nonce is for
    token = models.StringProperty()  # the token this nonce is for
    created_at = properties.DateTimeProperty(auto_now_add=True)
Esempio n. 11
0
class Actor(DeletedMarkerModel):
    """
  extra:
    contact_count - int; number of contacts
    follower_count - int; number of followers
    icon - string; avatar path
    bg_image - string; image for background (takes precedence over bg_color)
    bg_color - string; color for background
    bg_repeat - whether to repeat bg_image
    description [channel] - string; Channel description
    external_url [channel] - string; External url related ot channel
    member_count [channel] - int; number of members
    admin_count [channel] - int; number of admins
    email_notify [user] - boolean; does the user want email notifications?
    given_name [user] - string; First name
    family_name [user] - string; Last Name
    comments_hide [user] - boolean; Whether comments should be hidden on 
                             overview
  """
    nick = models.StringProperty()
    # the appengine datastore is case-sensitive whereas human brains are not,
    # Paul is not different from paul to regular people so we need a way to
    # prevent duplicate names from cropping up, this adds an additional indexed
    # property to support that
    normalized_nick = models.StringProperty()
    password = models.StringProperty()
    privacy = models.IntegerProperty()
    type = models.StringProperty()
    extra = properties.DictProperty()
    # avatar_updated_at is used by DJabberd to get a list of changed avatar. We
    # set the default to a date before the launch so that initial avatars have an
    # updated_at that is less than any real changes.
    avatar_updated_at = properties.DateTimeProperty(
        default=datetime.datetime(2009, 01, 01))

    key_template = 'actor/%(nick)s'

    def url(self, path="", request=None, mobile=False):
        """ returns a url, with optional path appended
    
    NOTE: if appending a path, it should start with '/'
    """
        return actor_url(_get_actor_urlnick_from_nick(self.nick),
                         self.type,
                         path=path,
                         request=request,
                         mobile=mobile)

    def shortnick(self):
        return _get_actor_urlnick_from_nick(self.nick)

    def display_nick(self):
        return self.nick.split("@")[0]
        return _get_actor_urlnick_from_nick(self.nick)

    def to_api(self):
        rv = super(Actor, self).to_api()
        del rv['password']
        del rv['normalized_nick']
        extra = {}
        for k, v in rv['extra'].iteritems():
            if k in ACTOR_ALLOWED_EXTRA:
                extra[k] = v
        rv['extra'] = extra
        return rv

    def to_api_limited(self):
        rv = self.to_api()
        extra = {}
        for k, v in rv['extra'].iteritems():
            if k in ACTOR_LIMITED_EXTRA:
                extra[k] = v
        rv['extra'] = extra
        return rv

    def is_channel(self):
        return self.type == 'channel'

    def is_public(self):
        return self.privacy == PRIVACY_PUBLIC

    def is_restricted(self):
        return self.privacy == PRIVACY_CONTACTS

    def __repr__(self):
        # Get all properties, but not directly as property objects, because
        # constructor requires values to be passed in.
        d = dict([(k, self.__getattribute__(k))
                  for k in self.properties().keys()])
        return "%s(**%s)" % (self.__class__.__name__, repr(d))