예제 #1
0
파일: person.py 프로젝트: marnanel/kepi
    def icon_or_default(self):
        if self.icon_image:
            return uri_to_url(self.icon_image)

        which = self.id % 10
        return uri_to_url('/static/defaults/avatar_{}.jpg'.format(
            which,
            ))
예제 #2
0
 def setUp(self):
     settings.KEPI['LOCAL_OBJECT_HOSTNAME'] = 'testserver'
     self.alice = create_local_person('alice')
     self.client = Client()
     self.alice_url = uri_to_url(settings.KEPI['USER_LINK'] % {
         'username': '******',
     })
예제 #3
0
    def url(self):
        if self.remote_url is not None:
            return self.remote_url

        return uri_to_url(settings.KEPI['STATUS_LINK'] % {
                'username': self.account.username,
                'id': self.id,
                })
예제 #4
0
    def activity_url(self):
        if self.remote_url is not None:
            raise ValueError(
                    "Activity URL is not stored for remote statuses",
                    )

        return uri_to_url(settings.KEPI['STATUS_ACTIVITY_LINK'] % {
                'username': self.account.username,
                'id': self.id,
                })
예제 #5
0
    def test_get_single_status(self):
        self._alice = create_local_person(name='alice')

        self._status = create_local_status(
            content='Hello world.',
            posted_by=self._alice,
        )

        content = self.get(
            path='/api/v1/statuses/' + str(self._alice.id),
            as_user=self._alice,
        )

        for field, expected in STATUS_EXPECTED.items():
            self.assertIn(field, content)
            self.assertEqual(content[field],
                             expected,
                             msg="field '{}'".format(field))

        self.assertIn('account', content)
        account = content['account']

        account_expected = ACCOUNT_EXPECTED.copy()
        account_expected['statuses_count'] = 1

        for field, expected in account_expected.items():

            if field.startswith('status['):
                # this doesn't give us the status dict
                continue

            self.assertIn(field, account)
            self.assertEqual(account[field],
                             expected,
                             msg="account field '{}'".format(field))

        self.assertIn('id', content)

        self.assertIn('url', content)
        self.assertEqual(
            content['url'],
            uri_to_url(settings.KEPI['STATUS_LINK'] % {
                'username': '******',
                'id': content['id'],
            }))
예제 #6
0
    def _do_something_with(self, the_person, request):

        try:

            if the_person.auto_follow:
                offer = None
            else:
                number = random.randint(0, 0xffffffff)
                offer = uri_to_url(settings.KEPI['FOLLOW_REQUEST_LINK'] % {
                    'username': request.user.username,
                    'number': number,
                })

            follow = trilby_models.Follow(
                follower=request.user.localperson,
                following=the_person,
                offer=offer,
            )

            with transaction.atomic():
                follow.save(send_signal=True, )

            logger.info('  -- follow: %s', follow)
            logger.debug('    -- offer ID: %s', offer)

            if the_person.auto_follow:
                follow_back = trilby_models.Follow(
                    follower=the_person,
                    following=request.user.localperson,
                    offer=None,
                )

                with transaction.atomic():
                    follow_back.save(send_signal=True, )

                logger.info('  -- follow back: %s', follow_back)

            return the_person

        except IntegrityError:
            logger.info('  -- not creating a follow; it already exists')
예제 #7
0
파일: person.py 프로젝트: marnanel/kepi
 def followers_url(self):
     return uri_to_url(settings.KEPI['USER_FOLLOWERS_LINK'] % {
         'username': self.local_user.username,
         })
예제 #8
0
파일: person.py 프로젝트: marnanel/kepi
 def featured_url(self):
     return uri_to_url(settings.KEPI['USER_FEATURED_LINK'] % {
         'username': self.local_user.username,
         })
예제 #9
0
파일: person.py 프로젝트: marnanel/kepi
 def outbox_url(self):
     return uri_to_url(settings.KEPI['USER_OUTBOX_LINK'] % {
         'username': self.local_user.username,
         })
예제 #10
0
파일: person.py 프로젝트: marnanel/kepi
    def header_or_default(self):
        if self.header_image:
            return uri_to_url(self.header_image)

        return uri_to_url('/static/defaults/header.jpg')
예제 #11
0
 def to_representation(self, instance):
     return {
         'sharedInbox': uri_to_url(settings.KEPI['SHARED_INBOX_LINK'], ),
     }