[new] Chapter Module clean up after review
diff --git a/erpnext/non_profit/doctype/chapter/chapter.json b/erpnext/non_profit/doctype/chapter/chapter.json
index 2d159f3..718df6f 100644
--- a/erpnext/non_profit/doctype/chapter/chapter.json
+++ b/erpnext/non_profit/doctype/chapter/chapter.json
@@ -2,7 +2,7 @@
  "allow_copy": 0, 
  "allow_guest_to_view": 1, 
  "allow_import": 0, 
- "allow_rename": 0, 
+ "allow_rename": 1, 
  "autoname": "field:title", 
  "beta": 0, 
  "creation": "2017-09-14 13:36:03.904702", 
@@ -170,6 +170,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "description": "chapters/chapter_name\nleave blank automatically set after saving chapter.", 
    "fieldname": "route", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -297,7 +298,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-11-23 17:31:44.669507", 
+ "modified": "2017-11-24 15:47:01.752772", 
  "modified_by": "Administrator", 
  "module": "Non Profit", 
  "name": "Chapter", 
@@ -329,7 +330,7 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "restrict_to_domain": "Non Profit", 
- "route": "chapter", 
+ "route": "chapters", 
  "show_name_in_global_search": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
diff --git a/erpnext/non_profit/doctype/chapter/chapter.py b/erpnext/non_profit/doctype/chapter/chapter.py
index efde580..7ee74d2 100644
--- a/erpnext/non_profit/doctype/chapter/chapter.py
+++ b/erpnext/non_profit/doctype/chapter/chapter.py
@@ -5,18 +5,20 @@
 from __future__ import unicode_literals
 import frappe
 from frappe.website.website_generator import WebsiteGenerator
-from frappe.model.document import Document
-from frappe import _
 
 class Chapter(WebsiteGenerator):
+	_website = frappe._dict(
+		condition_field = "published",
+	)
+
 	def get_context(self, context):
 		context.no_cache = True
+		context.parents = [dict(label='View All Chapters',
+			route='chapters', title='View Chapters')]
 
 	def validate(self):
-		chapter_head = self.chapter_head
-		chapter = frappe.get_all('Chapter', filters={'published': True}, fields=['chapter_head'])
 		if not self.route:		#pylint: disable=E0203
-			self.route = 'chapter/' + self.scrub(self.name)
+			self.route = 'chapters/' + self.scrub(self.name)
 
 	def enable(self):
 		chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
@@ -31,4 +33,4 @@
 	context.title = 'All Chapters'
 	context.no_breadcrumbs = True
 	context.order_by = 'creation desc'
-	context.introduction = '<p>All Chapters</p>'
+	context.introduction = '<p>All Chapters</p>'
\ No newline at end of file
diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter.html b/erpnext/non_profit/doctype/chapter/templates/chapter.html
index c2d871c..8953481 100644
--- a/erpnext/non_profit/doctype/chapter/templates/chapter.html
+++ b/erpnext/non_profit/doctype/chapter/templates/chapter.html
@@ -57,8 +57,8 @@
 <h3>Address</h3>
 <p>{{ address }}</p>
 
-<p style="margin: 20px 0 30px;"><a href="/join-chapter?name={{ name }}" class='btn btn-primary'>Join this Chapter</a></p>
-<p style="margin: 20px 0 30px;"><a href="/leave-chapter?name={{ name }}" class=''>Leave this Chapter</a></p>
+<p style="margin: 20px 0 30px;"><a href="/non_profit/join-chapter?name={{ name }}" class='btn btn-primary'>Join this Chapter</a></p>
+<p style="margin: 20px 0 30px;"><a href="/non_profit/leave-chapter?name={{ name }}" class=''>Leave this Chapter</a></p>
 
 
 {% endblock %}
diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
index 042aede..b6780e2 100644
--- a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
+++ b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
@@ -1,5 +1,5 @@
 <div style="margin-bottom: 30px; max-width: 600px" class="with-border clickable">
-	<a href={{ route }}>
+	<a href="/{{ doc.route }}">
 		<h3>{{ doc.title }}</h3>
 		<p>
 			<span class="label">{{ frappe.db.get_value('User', chapter_head, 'full_name') }}</span>
@@ -14,4 +14,45 @@
 		<p>{{ html2text(doc.introduction[:200]) }}{% if introduction|len > 200 %}...{% endif %}</p>
 	</a>
 </div>
