From bcd6d6466c98c539395141dc8b931be75818c386 Mon Sep 17 00:00:00 2001
From: Yannik Ammann <ammann@arteria.ch>
Date: Tue, 9 Dec 2014 17:23:25 +0100
Subject: [PATCH] no message

---
 favicon/__init__.py                  |  2 +-
 favicon/admin.py                     |  2 +-
 favicon/models.py                    | 68 +++-------------------------
 favicon/templates/favicon/index.html |  1 -
 favicon/templatetags/favtags.py      | 37 ++-------------
 favicon/views.py                     |  1 +
 6 files changed, 14 insertions(+), 97 deletions(-)
 delete mode 100644 favicon/templates/favicon/index.html

diff --git a/favicon/__init__.py b/favicon/__init__.py
index 9123cf0..b8023d8 100644
--- a/favicon/__init__.py
+++ b/favicon/__init__.py
@@ -1 +1 @@
-__version__ = '0.0.8'
+__version__ = '0.0.1'
diff --git a/favicon/admin.py b/favicon/admin.py
index 3351bb0..5925ac5 100644
--- a/favicon/admin.py
+++ b/favicon/admin.py
@@ -3,6 +3,6 @@ from favicon.models import Favicon
 
 
 class FaviconAdmin(admin.ModelAdmin):
-    list_display = ('title', 'precomposed')
+    list_display = ('title', 'isFavicon')
 
 admin.site.register(Favicon, FaviconAdmin)
diff --git a/favicon/models.py b/favicon/models.py
index 3f12a86..c87445b 100644
--- a/favicon/models.py
+++ b/favicon/models.py
@@ -8,11 +8,6 @@ from PIL import Image
 import StringIO
 from django.core.files.uploadedfile import InMemoryUploadedFile
 
