Esempio n. 1
0
NUM_TESTOBJECTS = 21

from django.db import models

POPULARITY_LISTSIZE = int(getattr(settings, 'POPULARITY_LISTSIZE', 10))


class TestObject(models.Model):
    title = models.CharField(max_length=100)

    def __unicode__(self):
        return self.title


import popularity
popularity.register(TestObject)


class PopularityTestCase(unittest.TestCase):
    def random_view(self):
        ViewTracker.add_view_for(random.choice(self.objs))

    def setUp(self):
        TestObject(title='Obj a').save()
        TestObject(title='Obj b').save()
        TestObject(title='Obj c').save()
        TestObject(title='Obj d').save()
        TestObject(title='Obj e').save()
        TestObject(title='Obj f').save()
        TestObject(title='Obj g').save()
        TestObject(title='Obj h').save()
Esempio n. 2
0
REPEAT_COUNT = 3
MAX_SECONDS = 2
NUM_TESTOBJECTS = 21

from django.db import models

POPULARITY_LISTSIZE = int(getattr(settings, 'POPULARITY_LISTSIZE', 10))

class TestObject(models.Model):
    title = models.CharField(max_length=100)
    
    def __unicode__(self):
        return self.title

import popularity
popularity.register(TestObject)

class PopularityTestCase(unittest.TestCase):
    def random_view(self):
        ViewTracker.add_view_for(random.choice(self.objs))
        
    def setUp(self):        
        TestObject(title='Obj a').save()
        TestObject(title='Obj b').save()
        TestObject(title='Obj c').save()
        TestObject(title='Obj d').save()
        TestObject(title='Obj e').save()
        TestObject(title='Obj f').save()
        TestObject(title='Obj g').save()
        TestObject(title='Obj h').save()
        TestObject(title='Obj i').save()
Esempio n. 3
0
        blank=True,
        help_text="Associate this article with a Project.",
        null=True)

    magazine_section = models.ForeignKey(
        MagazineSection,
        blank=True,
        help_text="Associate this article with a magazine section.",
        null=True, 
    )

    page_number = models.PositiveIntegerField(
        blank=True,
        null=True,
        help_text="An optional page number if this article also appears in a print magazine."
    )
        
        
    @property    
    def get_tags(self):
        return self.tags.all()
    
    @property    
    def get_magazines(self):
        return self.issues.all()

    def placeholder_image_url(self):
        return os.path.join(settings.MEDIA_URL, self.PLACEHOLDER_IMAGE_PATH)

popularity.register(Article)
Esempio n. 4
0
            help_text="For the Application's url")
    description = models.TextField()
    link = models.URLField()
    authors = models.ManyToManyField(Author, null=True, blank=True)
    online = models.BooleanField(default=True,
            help_text="Set to False to remove this Application from the front")
    date_add = models.DateTimeField(auto_now_add=True)
    platforms = models.ManyToManyField(Platform, null=True, blank=True)
    types = models.ManyToManyField(AppType, null=True, blank=True)
    screenshot = ThumbnailerImageField(null=True, blank=True,
            upload_to=image_name_from_slug('screenshots'),
            resize_source=dict(size=(1170, 0), crop='smart'),
        )

    objects = models.Manager()
    online_only = OnlineApplicationsManager()
    rank = models.FloatField(default=0.0, db_index=True)

    class Meta:
        ordering = ('-rank', 'slug',)

    def __unicode__(self):
        return self.name

    @property
    def day(self):
        return self.date_add.date()


popularity.register(Application)