-<!-- this is a sample default list template -->
\ No newline at end of file
+<style type="text/css">
+
+.label {
+	font-weight: normal;
+	background-color: #d1d8dd;
+	font-size: 13px;
+	padding: 3px 7px;
+	margin-right: 10px;
+}
+
+
+.with-border {
+	border: 1px solid #d1d8dd;
+	border-radius: 3px;
+	padding: 15px;
+	margin-bottom: 30px;
+}
+
+.with-border h3 {
+	margin-top: 0px;
+}
+
+a {
+	color: #5E64FF;
+}
+
+.clickable a {
+	color: #161c23;
+}
+
+.with-border.clickable:hover {
+	border-color: #36414C;
+	background-color: #fafbfc;
+
+}
+
+.with-border a, .with-border a:hover {
+	text-decoration: none;
+}
+
+
+</style>
\ No newline at end of file
diff --git a/erpnext/templates/pages/non_profit/__init__.py b/erpnext/templates/pages/non_profit/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/templates/pages/non_profit/__init__.py
diff --git a/erpnext/templates/pages/non_profit/join-chapter.html b/erpnext/templates/pages/non_profit/join-chapter.html
new file mode 100644
index 0000000..284e9c4
--- /dev/null
+++ b/erpnext/templates/pages/non_profit/join-chapter.html
@@ -0,0 +1,59 @@
+{% extends "templates/web.html" %}
+
+{% block page_content %}
+
+{% macro chapter_button() %}
+	<p><a href="/{{ chapter.route }}" class='btn btn-primary'>
+		Go to Chapter Page</a></p>
+{% endmacro %}
+{% if frappe.session.user=='Guest' %}
+	<p>Please signup and login to join this chapter</p>
+	<p><a href="/login?redirect-to=/{{ chapter.route }}" class='btn btn-primary'>Login</a></p>
+{% else %}
+	{% if already_member %}
+		<p>You are already a member of {{ chapter.title }}!</p>
+		{{ chapter_button() }}
+		<p><a href="">Leave Chapter</a></p>
+	{% else %}
+		{% if frappe.local.request.method=='POST' %}
+			<p>Welcome to chapter {{ chapter.title }}!</p>
+			{{ chapter_button() }}
+		{% else %}
+			<div style="padding: 20px 0;">
+				<div class="row">
+					<div class="col-lg-8 col-md-8">
+						<form name="user-intro" action="/join-chapter" method='POST'>
+							<div class="form-group">
+								<input name="name" class="hidden form-control" type="text"
+									value="{{chapter.name}}">
+								<input name="csrf_token" class="hidden  form-control" type="text"
+									value="{{frappe.session.csrf_token}}">
+							</div>
+							<div class="form-group">
+								<label for="user" class="">User Name</label>
+								<input name="user" class="form-control" type="text" value="{{ frappe.session.user }}">
+							</div>
+							<div class="form-group">
+								<label for="website_url" class="">Website URL</label>
+								<input name="website_url" required class="form-control" type="text"
+									placeholder="https://example.com" />
+							</div>
+							<div class="form-group">
+								<label for="introduction" class="">Introduction</label>
+								<textarea name="introduction" required class="form-control"
+									placeholder="Your profession and how you are associated with ERPNext"></textarea>
+							</div>
+							<div class="form-group">
+								<button type="Submit" id="update_member" class="btn btn-primary">
+									Submit</button>
+							</div>
+						</form>
+					</div>
+				</div>
+			</div>
+		{% endif %}
+	{% endif %}
+
+{% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/pages/non_profit/join_chapter.js b/erpnext/templates/pages/non_profit/join_chapter.js
new file mode 100644
index 0000000..e2bc8bc
--- /dev/null
+++ b/erpnext/templates/pages/non_profit/join_chapter.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2017, EOSSF and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Chapter Member', {
+	onsubmit: function (frm) {
+		console.log("here" + frappe.session.user)
+		// body...
+	}
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/templates/pages/non_profit/join_chapter.py b/erpnext/templates/pages/non_profit/join_chapter.py
new file mode 100644
index 0000000..bc9ba6b
--- /dev/null
+++ b/erpnext/templates/pages/non_profit/join_chapter.py
@@ -0,0 +1,22 @@
+import frappe
+
+def get_context(context):
+	context.no_cache = True
+	chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
+	if frappe.session.user!='Guest':
+		if frappe.session.user in [d.user for d in chapter.members]:
+			context.already_member = True
+		else:
+			if frappe.request.method=='GET':
+				pass
+			elif frappe.request.method=='POST':
+				chapter.append('members', dict(
+					user=frappe.session.user, 
+					introduction=frappe.form_dict.introduction,
+					website_url=frappe.form_dict.website_url,
+					enabled=1
+				))
+				chapter.save(ignore_permissions=1)
+				frappe.db.commit()
+
+	context.chapter = chapter
diff --git a/erpnext/templates/pages/non_profit/leave-chapter.html b/erpnext/templates/pages/non_profit/leave-chapter.html
new file mode 100644
index 0000000..2f8452d
--- /dev/null
+++ b/erpnext/templates/pages/non_profit/leave-chapter.html
@@ -0,0 +1,16 @@
+{% extends "templates/web.html" %}
+<!-- 
+{% macro chapter_button() %}
+	<p><a href="/{{ chapter.route }}" class='btn btn-primary'>
+		Go to Chapter Page</a></p>
+{% endmacro %}
+ -->
+{% block page_content %}
+
+	{% if member_deleted %}
+		<p>You are not a member of {{ chapter.title }}!</p>
+		<p>Please signup and login to join this chapter</p>
+
+		<p><a href="/join-chapter?name={{ chapter.name }}" class='btn btn-primary'>Become Member agian</a></p>
+	{% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/pages/non_profit/leave_chapter.py b/erpnext/templates/pages/non_profit/leave_chapter.py
new file mode 100644
index 0000000..6dbdeca
--- /dev/null
+++ b/erpnext/templates/pages/non_profit/leave_chapter.py
@@ -0,0 +1,15 @@
+import frappe
+
+def get_context(context):
+	context.no_cache = True
+	chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
+	# if frappe.session.user!='Guest':
+	if frappe.session.user in [d.user for d in chapter.members]:
+		user = frappe.session.user
+		parent = frappe.form_dict.name
+		frappe.db.sql("""delete from `tabChapter Member` where parent = %s and user = %s """, (parent, user))
+		frappe.db.commit()
+
+	context.member_deleted = True
+
+	context.chapter = chapter