From a72a3bd536b6ab334b71f09012804b03fe63e7d0 Mon Sep 17 00:00:00 2001 From: Vishal Date: Fri, 24 Nov 2017 17:24:41 +0530 Subject: [PATCH] [new] Chapter Module clean up after review --- .../non_profit/doctype/chapter/chapter.json | 7 ++- erpnext/non_profit/doctype/chapter/chapter.py | 14 +++-- .../doctype/chapter/templates/chapter.html | 4 +- .../chapter/templates/chapter_row.html | 45 +++++++++++++- .../templates/pages/non_profit/__init__.py | 0 .../pages/non_profit/join-chapter.html | 59 +++++++++++++++++++ .../pages/non_profit/join_chapter.js | 12 ++++ .../pages/non_profit/join_chapter.py | 22 +++++++ .../pages/non_profit/leave-chapter.html | 16 +++++ .../pages/non_profit/leave_chapter.py | 15 +++++ 10 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 erpnext/templates/pages/non_profit/__init__.py create mode 100644 erpnext/templates/pages/non_profit/join-chapter.html create mode 100644 erpnext/templates/pages/non_profit/join_chapter.js create mode 100644 erpnext/templates/pages/non_profit/join_chapter.py create mode 100644 erpnext/templates/pages/non_profit/leave-chapter.html create mode 100644 erpnext/templates/pages/non_profit/leave_chapter.py diff --git a/erpnext/non_profit/doctype/chapter/chapter.json b/erpnext/non_profit/doctype/chapter/chapter.json index 2d159f3a85..718df6f91e 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 efde580b83..7ee74d2a38 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 @@ def get_list_context(context): context.title = 'All Chapters' context.no_breadcrumbs = True context.order_by = 'creation desc' - context.introduction = '

All Chapters

' + context.introduction = '

All Chapters

' \ 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 c2d871c5e7..8953481196 100644 --- a/erpnext/non_profit/doctype/chapter/templates/chapter.html +++ b/erpnext/non_profit/doctype/chapter/templates/chapter.html @@ -57,8 +57,8 @@

Address

{{ address }}

-

Join this Chapter

-

Leave this Chapter

+

Join this Chapter

+

Leave this Chapter

{% endblock %} diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html index 042aede17c..b6780e2328 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 @@
- +

{{ doc.title }}

{{ frappe.db.get_value('User', chapter_head, 'full_name') }} @@ -14,4 +14,45 @@

{{ html2text(doc.introduction[:200]) }}{% if introduction|len > 200 %}...{% endif %}

- \ No newline at end of file + \ 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 0000000000..e69de29bb2 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 0000000000..284e9c4356 --- /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() %} +

+ Go to Chapter Page

+{% endmacro %} +{% if frappe.session.user=='Guest' %} +

Please signup and login to join this chapter

+

Login

+{% else %} + {% if already_member %} +

You are already a member of {{ chapter.title }}!

+ {{ chapter_button() }} +

Leave Chapter

+ {% else %} + {% if frappe.local.request.method=='POST' %} +

Welcome to chapter {{ chapter.title }}!

+ {{ chapter_button() }} + {% else %} +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+ {% 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 0000000000..e2bc8bca71 --- /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 0000000000..bc9ba6ba74 --- /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 0000000000..2f8452d525 --- /dev/null +++ b/erpnext/templates/pages/non_profit/leave-chapter.html @@ -0,0 +1,16 @@ +{% extends "templates/web.html" %} + +{% block page_content %} + + {% if member_deleted %} +

You are not a member of {{ chapter.title }}!

+

Please signup and login to join this chapter

+ +

Become Member agian

+ {% 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 0000000000..6dbdeca528 --- /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