Example #1
0
class WatchGroup(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()

    vk_id = models.TextField(null=False, unique=True)
    name = models.TextField(blank=True, null=False, unique=True)
    last = models.IntegerField(null=False, default=0)

    def __str__(self):
        return "{} ({})".format(self.name, self.vk_id)

    class Meta:
        ordering = ('-created_at', )

    @property
    def vk_url(self):
        return 'https://vk.com/public{}'.format(self.vk_id.replace('-', ''))

    @property
    def json(self):
        return dict(
            id=self.id,
            vk_id=self.vk_id,
            vk_url=self.vk_url,
            name=self.name,
        )
Example #2
0
class AliDeeplink(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()
    active = apputils.active_field()

    name = models.TextField(blank=True, null=False, unique=True)
    value = models.TextField(blank=False, null=False, unique=True)

    def __str__(self):
        return "{} ({})".format(self.name, self.value)

    class Meta:
        ordering = ('-created_at', 'name')

    def create_url(self, ali_url, sub=None):
        params = dict(to=ali_url)
        if sub:
            params['sub'] = sub

        query = urllib.parse.urlencode(params)
        baseurl = 'http://shopeasy.by/redirect/cpa/o'

        # "http://shopeasy.by/redirect/cpa/o/{deeplink}?sub=test3&to=https%3A%2F%2Fru.aliexpress.com%2Fitem%2FDurex-Condoms-32-Pcs-Box-Natural-Latex-Smooth-Lubricated-Contraception-4-Types-Condoms-for-Men-Sex%2F32804308253.html"
        return "{baseurl}/{deeplink}?{query}".format(baseurl=baseurl,
                                                     deeplink=self.value,
                                                     query=query)
Example #3
0
class WatchGroupPost(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()

    vk_id = models.TextField(null=False, unique=True)
    contents = models.TextField(null=False)
    group = models.ForeignKey(WatchGroup,
                              null=False,
                              on_delete=models.CASCADE,
                              related_name='posts')
    ali_item = models.ForeignKey(Item,
                                 null=True,
                                 on_delete=models.CASCADE,
                                 related_name="posts")
    published = models.BooleanField(default=False, null=False)
    parsed = models.BooleanField(default=False, null=False)
    build = models.BooleanField(default=False, null=False)

    full_url = models.URLField(max_length=500)
    short_url = models.URLField()
    template = models.TextField(default="", null=False)
    text = models.TextField(default="", null=False)
    photo1 = models.URLField(null=True)
    photo2 = models.URLField(null=True)
    photo3 = models.URLField(null=True)
    photo4 = models.URLField(null=True)
    photo5 = models.URLField(null=True)

    def __str__(self):
        return "{} ({})".format(self.group_id, self.vk_id)

    class Meta:
        ordering = ('-created_at', )

    @property
    def json(self):
        return dict(
            id=self.id,
            created_at=self.created_at,
            vk_id=self.vk_id,
            text=self.text,
            photo1=self.photo1,
            photo2=self.photo2,
            photo3=self.photo3,
            photo4=self.photo4,
            photo5=self.photo5,
            published=self.published,
            handled=self.parsed and self.build,
            parsed=self.parsed,
            build=self.build,
            ali_item=self.ali_item.json if self.ali_item else {},
            vk_url=self.vk_url,
        )

    @property
    def vk_url(self):
        return "{}?w=wall{}_{}".format(self.group.vk_url, self.group.vk_id,
                                       self.vk_id)
Example #4
0
class Credentials(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()
    active = apputils.active_field()

    username = models.CharField(max_length=255)
    password = models.CharField(max_length=255)
Example #5
0
class AccessCode(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()
    active = apputils.active_field()

    app = models.ForeignKey(App,
                            on_delete=models.CASCADE,
                            related_name='access_codes')
    value = models.CharField(max_length=255, unique=True)
Example #6
0
class AliLink(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()
    active = apputils.active_field()

    deeplink = models.ForeignKey(AliDeeplink,
                                 on_delete=models.CASCADE,
                                 null=False)
    item = models.ForeignKey(Item, on_delete=models.CASCADE, null=False)
    url = models.TextField(default="", null=False, db_index=True)
    short_url = models.TextField(default="", null=False, db_index=True)

    def __str__(self):
        return self.url
Example #7
0
class App(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()
    active = apputils.active_field()

    name = models.TextField(blank=True, null=False, unique=True)
    app_id = models.TextField(null=False, unique=True)
    secret_key = models.TextField(null=False, unique=True)
    service_key = models.TextField(null=False, unique=True)

    def __str__(self):
        return "{} ({})".format(self.name, self.app_id)

    class Meta:
        ordering = ('-created_at', )
Example #8
0
class Item(models.Model):
    id = apputils.uuid_pk_field()
    created_at = apputils.created_at_field()
    modified_at = apputils.modified_at_field()
    active = apputils.active_field()

    url = models.URLField(db_index=True, null=False)
    name = models.TextField(blank=True, null=False, default="")

    def __str__(self):
        if self.name:
            return "{}: {}".format(self.name, self.url)

        return "{}".format(self.url)

    class Meta:
        ordering = ('-created_at',)

    @property
    def json(self):
        return dict(
            name=self.name,
            url=self.url
        )