diff options
Diffstat (limited to 'app/unused_apps/stuff')
-rw-r--r-- | app/unused_apps/stuff/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/stuff/admin.py | 56 | ||||
-rw-r--r-- | app/unused_apps/stuff/models.py | 65 | ||||
-rw-r--r-- | app/unused_apps/stuff/temp.py | 115 |
4 files changed, 0 insertions, 236 deletions
diff --git a/app/unused_apps/stuff/__init__.py b/app/unused_apps/stuff/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/app/unused_apps/stuff/__init__.py +++ /dev/null diff --git a/app/unused_apps/stuff/admin.py b/app/unused_apps/stuff/admin.py deleted file mode 100644 index 135b17b..0000000 --- a/app/unused_apps/stuff/admin.py +++ /dev/null @@ -1,56 +0,0 @@ -from django.contrib import admin -from .models import Item - - -@admin.register(Item) -class ItemAdmin(admin.ModelAdmin): - list_display = ( - 'title', - 'admin_thumbnail', - 'item_type', - 'creator', - 'purchase_price', - 'item_format', - 'isbn' - ) - list_filter = ['item_format', 'item_type'] - - fieldsets = ( - ('Item', { - 'fields': ( - 'title', - ('date_purchased', 'date_added'), - 'item_format', - 'purchase_price', - 'image', - 'item_type', - 'creator', - 'serial_number', - 'isbn', - ), - 'classes': ( - 'show', - 'extrapretty', - 'wide' - ) - } - ), - ('Extra', { - 'fields': ( - 'creator_sort_last_name', - 'creator_sort_first_name', - 'current_price', - 'retail_price', - 'amazon_url', - 'image_url', - ), - 'classes': ( - 'collapse', - 'extrapretty', - 'wide' - ) - }), - ) - - class Media: - js = ('image-loader.js', 'next-prev-links.js') diff --git a/app/unused_apps/stuff/models.py b/app/unused_apps/stuff/models.py deleted file mode 100644 index 05a7f4f..0000000 --- a/app/unused_apps/stuff/models.py +++ /dev/null @@ -1,65 +0,0 @@ -from django.db import models -from django.urls import reverse -from django.utils.html import format_html -from django.utils import timezone -from django.conf import settings - - -class Item(models.Model): - isbn = models.CharField(max_length=100, blank=True, null=True) - serial_number = models.CharField(max_length=100, blank=True, null=True) - ITEM_TYPES = ( - (0, 'Book'), - (1, 'Apparel'), - (2, 'Gadget'), - (3, 'Furniture'), - ) - item_type = models.IntegerField(choices=ITEM_TYPES, default=0) - title = models.CharField(max_length=200) - creator = models.CharField(max_length=200, blank=True, null=True) - creator_sort_last_name = models.CharField(max_length=200, blank=True, null=True) - creator_sort_first_name = models.CharField(max_length=200, blank=True, null=True) - current_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) - retail_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) - purchase_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) - amazon_url = models.CharField(max_length=400, blank=True, null=True) - image_url = models.CharField(max_length=400, blank=True, null=True) - image = models.FileField(upload_to='stuff/', null=True, blank=True) - item_format = models.CharField(max_length=255, blank=True, null=True) - date_released = models.DateTimeField(blank=True, null=True) - date_purchased = models.DateTimeField(blank=True, null=True, default=timezone.now) - date_added = models.DateTimeField(blank=True, null=True, default=timezone.now) - - class Meta: - ordering = ['-date_added'] - - def __str__(self): - return self.title - - @property - def get_previous_published(self): - return self.get_previous_by_date_added(status__exact=1) - - @property - def get_next_published(self): - return self.get_next_by_date_added(status__exact=1) - - @property - def get_previous_admin_url(self): - n = self.get_previous_by_date_added() - return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[n.id]) - - @property - def get_next_admin_url(self): - model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name) - try: - return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_next_by_date_added().pk]) - except model.DoesNotExist: - return '' - - def get_image_url(self): - return '%s%s' % (settings.MEDIA_URL, self.image) - - def admin_thumbnail(self): - return format_html('<img src="%s" width="100" style="width:100px">' % (self.get_image_url())) - admin_thumbnail.short_description = 'Thumbnail' diff --git a/app/unused_apps/stuff/temp.py b/app/unused_apps/stuff/temp.py deleted file mode 100644 index 2150563..0000000 --- a/app/unused_apps/stuff/temp.py +++ /dev/null @@ -1,115 +0,0 @@ -from stuff.models import Item -from django.conf import settings -from datetime import datetime -from decimal import Decimal -import csv -item_types = { 'Book':0, 'Apparel': 1,'Gadget': 2, 'Furniture': 3} -""" -csv_file = csv.DictReader(open('stuff.csv', 'rb'), delimiter=',') -for line in csv_file: - if line['release date'][:-6] != '': - date_released = datetime.strptime(line['release date'][:-6], "%Y-%m-%d %H:%M:%S") - else: - date_released = None - if line['purchase date'][:-6] != '': - date_purchased = datetime.strptime(line['purchase date'][:-6], "%Y-%m-%d %H:%M:%S") - else: - date_purchased = None - if line['creation date'][:-6] != '': - date_added = datetime.strptime(line['creation date'][:-6], "%Y-%m-%d %H:%M:%S") - else: - date_added = None - item_type = int(item_types[line['item type']]) - if line['current value'][1:] != '': - try: - current_price = Decimal(line['current value'][1:].replace(",", "")) - except: - current_price = None - else: - current_price = None - if line['retail price'][1:] != '': - try: - retail_price = Decimal(line['retail price'][1:].replace(",", "")) - except: - retail_price =None - else: - retail_price =None - if line['purchase price'][1:] != '' and line['purchase price'] != "Gift": - try: - purchase_price = Decimal(line['purchase price'][1:].replace(",", "").replace('\\xa0', ' ')) - except: - purchase_price =None - else: - purchase_price =None - i, created = Item.objects.get_or_create( - isbn = line['ISBN'], - serial_number = line['serial number'], - type = item_type, - title = line['title'], - creator = line['creator'], - current_price = current_price, - retail_price = retail_price, - purchase_price = purchase_price, - amazon_url = line['amazon link'], - image_url = line['coverImageLargeURLString'], - format = line['format'], - date_released = date_released, - date_purchased = date_purchased, - date_added = date_added - ) - print created, i.title -""" -import datetime -import os -import io -import urllib - - -from django.contrib.contenttypes.models import ContentType -from django.template.defaultfilters import slugify -from django.core.exceptions import ObjectDoesNotExist -from django.conf import settings - -# Required PIL classes may or may not be available from the root namespace -# depending on the installation -try: - import Image - import ImageFile - import ImageFilter - import ImageEnhance -except ImportError: - try: - from PIL import Image - from PIL import ImageFile - from PIL import ImageFilter - from PIL import ImageEnhance - except ImportError: - raise ImportError("Could not import the Python Imaging Library.") - -ImageFile.MAXBLOCK = 1000000 - - -def grab_item_image(item): - crop_dir = settings.IMAGES_ROOT + '/stuff/' - if not os.path.isdir(crop_dir): - os.makedirs(crop_dir) - remote = item.image_url - try: - fname = urllib.request.urlopen(remote) - except: - return False - im = io.BytesIO(fname.read()) - img = Image.open(im) - ext = slugify(item.title)[:40] - filename = '%s/%s.jpg' %(crop_dir, ext) - try: - if img.format == 'JPEG': - img.save(filename, 'JPEG', quality=95, optimize=True) - else: - img.save(filename) - except IOError: - if os.path.isfile(filename): - os.unlink(filename) - pass - return 'images/stuff/%s.jpg'%(ext) - |