[website] [cleanup] selectable images will now be relative urls (files/..) or full urls (http:..)

This commit is contained in:
Rushabh Mehta 2013-03-28 16:26:11 +05:30
parent 0c541a0fe2
commit 2fe802c81e
12 changed files with 26 additions and 42 deletions

View File

@ -0,0 +1,16 @@
import webnotes
def execute():
for f in webnotes.conn.sql("""select parent, fieldname
from tabDocField where options="attach_files:" """, as_dict=1):
if webnotes.conn.get_value("DocType", f.parent, "issingle"):
fname = webnotes.conn.get_value(f.parent, None, f.fieldname)
if fname:
if not (fname.startswith("http") or fname.startswith("files")):
webnotes.conn.set_value(f.parent, None, f.fieldname, "files/" + fname)
else:
webnotes.conn.sql("""update `tab%(parent)s`
set %(fieldname)s =
if(substr(%(fieldname)s,0,4)='http' or substr(%(fieldname)s, 0, 5)='files',
%(fieldname)s,
concat('files/', %(fieldname)s))""" % f)

View File

@ -224,4 +224,5 @@ patch_list = [
"execute:webnotes.conn.set_value('Email Settings', None, 'send_print_in_body_and_attachment', 1)",
"patches.march_2013.p09_unset_user_type_partner",
"patches.march_2013.p10_set_fiscal_year_for_stock",
"patches.march_2013.p11_update_attach_files",
]

View File

@ -235,9 +235,8 @@ class DocType(DocListController):
clear_cache(self.doc.page_name)
def prepare_template_args(self):
from website.helpers.product import get_parent_item_groups, url_for_website
from website.helpers.product import get_parent_item_groups
self.parent_groups = get_parent_item_groups(self.doc.item_group) + [{"name":self.doc.name}]
self.doc.website_image = url_for_website(self.doc.website_image)
self.doc.title = self.doc.item_name
if self.doc.slideshow:

View File

@ -2,7 +2,6 @@
from __future__ import unicode_literals
import webnotes
from website.utils import url_for_website
class DocType:
def __init__(self, d, dl):
@ -14,9 +13,6 @@ class DocType:
def get_args():
obj = webnotes.get_obj("About Us Settings")
for d in obj.doclist.get({"doctype":"About Us Team Member"}):
if not "/" in d.image_link:
d.image_link = "files/" + d.image_link
return {
"obj": obj
}

View File

@ -78,8 +78,6 @@ class DocType:
self.doc.content_html = self.doc.content
if self.doc.blogger:
self.doc.blogger_info = webnotes.doc("Blogger", self.doc.blogger).fields
if self.doc.blogger_info.avatar and not "/" in self.doc.blogger_info.avatar:
self.doc.blogger_info.avatar = "files/" + self.doc.blogger_info.avatar
self.doc.description = self.doc.blog_intro or self.doc.content[:140]

View File

@ -4,7 +4,7 @@
body {
{% if doc.background_image %}
background: url("../files/{{ doc.background_image }}") repeat;
background: url("../{{ doc.background_image }}") repeat;
{% elif doc.background_color %}
background-color: #{{ doc.background_color }};
background-image: none;
@ -67,16 +67,10 @@ div.web-footer, div.web-footer a {
/* Bootstrap Navbar */
.navbar-inverse .navbar-inner {
box-shadow: none;
background-color: #{{ doc.top_bar_background or "444444"}};
background-repeat: repeat-x;
background-image: none;
}
.navbar-inner {
box-shadow: none;
}
.navbar-inner {
border-bottom: 1px solid {% if doc.top_bar_background == doc.page_background -%}
#{{ get_hex_shade(doc.page_background or "ffffff", 15) }};
{%- else -%}

View File

@ -48,7 +48,6 @@ cur_frm.cscript.set_banner_from_image = function(doc) {
msgprint(wn._("Select a Banner Image first."));
}
var src = doc.banner_image;
if(src.indexOf("/")==-1) src = "files/" + src;
cur_frm.set_value("banner_html", "<a href='/'><img src='"+ src
+"' style='max-width: 200px;'></a>");
}

View File

@ -46,8 +46,6 @@ def get_blog_list(start=0, by=None, category=None):
if not res['content']:
res['content'] = website.utils.get_html(res['page_name'])
res['content'] = res['content'][:140]
if res.avatar and not "/" in res.avatar:
res.avatar = "files/" + res.avatar
return result
@ -133,9 +131,6 @@ def get_blog_template_args():
def get_writers_args():
bloggers = webnotes.conn.sql("""select * from `tabBlogger`
order by posts desc""", as_dict=1)
for blogger in bloggers:
if blogger.avatar and not "/" in blogger.avatar:
blogger.avatar = "files/" + blogger.avatar
args = {
"bloggers": bloggers,

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr
from website.utils import build_html, url_for_website, delete_page_cache
from website.utils import build_html, delete_page_cache
@webnotes.whitelist(allow_guest=True)
@ -90,7 +90,6 @@ def scrub_item_for_list(r):
r.website_description = "No description given"
if len(r.website_description.split(" ")) > 24:
r.website_description = " ".join(r.website_description.split(" ")[:24]) + "..."
r.website_image = url_for_website(r.website_image)
def get_parent_item_groups(item_group_name):
item_group = webnotes.doc("Item Group", item_group_name)

View File

@ -20,7 +20,4 @@ def get_slideshow(obj):
slideshow = webnotes.bean("Website Slideshow", obj.doc.slideshow)
obj.slides = slideshow.doclist.get({"doctype":"Website Slideshow Item"})
obj.doc.slideshow_header = slideshow.doc.header or ""
for s in obj.slides:
if s.image and not s.image.lower().startswith("http"):
s.image = "files/" + s.image

View File

@ -10,13 +10,8 @@
<script type="text/javascript" src="js/wn-web.js"></script>
<link type="text/css" rel="stylesheet" href="css/all-web.css">
<link type="text/css" rel="stylesheet" href="css/wn-web.css">
{%- if favicon %}
<link rel="shortcut icon" href="files/{{ favicon }}" type="image/x-icon">
<link rel="icon" href="files/{{ favicon }}" type="image/x-icon">
{% else %}
<link rel="shortcut icon" href="app/images/favicon.ico" type="image/x-icon">
<link rel="icon" href="app/images/favicon.ico" type="image/x-icon">
{% endif -%}
<link rel="shortcut icon" href="{{ favicon }}" type="image/x-icon">
<link rel="icon" href="{{ favicon }}" type="image/x-icon">
{% if description -%}
<meta name="description" content="{{ description }}">
{%- endif %}

View File

@ -192,6 +192,7 @@ def get_source_doc(page_name):
return None, None
def get_outer_env(page_name, args):
from webnotes.utils import get_request_site_address
from urllib import quote
@ -238,7 +239,7 @@ def get_outer_env(page_name, args):
args.update(ret)
settings = webnotes.doc("Website Settings", "Website Settings")
for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via"
for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
"favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
if k in settings.fields:
args[k] = settings.fields.get(k)
@ -280,13 +281,7 @@ def get_all_pages():
def delete_page_cache(page_name):
if page_name:
webnotes.cache().delete_value("page:" + page_name)
def url_for_website(url):
if url and not url.lower().startswith("http"):
return "files/" + url
else:
return url
def get_hex_shade(color, percent):
def p(c):