# Path: ISeeNN/image_server/models.py
# class DBImage(Document):
#     server = fields.ObjectIdField(required=True)
#     path = fields.StringField(required=True)
#     mime_type = fields.StringField(required=True)
#     width = fields.IntField(required=True)
#     height = fields.IntField(required=True)
#     source = fields.StringField()
#     meta = {
#         'indexes': [
#             {
#                 'fields': ['path'],
#                 'unique': True
#             },
#             '#source'
#         ]
#     }
# 
#     def get_thumbnail(self):
#         try:
#             my_thumbnail = DBImageThumbnail.objects.get(DBImage=self.pk)
#             return my_thumbnail
#         except DBImageThumbnail.DoesNotExist:
#             im = Image.open(self.path)
#             thumbnail_height = 200
#             thumbnail_width = thumbnail_height * im.width / im.height
#             im.thumbnail((thumbnail_width, thumbnail_height), Image.ANTIALIAS)
#             io = StringIO()
#             im.save(io, im.format)
#             io.seek(0)
# 
#             my_thumbnail = DBImageThumbnail(DBImage=self.pk,
#                                             file=io,
#                                             width=thumbnail_width,
#                                             height=thumbnail_height,
#                                             mime_type=self.mime_type)
#             my_thumbnail.save()
#             return my_thumbnail
# 
# 
#     def __str__(self):
#         return "[%s](%s)" % (self.server, self.path)
# 
# class ImageServer(Document):
#     server_name = fields.StringField(required=True)
#     server_ip = fields.StringField(required=True)
# 
#     def __str__ (self):
#         return "%s(%s)" % (self.server_name, self.server_ip)


from django.http import HttpResponse, HttpResponseGone, HttpResponseBadRequest, HttpResponseServerError
from django.http import Http404
from django.conf import settings
from .models import DBImage, ImageServer
# from django.shortcuts import render

# Create your views here.



def get_image(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        try:
            server = ImageServer.objects.get(id=db_image.server)
            if server.server_name != settings.SERVER_NAME:
                return HttpResponseBadRequest("Image Not On This Server")

# Path: ISeeNN/image_server/models.py
# class DBImage(Document):
#     server = fields.ObjectIdField(required=True)
#     path = fields.StringField(required=True)
#     mime_type = fields.StringField(required=True)
#     width = fields.IntField(required=True)
#     height = fields.IntField(required=True)
#     source = fields.StringField()
#     meta = {
#         'indexes': [
#             {
#                 'fields': ['path'],
#                 'unique': True
#             },
#             '#source'
#         ]
#     }
# 
#     def get_thumbnail(self):
#         try:
#             my_thumbnail = DBImageThumbnail.objects.get(DBImage=self.pk)
#             return my_thumbnail
#         except DBImageThumbnail.DoesNotExist:
#             im = Image.open(self.path)
#             thumbnail_height = 200
#             thumbnail_width = thumbnail_height * im.width / im.height
#             im.thumbnail((thumbnail_width, thumbnail_height), Image.ANTIALIAS)
#             io = StringIO()
#             im.save(io, im.format)
#             io.seek(0)
# 
#             my_thumbnail = DBImageThumbnail(DBImage=self.pk,
#                                             file=io,
#                                             width=thumbnail_width,
#                                             height=thumbnail_height,
#                                             mime_type=self.mime_type)
#             my_thumbnail.save()
#             return my_thumbnail
# 
# 
#     def __str__(self):
#         return "[%s](%s)" % (self.server, self.path)
# 
# class ImageServer(Document):
#     server_name = fields.StringField(required=True)
#     server_ip = fields.StringField(required=True)
# 
#     def __str__ (self):
#         return "%s(%s)" % (self.server_name, self.server_ip)


# Path: ISeeNN/image_server/views.py
from django.http import HttpResponse, HttpResponseGone, HttpResponseBadRequest, HttpResponseServerError
from django.http import Http404
from django.conf import settings
from .models import DBImage, ImageServer

# from django.shortcuts import render

# Create your views here.



def get_image(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        try:
            server = ImageServer.objects.get(id=db_image.server)
            if server.server_name != settings.SERVER_NAME:
                return HttpResponseBadRequest("Image Not On This Server")

        except ImageServer.DoesNotExist: