class MarketSubCategory(models.Model):
    marketplace = models.ForeignKey(MarketPlace)
    name = models.CharField(max_length=60)
    slug = models.SlugField(max_length=60)
    parent = models.ForeignKey(MarketCategory,
                               null=True,
                               blank=True,
                               related_name='subcategories')
    order = models.IntegerField(default=255)
    image = ImageWithThumbsField(upload_to=build_image_item_filename,
                                 sizes=((100, 100), (400, 400)),
                                 crop=False,
                                 null=True,
                                 blank=True)

    class Meta:
        unique_together = (('parent', 'slug'), )
        ordering = ['order']

    def __unicode__(self):
        return "%s > %s" % (self.parent, self.name)

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(MarketSubCategory, self).save(*args, **kwargs)
class Profile(models.Model):
    user = models.OneToOneField(User)
    street_address = models.CharField(max_length=80, blank=True, null=True)
    city = models.CharField(max_length=80, blank=True, null=True)
    state = models.CharField(max_length=80, blank=True, null=True)
    zip = models.CharField(max_length=30, blank=True, null=True)
    country = models.CharField(max_length=50, blank=True, null=True)
    phone = models.CharField(max_length=50, blank=True, null=True)
    birth = models.DateField(blank=True, null=True)
    photo = ImageWithThumbsField(upload_to='images',
                                 sizes=((100, 100), ((128, 135)), (400, 400)),
                                 blank=True,
                                 null=True)

    #photo = models.ImageField(upload_to='images', blank=True, null=True)

    def get_cart(self, shop):
        try:
            cart = Cart.objects.filter(shop=shop).filter(
                bidder=self.user).get()
        except Cart.DoesNotExist:
            raise Exception("Profile %s don't have a Cart associated yet!" %
                            self)
        return cart

    def get_sell(self):
        try:
            payment = Payment.objects.filter(sell__bidder=self.user,
                                             state_actual__state='PE').get()
            return payment.sell
        except Payment.DoesNotExist:
            return Sell.new_sell(self.shop, self.user)

    def set_subscription_plan(self, plan_id, subscription_id):
        from subscriptions.models import Subscription, SubscriptionPlan

        subscription_plan = SubscriptionPlan.objects.filter(
            plan_id=plan_id).get()
        subscription = Subscription(owner=self,
                                    subscription_id=subscription_id,
                                    plan=subscription_plan)
        subscription.save()

    def update_user_info(self, shipping_form):
        self.user.first_name = shipping_form.cleaned_data['first_name']
        self.user.last_name = shipping_form.cleaned_data['last_name']
        self.user.save()

    def update_shipping_info(self, shipping_form):
        self.update_user_info(shipping_form)
        self.street_address = shipping_form.cleaned_data['street_address']
        self.city = shipping_form.cleaned_data['city']
        self.state = shipping_form.cleaned_data['state']
        self.zip = shipping_form.cleaned_data['zip']
        self.country = shipping_form.cleaned_data['country']
        self.save()

    def __unicode__(self):
        return "Profile<%s>" % (self.user.username)
Example #3
0
class ImageLot(models.Model):
    image = ImageWithThumbsField(upload_to='images', sizes=((100,100),(400,400)), crop=False)
    lot = models.ForeignKey(Lot)
    primary_picture = models.BooleanField(default=False)
    
    def save(self, *args, **kwargs):
        super(ImageLot, self).save(*args, **kwargs)
        self.lot.has_image = True
        self.lot.save()
Example #4
0
class MarketPlaceAnnouncement(models.Model):
    marketplace = models.ForeignKey(MarketPlace)
    posted_on = models.DateTimeField(auto_now_add=True)
    posted_by = models.CharField(max_length=100)
    announcement = models.TextField()
    #image = models.ImageField(upload_to='img/announcement')
    image = ImageWithThumbsField(upload_to='img/announcement', sizes=((100,100),))
    def __str__(self):
        return "%s > %s - %s" % (self.marketplace, self.posted_on, self.posted_by)
Example #5
0
class FAQCategory(models.Model):
    marketplace = models.ForeignKey(MarketPlace)
    posted_on = models.DateTimeField(auto_now_add=True)
    name = models.CharField(max_length=200)
    description = models.TextField(blank=True, null=True)
    #image = models.ImageField(upload_to='img/faq')
    image = ImageWithThumbsField(upload_to='img/faq', sizes=((100,100),), blank=True)
    order = models.IntegerField(default=5)
    def __str__(self):
        return "%s :: %s" % (self.marketplace, self.name)
Example #6
0
class ImageItem(models.Model):
    #image = models.ImageField(upload_to='images') 
    image = ImageWithThumbsField(upload_to=build_image_item_filename, sizes=((100,100),(400,400)), crop=False)
    item = models.ForeignKey(Item)
    primary_picture = models.BooleanField(default=False)
    
    def __unicode__(self):
        return "%s > %s" % (self.item, self.id)

    def save(self, *args, **kwargs):
        super(ImageItem, self).save(*args, **kwargs)
        self.item.has_image = True
        self.item.save()
Example #7
0
class App(models.Model):
    title = models.CharField(max_length=255)
    stub = models.CharField(max_length=32)
    description = models.CharField(max_length=255)
    path = models.CharField(max_length=32)
    icon_file = ImageWithThumbsField(upload_to='app_icons',
                                     sizes=((300, 300), (200, 200), (100,
                                                                     100)),
                                     default='app_icons/default.jpg',
                                     null=True,
                                     blank=True)

    def __unicode__(self):
        return self.title

    class Meta:
        permissions = (("can_use", "Can use this app"), )
