diff --git a/blog/templatetags/blog_tags.py b/blog/templatetags/blog_tags.py index c0e4775..c9bf164 100644 --- a/blog/templatetags/blog_tags.py +++ b/blog/templatetags/blog_tags.py @@ -130,14 +130,14 @@ def load_sidebar(user): show_adsense = settings.SHOW_GOOGLE_ADSENSE # 标签云 计算字体大小 # 根据总数计算出平均值 大小为 (数目/平均值)*步长 - increment = 10 + increment = 5 tags = Tag.objects.all() sidebar_tags = None if tags: s = list(map(lambda t: (t, t.get_article_count()), tags)) count = sum(map(lambda t: t[1], s)) dd = count / len(tags) - sidebar_tags = list(map(lambda x: (x[0], x[1], (x[1] / dd) * increment), s)) + sidebar_tags = list(map(lambda x: (x[0], x[1], (x[1] / dd) * increment + 10), s)) return { 'recent_articles': recent_articles, diff --git a/blog/views.py b/blog/views.py index b5bbd68..4dba923 100644 --- a/blog/views.py +++ b/blog/views.py @@ -209,19 +209,29 @@ class TagDetailView(ArticleListView): @csrf_exempt def fileupload(request): if request.method == 'POST': - fname = '' - timestr = datetime.datetime.now().strftime('%Y/%m/%d') - basepath = os.path.join(r'/var/www/resource/image/', timestr) - if not os.path.exists(basepath): - os.makedirs(basepath) - fname = '' + response = [] for filename in request.FILES: - fname = filename + timestr = datetime.datetime.now().strftime('%Y/%m/%d') + imgextensions = ['jpg', 'png', 'jpeg', 'bmp'] + fname = u''.join(str(filename)) + + isimage = len([i for i in imgextensions if fname.find(i) >= 0]) > 0 + basepath = os.path.join(r'/var/www/resource/' + 'files' if not isimage else'image' + '/', + timestr) + url = 'https://resource.lylinux.net/{type}/{timestr}/{filename}'.format( + type='files' if not isimage else'image', timestr=timestr, filename=filename) + if not os.path.exists(basepath): + os.makedirs(basepath) savepath = os.path.join(basepath, filename) with open(savepath, 'wb+') as wfile: for chunk in request.FILES[filename].chunks(): wfile.write(chunk) - return HttpResponse('https://resource.lylinux.net/' + 'image/' + timestr + '/' + fname) + if isimage: + from PIL import Image + image = Image.open(savepath) + image.save(savepath, quality=20, optimize=True) + response.append(url) + return HttpResponse(response) else: return HttpResponse("only for post") diff --git a/requirements.txt b/requirements.txt index 6349ca6..720bc93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ django-appconf==1.0.2 django-autoslug==1.9.3 django-compressor==2.1.1 django-debug-toolbar==1.8 -django-haystack==2.6.0 +django-haystack==2.6.1 django-ipware==1.1.6 django-pagedown==0.1.3 django-uuslug==1.1.8 diff --git a/templates/share_layout/base.html b/templates/share_layout/base.html index 850b452..17cfcd6 100644 --- a/templates/share_layout/base.html +++ b/templates/share_layout/base.html @@ -36,15 +36,12 @@ {% comment %}{% endcomment %} + {% block compress_css %} {% endblock %} {% endcompress %} - {% comment %} - {% endcomment %} -
@@ -74,23 +71,9 @@ {% include 'share_layout/footer.html' %} -{% comment %} -