-
-#sizes = [16,32,64]
-sizes = [16,32,57,72,86,96,114,120,128,144,152,195,228]
-sizes = getattr(settings, 'FAVICON_SIZES', sizes)
-
 config = {
     'shortcut icon': [16 ,32 ,48 ,128, 192],
     'touch-icon': [196],
@@ -21,79 +16,31 @@ config = {
     'apple-touch-icon-precomposed': [57, 72, 76, 114, 120, 144, 152,180],
 }
 
+config = getattr(settings, 'FAVICON_CONFIG', config)
+
 
 @python_2_unicode_compatible
 class Favicon(models.Model):
-    verbose_name = 'Favicon'
-    verbose_name_plural = 'Favicons'
 
     title = models.CharField(max_length=100)
     faviconImage = models.ImageField(upload_to="favicon")
-    precomposed = models.BooleanField(default=False)
 
     isFavicon = models.BooleanField(default=True)
 
+    class Meta:
+        verbose_name = 'Favicon'
+        verbose_name_plural = 'Favicons'
 
     def get_favicons(self):
         favicons = []
         for rel in config:
             for size in config[rel]:
-                favicons.append(FaviconImg.objects.get(faviconFK=self, size=size, rel=rel))
-        return favicons
-
-    '''
-    def get_favicons(self):
-        return [self.get_favicon(n).faviconImage.name for n in sizes]
-        '''
-
-
-    '''
-    def get_favicons(self):
-        #favicons = []
-        #for n in sizes:
-        #    fav = self.get_favicon(n)
-        #    favicons.append(fav.faviconImages.name)
-
+                favicons.append(self.get_favicon(size, rel))
         return favicons
-    '''
-
-    '''
-    def get_favicons(self):
-        objs = FaviconImg.objects.filter(faviconFK=self)
-        favicons = []
-        for n in sizes:
-            favs = objs.filter(size=n)
-            fav = favs.get()
-            favicons.append(fav.faviconImage.name)
-        return favicons
-    '''
-
-    '''
-    def get_favicons(self):
-        objs = FaviconImg.objects.filter(faviconFK=self)
-        favicons = []
-        for n in sizes:
-            favs = objs.filter(size=n)
-            try:
-                fav = objs.get()
-            except:
-                if favs:
-                    for obj in favs:
-                        obj.delete()
-                fav = self.get_favicon(n)
-            favicons.append(fav.faviconImage.name)
-        return favicons
-    '''
-
-
-    def get_default_favicon(self):
-
 
     def __str__(self):
         return self.faviconImage.name
 
-    # def __unicode__(self):
-    #    return self.faviconImage.name
 
     def get_absolute_url(self):
         return "%s" % self.faviconImage.name
@@ -112,7 +59,6 @@ class Favicon(models.Model):
 
             fav.faviconImage=tmpFile
             fav.save()
-
         return fav
 
 
@@ -140,8 +86,6 @@ class Favicon(models.Model):
         #    for n in sizes:
         #        self.get_favicon(n,update=update)
 
-        
-
 
 class FaviconImg(models.Model):
     faviconFK = models.ForeignKey(Favicon)
diff --git a/favicon/templates/favicon/index.html b/favicon/templates/favicon/index.html
deleted file mode 100644
index dec9976..0000000
--- a/favicon/templates/favicon/index.html
+++ /dev/null
@@ -1 +0,0 @@
-<img src="{{ img }}">
\ No newline at end of file
diff --git a/favicon/templatetags/favtags.py b/favicon/templatetags/favtags.py
index 28ba3b4..e2eb99c 100644
--- a/favicon/templatetags/favtags.py
+++ b/favicon/templatetags/favtags.py
@@ -1,12 +1,11 @@
 from django import template
 from favicon.models import Favicon
 from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
 
 from favicon.models import Favicon
 from favicon.models import config
 
-from django.core.exceptions import ImproperlyConfigured
-
 register = template.Library()
 
 media_url = getattr(settings, 'MEDIA_URL', False)
@@ -21,6 +20,7 @@ def placeFavicon(context):
 
         {% placeFavicon %}
     """
+
     if not media_url:
         raise ImproperlyConfigured('MEDIA_URL not found in settings')
 
@@ -31,25 +31,12 @@ def placeFavicon(context):
     else:
         return '<!-- %s -->' % ('no favicon found',)
     '''
-
     favs = fav.get_favicons()
-
-
-
     request = context['request']
+    html = ''
+    html += '<link rel="shortcut icon" href="http://%s/favicon.ico"/>' % (request.get_host(),)
+    html += '<link rel="shortcut icon" href="http://%s/favicon.ico"/>'
 
-    html = '<link rel="shortcut icon" href="http://%s/favicon.ico"/>' % (request.get_host(),)
-
-
-
-    '''
-    for rel in config:
-        for size in sorted(config[rel],reverse=True):
-            n = fav.get_favicon(size=size,rel=rel)
-            html += '<link rel="%s" size ="%sx%s" href="%s%s"/>' % ( n.rel, n.size, n.size, media_url, n.faviconImage.name)
-    '''
-
-    
     for rel in config:
         for size in sorted(config[rel],reverse=True)[:-1]:
             n = fav.get_favicon(size=size,rel=rel)
@@ -57,19 +44,5 @@ def placeFavicon(context):
         for size in sorted(config[rel],reverse=True)[-1:]:
             n = fav.get_favicon(size=size,rel=rel)
             html += '<link rel="%s" size ="any" href="%s%s"/>' % ( n.rel, media_url, n.faviconImage.name)
-    
-
-    
 
     return html
-
-
-'''
-    try:
-        icon = Favicon.objects.all()[0]
-        return """<link rel='shortcut icon' href='%s%s'/>
-        <!-- %i -->""" %  ( str(settings.MEDIA_URL), str(icon.get_absolute_url()), icon.id )
-    except:
-        pass
-    return "<!-- ERROR: No valid favicon found, see https://bitbucket.org/arteria/django-favicon for more info. -->"
-'''
diff --git a/favicon/views.py b/favicon/views.py
index 9f1ce18..78fac34 100644
--- a/favicon/views.py
+++ b/favicon/views.py
@@ -12,6 +12,7 @@ from django.conf import settings
 def favicon(request, template_name='favicon/index.html'):
     if 'favicon' in request.path:
         fav = get_object_or_404(Favicon, isFavicon=True)
+        favicon = fav.get_favicon(64,'icon')
         link = settings.MEDIA_URL
         link += fav.faviconImage.name
         return redirect(link)
-- 
GitLab