Refactored get_url, verified command and other minor fixes
This commit is contained in:
parent
878dcf98fb
commit
1f0c1c8e43
8 changed files with 41 additions and 38 deletions
|
|
@ -548,12 +548,14 @@ def compare(val1, condition, val2):
|
|||
import frappe.utils
|
||||
return frappe.utils.compare(val1, condition, val2)
|
||||
|
||||
def respond_as_web_page(title, html, success=None):
|
||||
def respond_as_web_page(title, html, success=None, http_status_code=None):
|
||||
local.message_title = title
|
||||
local.message = html
|
||||
local.message_success = success
|
||||
local.response['type'] = 'page'
|
||||
local.response['page_name'] = 'message.html'
|
||||
if http_status_code:
|
||||
local.response['http_status_code'] = http_status_code
|
||||
|
||||
def build_match_conditions(doctype, as_condition=True):
|
||||
import frappe.widgets.reportview
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ frappe.desktop.show_pending_notifications = function() {
|
|||
sum = frappe.boot.notification_info.open_count_module[module];
|
||||
}
|
||||
if (frappe.modules[module]) {
|
||||
var notifier = $("#module-count-" + frappe.modules[module]._id);
|
||||
var notifier = $("#module-count-" + frappe.desktop.get_module(module)._id);
|
||||
if(notifier.length) {
|
||||
notifier.toggle(sum ? true : false);
|
||||
notifier.find(".circle-text").html(sum || "");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<h3>Password Reset</h3>
|
||||
<br>
|
||||
<p>Dear {{ first_name }}{% if last_name %} {{ last_name}}{% endif %},</p>
|
||||
<p>Please click on the following link to update your new password:</p>
|
||||
<p>Please click on the following link to set your new password:</p>
|
||||
<p><a href="{{ link }}">{{ link }}</a></p>
|
||||
<p>Thank you,<br>
|
||||
{{ user_fullname }}</p>
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
{% block title %} Reset Password {% endblock %}
|
||||
|
||||
{% block header %}{% endblock %}
|
||||
{% block breadcrumbs %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row" style="margin-top: 40px; margin-bottom: 20px">
|
||||
|
|
|
|||
|
|
@ -67,24 +67,6 @@ def validate_email_add(email_str):
|
|||
email = extract_email_id(email_str)
|
||||
return re.match("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", email.lower())
|
||||
|
||||
def get_request_site_address(full_address=False):
|
||||
"""get app url from request"""
|
||||
host_name = frappe.local.conf.host_name
|
||||
|
||||
if not host_name:
|
||||
if frappe.request:
|
||||
protocol = 'https' == frappe.get_request_header('X-Forwarded-Proto', "") and 'https://' or 'http://'
|
||||
host_name = protocol + frappe.request.host
|
||||
elif frappe.local.site:
|
||||
return "http://" + frappe.local.site
|
||||
else:
|
||||
return "http://localhost"
|
||||
|
||||
if full_address:
|
||||
return host_name + frappe.get_request_header("REQUEST_URI", "")
|
||||
else:
|
||||
return host_name
|
||||
|
||||
def random_string(length):
|
||||
"""generate a random string"""
|
||||
import string
|
||||
|
|
@ -817,19 +799,34 @@ def get_files_path():
|
|||
return get_site_path("public", "files")
|
||||
|
||||
def get_backups_path():
|
||||
return get_site_path("private", "backups")
|
||||
return get_site_path("private", "backups")
|
||||
|
||||
def get_url(uri=None):
|
||||
url = get_request_site_address()
|
||||
if not url or "localhost" in url:
|
||||
subdomain = frappe.db.get_value("Website Settings", "Website Settings",
|
||||
"subdomain")
|
||||
if subdomain:
|
||||
if "http" not in subdomain:
|
||||
url = "http://" + subdomain
|
||||
def get_request_site_address(full_address=False):
|
||||
return get_url(full_address=full_address)
|
||||
|
||||
def get_url(uri=None, full_address=False):
|
||||
"""get app url from request"""
|
||||
host_name = frappe.local.conf.host_name
|
||||
|
||||
if not host_name:
|
||||
if hasattr(frappe.local, "request") and frappe.local.request and frappe.local.request.host:
|
||||
protocol = 'https' == frappe.get_request_header('X-Forwarded-Proto', "") and 'https://' or 'http://'
|
||||
host_name = protocol + frappe.local.request.host
|
||||
elif frappe.local.site:
|
||||
host_name = "http://{}".format(frappe.local.site)
|
||||
else:
|
||||
host_name = frappe.db.get_value("Website Settings", "Website Settings",
|
||||
"subdomain")
|
||||
if host_name and "http" not in host_name:
|
||||
host_name = "http://" + host_name
|
||||
|
||||
if uri:
|
||||
url = urllib.basejoin(url, uri)
|
||||
if not host_name:
|
||||
host_name = "http://localhost"
|
||||
|
||||
if not uri and full_address:
|
||||
uri = frappe.get_request_header("REQUEST_URI", "")
|
||||
|
||||
url = urllib.basejoin(host_name, uri) if uri else host_name
|
||||
|
||||
return url
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ def json_handler(obj):
|
|||
def as_page():
|
||||
"""print web page"""
|
||||
from frappe.website.render import render
|
||||
return render(frappe.response['page_name'])
|
||||
return render(frappe.response['page_name'], http_status_code=frappe.response.get("http_status_code"))
|
||||
|
||||
def redirect():
|
||||
return werkzeug.utils.redirect(frappe.response.location)
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ import hmac
|
|||
import urllib
|
||||
|
||||
import frappe
|
||||
from frappe.utils import cstr
|
||||
import frappe.utils
|
||||
|
||||
def get_url(cmd, params, nonce, secret=None):
|
||||
signature = get_signature(params, nonce, secret)
|
||||
params['signature'] = signature
|
||||
return ''.join([frappe.local.request.url_root, 'api/method/', cmd, '?', urllib.urlencode(params)])
|
||||
return frappe.utils.get_url("".join(['api/method/', cmd, '?', urllib.urlencode(params)]))
|
||||
|
||||
def get_signature(params, nonce, secret=None):
|
||||
params = "".join((cstr(p) for p in params.values()))
|
||||
params = "".join((frappe.utils.cstr(p) for p in params.values()))
|
||||
if not secret:
|
||||
secret = frappe.local.conf.get("secret") or "secret"
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from frappe.website.permissions import get_access, clear_permissions
|
|||
|
||||
class PageNotFoundError(Exception): pass
|
||||
|
||||
def render(path, http_status_code=200):
|
||||
def render(path, http_status_code=None):
|
||||
"""render html page"""
|
||||
path = resolve_path(path.lstrip("/"))
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ def render(path, http_status_code=200):
|
|||
data = render_page(path)
|
||||
http_status_code = 500
|
||||
|
||||
return build_response(path, data, http_status_code)
|
||||
return build_response(path, data, http_status_code or 200)
|
||||
|
||||
def build_response(path, data, http_status_code):
|
||||
# build response
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue