<commit_before># -*- coding: UTF-8 -*-

"""
    A collection of abstract models to speed up and standardise development. 
    They are not required to use the shopping framework.
"""

import os
from datetime import datetime
from django.db import models
from rollyourown.shopping import purchase
from rollyourown.shopping.utils import FriendlyID

friendly_id = FriendlyID()

class ActiveObjectManager(models.Manager):
    " Provides easy access to active objects. "
    def active(self):
        return self.get_query_set().filter(active=True)

class ProductManager(ActiveObjectManager):
    " Provides access to a number of common features "
    def popular(self):
        " Returns query set of the most popular items. "
        raise NotImplemented

    def featured(self):
        " Returns Query Set of Featured Products "
        raise NotImplemented

class Product(models.Model):
    # Basic product information
    name        = models.CharField(max_length=150, help_text="Full product name, but keep this one simple")
    slug        = models.SlugField(unique=True, help_text="Used to form the URL for this product")
    sku         = models.SlugField(unique=True, help_text="A unique code to identify this product")
    
    # Shop information
    available_from  = models.DateField(blank=True, null=True, help_text='Enter the earlist date the product will dispatch (optional)')
    active          = models.BooleanField(default=True, help_text="Uncheck this box to remove product from site display")

    # Highlighting
    featured    = models.BooleanField(default=False, help_text="Will highlight this product as featured thoughout the website")
    rank        = models.PositiveIntegerField('order rank', default=5, help_text="Determines where the product will be displayed in the listings. 1 means at top")
    
    # HTML Meta data
    meta_page_title = models.CharField(max_length=150, default="", blank=True, help_text="SEO Browser title for this product")
    meta_keywords = models.CharField(max_length=150, default="", blank=True, help_text="Keywords for search engine optimisation")
    meta_description = models.TextField(default="", blank=True, help_text="Product description for search engine optimisation")

    created_on = models.DateTimeField(default=datetime.now, blank=True, editable=False)
    updated_on = models.DateTimeField(blank=True, editable=False)

    objects = ProductManager()

    def save(self, *args, **kwargs):
        self.meta_page_title = self.meta_page_title or self.name
        self.updated_on = datetime.now()
        super(Product, self).save(*args, **kwargs)

    class Meta:
        abstract = True
        ordering = ['rank', 'name', 'sku']
    
    def __unicode__(self):
        return self.name or self.sku

class ProductCategory(models.Model):
    " A simple way to categories products. "
    title = models.CharField(max_length=100, help_text="The title of the category is displayed in link menus.")
    slug = models.SlugField('key', unique=True, help_text="A unique key to identify this category. Ideally human readable.")

    is_active = models.BooleanField('is active', default=True, help_text="Uncheck this to deactivate this category from showing in the site")
<commit_msg>Minor changes to abstract models.<commit_after># -*- coding: UTF-8 -*-

"""
    A collection of abstract models to speed up and standardise development. 
    They are not required to use the shopping framework.
"""

import os
from datetime import datetime
from django.db import models
from rollyourown.shopping import purchase
from rollyourown.shopping.utils import FriendlyID

friendly_id = FriendlyID()

class ActiveObjectManager(models.Manager):
    " Provides easy access to active objects. "
    def active(self):
        return self.get_query_set().filter(active=True)

class ProductManager(ActiveObjectManager):
    " Provides access to a number of common features "
    use_for_related_fields = True
    def popular(self):
        " Returns query set of the most popular items. "
        raise NotImplemented

    def featured(self):
        " Returns Query Set of Featured Products "
        return self.get_query_set().filter(featured=True)

class Product(models.Model):
    # Basic product information
    name        = models.CharField(max_length=150, help_text="Full product name, but keep this one simple")
    slug        = models.SlugField(unique=True, help_text="Used to form the URL for this product")
    sku         = models.SlugField(unique=True, help_text="A unique code to identify this product")
    
    # Shop information
    available_from  = models.DateField(blank=True, null=True, help_text='Enter the earlist date the product will dispatch (optional)')
    active          = models.BooleanField(default=True, help_text="Uncheck this box to remove product from site display")

    # Highlighting
    featured    = models.BooleanField(default=False, help_text="Will highlight this product as featured thoughout the website")
    rank        = models.PositiveIntegerField('order rank', default=5, help_text="Determines where the product will be displayed in the listings. 1 means at top")
    
    # HTML Meta data
    meta_page_title = models.CharField(max_length=150, default="", blank=True, help_text="SEO Browser title for this product")
    meta_keywords = models.CharField(max_length=150, default="", blank=True, help_text="Keywords for search engine optimisation")
    meta_description = models.TextField(default="", blank=True, help_text="Product description for search engine optimisation")

    created_on = models.DateTimeField(default=datetime.now, blank=True, editable=False)
    updated_on = models.DateTimeField(blank=True, editable=False)

    objects = ProductManager()

    def save(self, *args, **kwargs):
        self.meta_page_title = self.meta_page_title or self.name
        self.updated_on = datetime.now()
        super(Product, self).save(*args, **kwargs)

    class Meta:
        abstract = True
        ordering = ['rank', 'name', 'sku']
    
    def __unicode__(self):
        return self.name or self.sku

    @property
    def availability(self):
        if self.available_from:
            return self.available_from.strftime('%x')
        else:
            return 'in stock'

class ProductCategory(models.Model):
    " A simple way to categories products. "
    title = models.CharField(max_length=100, help_text="The title of the category is displayed in link menus.")
    slug = models.SlugField('key', unique=True, help_text="A unique key to identify this category. Ideally human readable.")

    is_active = models.BooleanField('is active', default=True, help_text="Uncheck this to deactivate this category from showing in the site")

{'fraction_non_alphanumeric': 0.0900593471810089, 'fraction_numerical': 0.004451038575667656, 'mean_word_length': 3.815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3376044', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1804, 'n_words': 599}