コード例 #1
0
class Product(ModelBase):
    """Represents a product we capture feedback for"""
    # Whether or not this product is enabled
    enabled = models.BooleanField(default=True)

    # Used internally for notes to make it easier to manage products
    notes = models.CharField(max_length=255, blank=True, default=u'')

    # This is the name we display everywhere
    display_name = models.CharField(max_length=20)

    # We're not using foreign keys, so when we save something to the
    # database, we use this name
    db_name = models.CharField(max_length=20)

    # This is the slug used in the feedback product urls; we don't use
    # the SlugField because we don't require slugs be unique
    slug = models.CharField(max_length=20)

    # Whether or not this product shows up on the dashboard
    on_dashboard = models.BooleanField(default=True)

    # System slated for automatic translation, or null if none;
    # See translation app for details.
    translation_system = models.CharField(
        choices=get_translation_system_choices(),
        null=True,
        blank=True,
        max_length=20,
    )

    @classmethod
    def from_slug(cls, slug):
        return cls.objects.get(slug=slug)

    @classmethod
    def get_product_map(cls):
        """Returns map of product slug -> db_name"""
        products = cls.objects.values_list('slug', 'db_name')
        return dict(prod for prod in products)

    def __unicode__(self):
        return self.display_name

    def __repr__(self):
        return self.__unicode__().encode('ascii', 'ignore')
コード例 #2
0
class Product(ModelBase):
    """Represents a product we capture feedback for"""
    # Whether or not this product is enabled
    enabled = models.BooleanField(default=True)

    # Used internally for notes to make it easier to manage products
    notes = models.CharField(max_length=255, blank=True, default=u'')

    # This is the name we display everywhere
    display_name = models.CharField(max_length=50)

    # We're not using foreign keys, so when we save something to the
    # database, we use this name
    db_name = models.CharField(max_length=50)

    # This is the slug used in the feedback product urls; we don't use
    # the SlugField because we don't require slugs be unique
    slug = models.CharField(max_length=50)

    # Whether or not this product shows up on the dashboard; we sort of
    # use this to denote whether data is publicly available, too
    on_dashboard = models.BooleanField(default=True)

    # Whether or not this product shows up in the product picker
    on_picker = models.BooleanField(default=True)

    # The image we use on the product picker. This has to be a valid
    # image in fjord/feedback/static/img/ and should be a .png of
    # size 295x285.
    # FIXME: Make this more flexible.
    image_file = models.CharField(max_length=100,
                                  null=True,
                                  blank=True,
                                  default=u'noimage.png')

    # System slated for automatic translation, or null if none;
    # See translation app for details.
    translation_system = models.CharField(
        choices=get_translation_system_choices(),
        null=True,
        blank=True,
        max_length=20,
    )

    # If this product should grab browser data, which browsers should
    # it grab browser data for. Note, this value should match what
    # we're inferring from the user agent.
    browser_data_browser = models.CharField(
        max_length=100,
        blank=True,
        default=u'',
        help_text=u'Grab browser data for browser product')

    browser = models.CharField(
        max_length=30,
        blank=True,
        default=u'',
        help_text=u'User agent inferred browser for this product if any')

    objects = ProductManager()

    @classmethod
    def from_slug(cls, slug):
        return cls.objects.get(slug=slug)

    @classmethod
    def get_product_map(cls):
        """Return map of product slug -> db_name for enabled products"""
        products = (cls.objects.filter(enabled=True).values_list(
            'slug', 'db_name'))
        return dict(prod for prod in products)

    def collect_browser_data_for(self, browser):
        """Return whether we should collect browser data from this browser"""
        return browser and browser == self.browser_data_browser

    def __unicode__(self):
        return self.display_name

    def __repr__(self):
        return self.__unicode__().encode('ascii', 'ignore')