Browse Source

Refactored get_url, verified command and other minor fixes

version-14
Anand Doshi 11 years ago
parent
commit
1f0c1c8e43
8 changed files with 42 additions and 39 deletions
  1. +3
    -1
      frappe/__init__.py
  2. +1
    -1
      frappe/core/page/desktop/desktop.js
  3. +2
    -1
      frappe/templates/emails/password_reset.html
  4. +3
    -0
      frappe/templates/pages/update-password.html
  5. +27
    -30
      frappe/utils/__init__.py
  6. +1
    -1
      frappe/utils/response.py
  7. +3
    -3
      frappe/utils/verified_command.py
  8. +2
    -2
      frappe/website/render.py

+ 3
- 1
frappe/__init__.py View File

@@ -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


+ 1
- 1
frappe/core/page/desktop/desktop.js View File

@@ -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 || "");


+ 2
- 1
frappe/templates/emails/password_reset.html View File

@@ -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>

+ 3
- 0
frappe/templates/pages/update-password.html View File

@@ -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">


+ 27
- 30
frappe/utils/__init__.py View File

@@ -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")
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
return get_site_path("private", "backups")
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



+ 1
- 1
frappe/utils/response.py View File

@@ -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)


+ 3
- 3
frappe/utils/verified_command.py View File

@@ -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"


+ 2
- 2
frappe/website/render.py View File

@@ -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…
Cancel
Save