# Path: forum/models.py
# class Section(models.Model):
#     name = models.CharField(max_length=32, unique=True, blank=False, null=False)
#     date_created = models.DateTimeField(auto_now_add=True)
#     order = models.IntegerField(default=1)
#     last_modified = models.DateTimeField(auto_now=True, blank=True, null=True)
#     
#     class Meta():
#         ordering = ['-order']
#     
#     def __str__(self):
#         return self.name
# 
# class Node(models.Model):
#     section = models.ForeignKey(Section, on_delete=models.PROTECT, related_name='nodes')
#     name = models.CharField(max_length=32, unique=True, blank=False, null=False)
#     description = models.TextField(blank=False, null=False)
#     icon_raw = models.ImageField("Node's icon", upload_to='upload/node/%Y%m%d', blank=True, null=True, default="")
#     icon_l = models.ImageField("large icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_m = models.ImageField("medium icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_s = models.ImageField("small icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     order = models.IntegerField(default=0)
#     is_trash = models.BooleanField(default=False)
#     date_created = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True, blank=True, null=True)
#     watcher = models.ManyToManyField(User, blank=True, related_name='watch_nodes')
#     
#     class Meta():
#         ordering = ['section', '-order']
#     
#     def __str__(self):
#         return "%s/%s" % (self.section.name, self.name)
#     
#     def admin_image(self):
#         if self.icon_s:
#             return '<img src="/media/%s" width="24" height="24" />' % (self.icon_s)
#         else:
#             return None
#     admin_image.allow_tags = True
#     admin_image.short_description = 'Icon'
# 
# Path: forum/utils.py
# def create_thumbnail(src, new_name, ext):
#     upload = Image.open(BytesIO(src.read()))
#     fmt = src.content_type.split('/')[-1]
#     
#     large = _thumbnail(upload, (IMAGE_LARGE, IMAGE_LARGE), fmt)
#     filename_l = "%s_l.%s" % (new_name, ext)
#     large_file = SimpleUploadedFile(filename_l, large.read(), content_type=src.content_type)
#     
#     medium = _thumbnail(upload, (IMAGE_MEDIUM, IMAGE_MEDIUM), fmt)
#     filename_m = "%s_m.%s" % (new_name, ext)
#     medium_file = SimpleUploadedFile(filename_m, medium.read(), content_type=src.content_type)
#     
#     small = _thumbnail(upload, (IMAGE_SMALL, IMAGE_SMALL), fmt)
#     filename_s = "%s_s.%s" % (new_name, ext)
#     small_file = SimpleUploadedFile(filename_s, small.read(), content_type=src.content_type)
#     
#     return large_file, medium_file, small_file


from django.contrib import admin
from forum.models import Section, Node
from django.utils.crypto import get_random_string
from forum.utils import create_thumbnail

class SectionAdmin(admin.ModelAdmin):
    list_display = ('name', 'order', 'last_modified')

class NodeAdmin(admin.ModelAdmin):
    exclude = ['icon_l', 'icon_m', 'icon_s']

# Path: forum/models.py
# class Section(models.Model):
#     name = models.CharField(max_length=32, unique=True, blank=False, null=False)
#     date_created = models.DateTimeField(auto_now_add=True)
#     order = models.IntegerField(default=1)
#     last_modified = models.DateTimeField(auto_now=True, blank=True, null=True)
#     
#     class Meta():
#         ordering = ['-order']
#     
#     def __str__(self):
#         return self.name
# 
# class Node(models.Model):
#     section = models.ForeignKey(Section, on_delete=models.PROTECT, related_name='nodes')
#     name = models.CharField(max_length=32, unique=True, blank=False, null=False)
#     description = models.TextField(blank=False, null=False)
#     icon_raw = models.ImageField("Node's icon", upload_to='upload/node/%Y%m%d', blank=True, null=True, default="")
#     icon_l = models.ImageField("large icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_m = models.ImageField("medium icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_s = models.ImageField("small icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     order = models.IntegerField(default=0)
#     is_trash = models.BooleanField(default=False)
#     date_created = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True, blank=True, null=True)
#     watcher = models.ManyToManyField(User, blank=True, related_name='watch_nodes')
#     
#     class Meta():
#         ordering = ['section', '-order']
#     
#     def __str__(self):
#         return "%s/%s" % (self.section.name, self.name)
#     
#     def admin_image(self):
#         if self.icon_s:
#             return '<img src="/media/%s" width="24" height="24" />' % (self.icon_s)
#         else:
#             return None
#     admin_image.allow_tags = True
#     admin_image.short_description = 'Icon'
# 
# Path: forum/utils.py
# def create_thumbnail(src, new_name, ext):
#     upload = Image.open(BytesIO(src.read()))
#     fmt = src.content_type.split('/')[-1]
#     
#     large = _thumbnail(upload, (IMAGE_LARGE, IMAGE_LARGE), fmt)
#     filename_l = "%s_l.%s" % (new_name, ext)
#     large_file = SimpleUploadedFile(filename_l, large.read(), content_type=src.content_type)
#     
#     medium = _thumbnail(upload, (IMAGE_MEDIUM, IMAGE_MEDIUM), fmt)
#     filename_m = "%s_m.%s" % (new_name, ext)
#     medium_file = SimpleUploadedFile(filename_m, medium.read(), content_type=src.content_type)
#     
#     small = _thumbnail(upload, (IMAGE_SMALL, IMAGE_SMALL), fmt)
#     filename_s = "%s_s.%s" % (new_name, ext)
#     small_file = SimpleUploadedFile(filename_s, small.read(), content_type=src.content_type)
#     
#     return large_file, medium_file, small_file


# Path: forum/admin.py
from django.contrib import admin
from forum.models import Section, Node
from django.utils.crypto import get_random_string
from forum.utils import create_thumbnail


class SectionAdmin(admin.ModelAdmin):
    list_display = ('name', 'order', 'last_modified')

class NodeAdmin(admin.ModelAdmin):
    exclude = ['icon_l', 'icon_m', 'icon_s']

    list_display = ('section', 'name', 'admin_image', 'description', 'order', 'last_modified')