Browse Source

[enhancement] edit-profile in frappe

version-14
Rushabh Mehta 9 years ago
parent
commit
123842ffda
6 changed files with 108 additions and 5 deletions
  1. +27
    -2
      frappe/core/doctype/user/user.json
  2. +3
    -1
      frappe/database.py
  3. +2
    -1
      frappe/model/utils/link_count.py
  4. +46
    -0
      frappe/templates/pages/edit-profile.html
  5. +29
    -0
      frappe/templates/pages/edit_profile.py
  6. +1
    -1
      frappe/templates/pages/list.py

+ 27
- 2
frappe/core/doctype/user/user.json View File

@@ -420,6 +420,31 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "phone",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Phone",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@@ -1458,7 +1483,7 @@
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "icon-user",
"idx": 1,
"idx": 253,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
@@ -1466,7 +1491,7 @@
"istable": 0,
"max_attachments": 5,
"menu_index": 0,
"modified": "2016-03-29 06:26:24.316335",
"modified": "2016-03-30 07:32:15.815142",
"modified_by": "Administrator",
"module": "Core",
"name": "User",


+ 3
- 1
frappe/database.py View File

@@ -369,7 +369,8 @@ class Database:
"""Returns `get_value` with fieldname='*'"""
return self.get_value(doctype, filters, "*", as_dict=as_dict, cache=cache)

def get_value(self, doctype, filters=None, fieldname="name", ignore=None, as_dict=False, debug=False, cache=False):
def get_value(self, doctype, filters=None, fieldname="name", ignore=None, as_dict=False,
debug=False, cache=False):
"""Returns a document property or list of properties.

:param doctype: DocType name.
@@ -418,6 +419,7 @@ class Database:
user = frappe.db.get_values("User", "test@example.com", "*")[0]
"""
out = None
cache = False
if cache and isinstance(filters, basestring) and \
(doctype, filters, fieldname) in self.value_cache:
return self.value_cache[(doctype, filters, fieldname)]


+ 2
- 1
frappe/model/utils/link_count.py View File

@@ -23,7 +23,8 @@ def update_link_count():
link_count = frappe.cache().get_value('_link_count')
if link_count:
for key, count in link_count.iteritems():
frappe.db.sql('update `tab{0}` set idx = idx + %s where name=%s'.format(key[0]), (count, key[1]))
frappe.db.sql('update `tab{0}` set idx = idx + %s where name=%s'.format(key[0]),
(count, key[1]))

# reset the count
frappe.cache().delete_value('_link_count')

+ 46
- 0
frappe/templates/pages/edit-profile.html View File

@@ -0,0 +1,46 @@
{% extends "templates/web.html" %}

{% block title %} {{ "Edit Profile" }} {% endblock %}

{% block header %}<h2>{{ _("Edit Profile") }}</h2>{% endblock %}

{% block page_content %}
<div class="user-content" style="max-width: 500px;">
<div class="alert alert-warning" id="message" style="display: none;"></div>
<form>
<fieldset>
<label>{{ _("Full Name") }}</label>
<input class="form-control" type="text" id="fullname" value="{{ user.full_name or "" }}">
</fieldset>
<fieldset>
<label>{{ _("Phone") }}</label>
<input class="form-control" type="text" id="phone" value="{{ user.phone or "" }}">
</fieldset>
<button id="update_user" type="submit" class="btn btn-default">{{ _("Update") }}</button>
</form>
</div>
<script>
frappe.ready(function() {
$("#fullname").val(getCookie("full_name") || "");
$("#update_user").click(function() {
frappe.call({
method: "frappe.templates.pages.edit_profile.update_user",
type: "POST",
args: {
fullname: $("#fullname").val(),
org_name: $("#org_name").val(),
phone: $("#phone").val()
},
btn: this,
msg: $("#message"),
callback: function(r) {
if(!r.exc) $("#user-full-name").html($("#fullname").val());
}
});
return false;
})
})
</script>
<!-- no-sidebar -->
{% endblock %}


+ 29
- 0
frappe/templates/pages/edit_profile.py View File

@@ -0,0 +1,29 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _

no_cache = 1
no_sitemap = 1

def get_context(context):
user = frappe.get_doc('User', frappe.session.user)
user.full_name = user.get_fullname()
context.user = user

@frappe.whitelist()
def update_user(fullname, phone=None):
if not fullname:
return _("Name is required")

user = frappe.get_doc('User', frappe.session.user)
user.first_name = fullname
user.last_name = ''
user.phone = phone
user.save(ignore_permissions=True)

frappe.local.cookie_manager.set_cookie("full_name", fullname)

return _("Updated")

+ 1
- 1
frappe/templates/pages/list.py View File

@@ -69,7 +69,7 @@ def set_route(context):
'''Set link for the list item'''
if context.is_web_form:
context.route = "{0}?name={1}".format(context.pathname, quote_plus(context.doc.name))
elif hasattr(context.doc, 'get_route'):
elif context.doc and getattr(context.doc, 'get_route', None):
context.route = context.doc.get_route()
else:
context.route = "{0}/{1}".format(context.pathname or quote_plus(context.doc.doctype), quote_plus(context.doc.name))


Loading…
Cancel
Save