[print] viewable if signature is given

This commit is contained in:
Rushabh Mehta 2014-09-17 12:37:25 +05:30
parent c34e835cd3
commit deb1c87dcd
6 changed files with 17 additions and 22 deletions

View file

@ -44,6 +44,7 @@ class Communication(Document):
def send(self, send_me_a_copy=False, print_html=None, print_format=None,
attachments=None):
if print_format:
print self.get_attach_link(print_format)
self.content += self.get_attach_link(print_format)
mail = get_email(self.recipients, sender=self.sender, subject=self.subject,
@ -73,7 +74,8 @@ class Communication(Document):
"url": get_url(),
"doctype": self.reference_doctype,
"name": self.reference_name,
"print_format": print_format
"print_format": print_format,
"key": self.get_parent_doc().get_signature()
})
def on_doctype_update():
@ -126,20 +128,3 @@ def attach_print(mail, parent_doc, print_html, print_format):
print_html = scrub_urls(print_html)
mail.add_attachment(name.replace(' ','').replace('/','-') + '.html',
print_html, 'text/html')
def set_portal_link(sent_via, comm):
"""set portal link in footer"""
footer = ""
if is_signup_enabled() and hasattr(sent_via, "get_portal_page"):
portal_page = sent_via.get_portal_page()
if portal_page:
is_valid_recipient = cstr(sent_via.get("email") or sent_via.get("email_id") or
sent_via.get("contact_email")) in comm.recipients
if is_valid_recipient:
url = "%s/%s?name=%s" % (get_url(), portal_page, urllib.quote(sent_via.name))
footer = """<!-- Portal Link -->
<p><a href="%s" target="_blank">View this on our website</a></p>""" % url
return footer

View file

@ -10,11 +10,11 @@ from frappe.model.document import Document
class ToDo(Document):
def validate(self):
if self.is_new():
self.add_comment(frappe._("Assigned to {0}").format(self.owner), "Assigned")
self.add_assign_comment(frappe._("Assigned to {0}").format(self.owner), "Assigned")
else:
cur_status = frappe.db.get_value("ToDo", self.name, "status")
if cur_status != self.status:
self.add_comment(frappe._("Assignment Status Changed"), "Assignment Completed")
self.add_assign_comment(frappe._("Assignment Status Changed"), "Assignment Completed")
def on_update(self):
self.update_in_reference()
@ -22,7 +22,7 @@ class ToDo(Document):
def on_trash(self):
self.update_in_reference()
def add_comment(self, text, comment_type):
def add_assign_comment(self, text, comment_type):
if not self.reference_type and self.reference_name:
return

View file

@ -9,6 +9,7 @@ from frappe.modules import load_doctype_module
from frappe.model.base_document import BaseDocument
from frappe.model.naming import set_new_name
from werkzeug.exceptions import NotFound, Forbidden
import hashlib
# once_only validation
# methods
@ -590,3 +591,6 @@ class Document(BaseDocument):
"comment": text or comment_type
}).insert(ignore_permissions=True)
return comment
def get_signature(self):
return hashlib.sha224(self.creation).hexdigest()

View file

@ -1,3 +1,3 @@
<p>
<a href="{{ url }}/print?doctype={{ doctype }}&name={{ name }}&format={{ print_format }}">{{ _("View this in your browser") }}</a>
<a href="{{ url }}/{{ doctype }}/{{ name }}?format={{ print_format }}&key={{ key }}">{{ _("View this in your browser") }}</a>
</p>

View file

@ -95,6 +95,10 @@ def download_pdf(doctype, name, format=None):
frappe.local.response.type = "download"
def validate_print_permission(doc):
if frappe.form_dict.get("key"):
if frappe.form_dict.key == doc.get_signature():
return
for ptype in ("read", "print"):
if not frappe.has_permission(doc.doctype, ptype, doc):
raise frappe.PermissionError(_("No {0} permission").format(ptype))

View file

@ -39,6 +39,8 @@ def upload():
comment = frappe.get_doc(dt, dn).add_comment("Attachment",
_("Added {0}").format("<a href='{file_url}' target='_blank'>{file_name}</a>".format(**filedata.as_dict())))
print dt, dn, comment
return {
"name": filedata.name,
"file_name": filedata.file_name,