예제 #1
0
    def setUp(self):
        super(SniptResourceTest, self).setUp()

        # Johnny
        self.johnny = User.objects.create_user('johnny', '*****@*****.**',
                                               'password')
        ApiKey.objects.get_or_create(user=self.johnny)
        self.johnny_auth = self.create_apikey(self.johnny,
                                              self.johnny.api_key.key)
        self.johnny_private = Snipt(title='Private snipt for Johnny',
                                    lexer='text',
                                    public=False,
                                    user=self.johnny)
        self.johnny_public = Snipt(title='Public snipt for Johnny',
                                   lexer='text',
                                   public=True,
                                   user=self.johnny)
        self.johnny_private.save()
        self.johnny_public.save()

        # Bob
        self.bob = User.objects.create_user('bob', '*****@*****.**', 'password')
        ApiKey.objects.get_or_create(user=self.bob)
        self.bob_auth = self.create_apikey(self.bob, self.bob.api_key.key)
        self.bob_private = Snipt(title='Private snipt for Bob',
                                 lexer='text',
                                 public=False,
                                 user=self.bob)
        self.bob_public = Snipt(title='Public snipt for Bob',
                                lexer='text',
                                public=True,
                                user=self.bob)
        self.bob_private.save()
        self.bob_public.save()
예제 #2
0
    def handle(self, *args, **options):
        api_key = options["api_key"][0]
        from_username = options["from_username"][0]
        to_username = options["to_username"][0]
        to_user = User.objects.get(username=to_username)

        print(u"Fetching snipts...")

        items = get_snipts(api_key, from_username)
        items.reverse()

        for snipt in items:
            s = Snipt(
                blog_post=snipt["blog_post"],
                code=snipt["code"],
                description=snipt["description"],
                id=snipt["id"],
                key=snipt["key"],
                lexer=snipt["lexer"],
                line_count=snipt["line_count"],
                meta=snipt["meta"],
                public=snipt["public"],
                publish_date=snipt["publish_datetime"],
                secure=snipt["secure"],
                slug=snipt["slug"],
                stylized=snipt["stylized"],
                title=snipt["title"],
                user=to_user,
                views=snipt["views"],
            )

            s.created = snipt["created"]
            s.modified = snipt["modified"]

            for tag in snipt["tags"]:
                s.tags.add(tag["name"])

            s.save()

            self.stdout.write(snipt["title"])