class MarketCategory(models.Model):
    marketplace = models.ForeignKey(MarketPlace)
    name = models.CharField(max_length=60)
    slug = models.SlugField(max_length=60, unique=True)
    order = models.IntegerField(default=255)
    image = ImageWithThumbsField(upload_to=build_image_item_filename,
                                 sizes=((100, 100), (400, 400)),
                                 crop=False,
                                 null=True,
                                 blank=True)

    def related_shops(self):
        from django.db.models import Count
        from inventory.models import Product
        from shops.models import Shop

        related_shops = []
        for product in Product.objects.filter(category=self).values(
                'category', 'shop').annotate(number_products=Count(
                    'category')).order_by('-number_products'):
            #            related_shops.append((Shop.objects.get(id=product['shop']), product['number_products']))
            related_shops.append(Shop.objects.get(id=product['shop']))

        return related_shops

    @classmethod
    def generate_captcha(cls):
        index = random.randint(0, cls.objects.count() - 1)
        captcha = cls.objects.all()[index].name.split()[0]
        return captcha, captcha

    class Meta:
        ordering = ['order']

    def __unicode__(self):
        return "%s > %s" % (self.marketplace, self.name)

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(MarketCategory, self).save(*args, **kwargs)
Example #9
0
class UserProfile(forms.Form):
    username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$', required=False,
        error_message = _("This value must contain only letters, numbers and underscores."))
    first_name = forms.CharField(label=_("First name"), max_length=50, required=False) 
    last_name = forms.CharField(label=_("Last name"), max_length=50, required=False)
    phone = forms.CharField(label=_("Phone number"), max_length=80, required=False)
    street_address = forms.CharField(label=_("Street address"), max_length=80, required=False)
    city = forms.CharField(label=_("City"), max_length=80, required=False)
    state = USStateField(label=_("State / Province"), required=False, widget=USStateSelect)
    zip = forms.CharField(label=_("ZIP / Portal code"), max_length=30, required=False)
    country = forms.CharField(label=_("Country or region"), max_length=50, required=False)
    photo = ImageWithThumbsField(sizes=((100,100),(400,400)), crop=False)

    def __init__(self, user=None, *args, **kwargs):
        self.user = user
        super(UserProfile, self).__init__(*args, **kwargs)

    def clean_username(self):
        username = self.cleaned_data["username"]
        username = username.strip()
        if self.user.username == username:
            return username
        
        if username == "":
            raise forms.ValidationError(_("Username field can't be blank."))
        
        try:
            User.objects.get(username=username)
        except User.DoesNotExist:
            return username
        raise forms.ValidationError(_("A user with that username already exists."))

    def clean_zip(self):
        zip = self.cleaned_data.get("zip", "")
        if zip and not (re.match("[0-9]{5}(-[0-9]{4})?$", zip)):
            raise forms.ValidationError("Invalid Zip code. Valid formats are XXXXX or XXXXX-XXXX")
           
        return zip
Example #10
0
class Person(KeyableModel):

    """
        Represents a user's profile
    """
    user = models.OneToOneField(settings.AUTH_USER_MODEL)
    stub = models.CharField(max_length=128, null=True, blank=True)
    title = models.CharField(max_length=128, null=True, blank=True)
    org_group = models.ForeignKey('OrgGroup', null=True, blank=True)
    office_location = models.ForeignKey('OfficeLocation', null=True,
                                        blank=True)
    desk_location = models.CharField(max_length=128, null=True, blank=True)
    office_phone = models.CharField(max_length=32, null=True, blank=True)
    mobile_phone = models.CharField(max_length=32, null=True, blank=True)
    home_phone = models.CharField(max_length=32, null=True, blank=True)
    photo_file = ImageWithThumbsField(upload_to='avatars',
                                      sizes=((34, 34), (125, 125), (200, 200)),
                                      default='avatars/default.jpg')
    what_i_do = models.TextField(null=True, blank=True)
    current_projects = models.TextField(null=True, blank=True)
    stuff_ive_done = models.TextField(null=True, blank=True)
    things_im_good_at = models.TextField(null=True, blank=True)
    schools_i_attended = models.TextField(null=True, blank=True)
    allow_tagging = models.BooleanField(default=True)
    email_notifications = models.BooleanField(default=False)
    tags = TaggableManager()
    start_date = models.DateTimeField(auto_now_add=True, null=True, blank=True)

    @classmethod
    def active_user_count(cls):
        return get_user_model().objects.filter(is_active=True).count()

    @property
    def full_name(self):
        return "%s %s" % (self.user.first_name, self.user.last_name)

    @property
    def days_since_hire(self):
        if self.start_date:
            diff = timezone.now() - self.start_date
            return diff.days
        else:
            pass

    def expire_cache(self):
        if 'staff_directory' in settings.INSTALLED_APPS:
            return expire_page(reverse('staff_directory:person', args=(self.stub,)))
        else:
            pass

    def format_phone_numbers(self):
        self.office_phone_formatted = format_phone_number(self.office_phone)
        self.mobile_phone_formatted = format_phone_number(self.mobile_phone)

    def save(self, *args, **kwargs):
        if self.photo_file is None:
            self.photo_file = 'avatars/default.jpg'
        self.expire_cache()
        self.format_phone_numbers()
        super(Person, self).save(*args, **kwargs)

    def __unicode__(self):
        return u'%s' % self.user

    def get_absolute_url(self):
        return reverse('staff_directory:person', args=(self.stub,))

    # Search fields

    @classmethod
    def search_category(cls):
        return 'Staff Directory'

    @property
    def to_search_result(self):
        return self.full_name