# Path: adminfiles/settings.py
# JQUERY_URL = getattr(settings, 'JQUERY_URL',
#                      'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js')
#     JQUERY_URL = posixpath.join(settings.STATIC_URL, JQUERY_URL)
# ADMINFILES_UPLOAD_TO = getattr(settings, 'ADMINFILES_UPLOAD_TO', 'adminfiles')
# ADMINFILES_THUMB_ORDER = getattr(settings, 'ADMINFILES_THUMB_ORDER',
#                                  ('-upload_date',))
# ADMINFILES_USE_SIGNALS = getattr(settings, 'ADMINFILES_USE_SIGNALS', False)
# ADMINFILES_REF_START = getattr(settings, 'ADMINFILES_REF_START', '<<<')
# ADMINFILES_REF_END = getattr(settings, 'ADMINFILES_REF_END', '>>>')
# ADMINFILES_STRING_IF_NOT_FOUND = getattr(settings,
#                                          'ADMINFILES_STRING_IF_NOT_FOUND',
#                                          u'')
# ADMINFILES_INSERT_LINKS = getattr(
#     settings,
#     'ADMINFILES_INSERT_LINKS',
#     {'': [(_('Insert Link'), {})],
#      'image': [(_('Insert'), {}),
#                (_('Insert (align left)'), {'class': 'left'}),
#                (_('Insert (align right)'), {'class': 'right'})]
#      },
#     )
# ADMINFILES_STDICON_SET = getattr(settings, 'ADMINFILES_STDICON_SET', None)
# ADMINFILES_BROWSER_VIEWS = getattr(settings, 'ADMINFILES_BROWSER_VIEWS',
#                                    ['adminfiles.views.AllView',
#                                     'adminfiles.views.ImagesView',
#                                     'adminfiles.views.AudioView',
#                                     'adminfiles.views.FilesView',
#                                     'adminfiles.views.FlickrView',
#                                     'adminfiles.views.YouTubeView',
#                                     'adminfiles.views.VimeoView'])


import os
import mimetypes
from django.conf import settings as django_settings
from django.db import models
from django.template.defaultfilters import slugify
from django.core.files.images import get_image_dimensions
from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from adminfiles import settings
    from tagging.fields import TagField
        try:
            uri = self.upload.path
        except NotImplementedError:
            uri = self.upload.url
        (mime_type, encoding) = mimetypes.guess_type(uri)
        try:
            [self.content_type, self.sub_type] = mime_type.split('/')
        except:
            self.content_type = 'text'
            self.sub_type = 'plain'
        super(FileUpload, self).save()

    def insert_links(self):
        links = []
        for key in [self.mime_type(), self.content_type, '']:
            if key in settings.ADMINFILES_INSERT_LINKS:
                links = settings.ADMINFILES_INSERT_LINKS[key]
                break
        for link in links:
            ref = self.slug
            opts = ':'.join(['%s=%s' % (k,v) for k,v in link[1].items()])
            if opts:
                ref += ':' + opts
            yield {'desc': link[0],
                   'ref': ref}

    def mime_image(self):
        if not settings.ADMINFILES_STDICON_SET:
            return None
        return ('http://www.stdicon.com/%s/%s?size=64'

# Path: adminfiles/settings.py
# JQUERY_URL = getattr(settings, 'JQUERY_URL',
#                      'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js')
#     JQUERY_URL = posixpath.join(settings.STATIC_URL, JQUERY_URL)
# ADMINFILES_UPLOAD_TO = getattr(settings, 'ADMINFILES_UPLOAD_TO', 'adminfiles')
# ADMINFILES_THUMB_ORDER = getattr(settings, 'ADMINFILES_THUMB_ORDER',
#                                  ('-upload_date',))
# ADMINFILES_USE_SIGNALS = getattr(settings, 'ADMINFILES_USE_SIGNALS', False)
# ADMINFILES_REF_START = getattr(settings, 'ADMINFILES_REF_START', '<<<')
# ADMINFILES_REF_END = getattr(settings, 'ADMINFILES_REF_END', '>>>')
# ADMINFILES_STRING_IF_NOT_FOUND = getattr(settings,
#                                          'ADMINFILES_STRING_IF_NOT_FOUND',
#                                          u'')
# ADMINFILES_INSERT_LINKS = getattr(
#     settings,
#     'ADMINFILES_INSERT_LINKS',
#     {'': [(_('Insert Link'), {})],
#      'image': [(_('Insert'), {}),
#                (_('Insert (align left)'), {'class': 'left'}),
#                (_('Insert (align right)'), {'class': 'right'})]
#      },
#     )
# ADMINFILES_STDICON_SET = getattr(settings, 'ADMINFILES_STDICON_SET', None)
# ADMINFILES_BROWSER_VIEWS = getattr(settings, 'ADMINFILES_BROWSER_VIEWS',
#                                    ['adminfiles.views.AllView',
#                                     'adminfiles.views.ImagesView',
#                                     'adminfiles.views.AudioView',
#                                     'adminfiles.views.FilesView',
#                                     'adminfiles.views.FlickrView',
#                                     'adminfiles.views.YouTubeView',
#                                     'adminfiles.views.VimeoView'])


# Path: adminfiles/models.py
import os
import mimetypes
from django.conf import settings as django_settings
from django.db import models
from django.template.defaultfilters import slugify
from django.core.files.images import get_image_dimensions
from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from adminfiles import settings
    from tagging.fields import TagField

        try:
            uri = self.upload.path
        except NotImplementedError:
            uri = self.upload.url
        (mime_type, encoding) = mimetypes.guess_type(uri)
        try:
            [self.content_type, self.sub_type] = mime_type.split('/')
        except:
            self.content_type = 'text'
            self.sub_type = 'plain'
        super(FileUpload, self).save()

    def insert_links(self):
        links = []
        for key in [self.mime_type(), self.content_type, '']:
            if key in settings.ADMINFILES_INSERT_LINKS:
                links = settings.ADMINFILES_INSERT_LINKS[key]
                break
        for link in links:
            ref = self.slug
            opts = ':'.join(['%s=%s' % (k,v) for k,v in link[1].items()])
            if opts:
                ref += ':' + opts
            yield {'desc': link[0],
                   'ref': ref}

    def mime_image(self):
        if not settings.ADMINFILES_STDICON_SET:
            return None
        return ('http://www.stdicon.com/%s/%s?size=64'

                % (settings.ADMINFILES_STDICON_SET, self.mime_type()))