[fix] back links from project web view
diff --git a/erpnext/templates/includes/projects/macros.html b/erpnext/templates/includes/projects/macros.html
new file mode 100644
index 0000000..eb2b8db
--- /dev/null
+++ b/erpnext/templates/includes/projects/macros.html
@@ -0,0 +1 @@
+{% macro back_link(doc) %}&back-to=/projects?project={{ doc.name }}|{{ doc.project_name }}{% endmacro %}
diff --git a/erpnext/templates/includes/projects/project_issues.html b/erpnext/templates/includes/projects/project_issues.html
index 34f6633..0d569d8 100644
--- a/erpnext/templates/includes/projects/project_issues.html
+++ b/erpnext/templates/includes/projects/project_issues.html
@@ -1,10 +1,12 @@
+{%- from "templates/includes/projects/macros.html" import back_link -%}
+
 {% for issue in doc.issues %}
 		<div class='issue'>
 			<div class='row project-item'>
 				<div class='col-xs-9'>
-					<a class="no-decoration" href="/issues-view?name={{ issue.name}}">
+					<a class="no-decoration" href="/issues?name={{ issue.name}}{{ back_link(doc) }}">
 						<span class="indicator {{ "red" if issue.status=="Open" else "green" }}">
-							{% if issue.status == "Closed" %} 
+							{% if issue.status == "Closed" %}
 							{{ issue.subject }} resolved {{ frappe.utils.pretty_date(issue.resolution_date) }}
 							{% else %}
 							{{ issue.subject }} raised on {{ issue.opening_date }}
@@ -14,17 +16,17 @@
 				</div>
 				<div class='col-xs-3'>
 					<div class='pull-right'>
-						{% if issue.todo %} 
+						{% if issue.todo %}
 						<span class="avatar avatar-small" title="{{ issue.todo.owner }}"> <img src="{{ 				issue.todo.user_image }}"></span>
 						{% else %}
 						<span class="avatar avatar-small avatar-empty"></span>
 						{% endif %}
 					</div>
 					<div class='pull-right' style='padding-right:10px;'>
-						{% if issue.status != "Closed" %} 
+						{% if issue.status != "Closed" %}
 						<span class="text-extra-muted "> <i class="octicon octicon-x issue-x" title="Close" id = "{{issue.name}}"></i> 				</span>
 						{% endif %}
-					</div>	    
+					</div>
 				</div>
 			</div>
 		</div>
diff --git a/erpnext/templates/includes/projects/project_tasks.html b/erpnext/templates/includes/projects/project_tasks.html
index b2be27b..a951712 100644
--- a/erpnext/templates/includes/projects/project_tasks.html
+++ b/erpnext/templates/includes/projects/project_tasks.html
@@ -1,8 +1,10 @@
+{%- from "templates/includes/projects/macros.html" import back_link -%}
+
 {% for task in doc.tasks %}
 	<div class='task'>
 		<div class='row project-item'>
 			<div class='col-xs-9'>
-				<a class="no-decoration" href="/tasks-view?name={{ task.name}}">
+				<a class="no-decoration" href="/tasks?name={{ task.name }}{{ back_link(doc) }}">
 					<span class="indicator {{ "orange" if task.status=="Open" else "green" }}">
 						{% if task.status == "Closed" %}
 						{{ task.subject }} completed on {{ task.closing_date }}
diff --git a/erpnext/templates/includes/projects/project_timelogs.html b/erpnext/templates/includes/projects/project_timelogs.html
index 4934032..7b5913b 100644
--- a/erpnext/templates/includes/projects/project_timelogs.html
+++ b/erpnext/templates/includes/projects/project_timelogs.html
@@ -1,12 +1,14 @@
+{%- from "templates/includes/projects/macros.html" import back_link -%}
+
 {% for timelog in doc.timelogs %}
 <div class='timelog'>
   <div class='row project-item'>
     <div class='col-xs-9'>
       <a class="no-decoration" href="/timelog_info?timelog={{ timelog.name}}">
         <span class="indicator {{ "green" if timelog.status=="Draft" else "blue" if timelog.status=="Submitted" else 			"darkgrey"}}">
-			
+
 			{{ timelog.title }}: From {{ frappe.format_date(timelog.from_time) }} to {{ 				frappe.format_date(timelog.to_time) }}
-		
+
 </span>
       </a>
     </div>
diff --git a/erpnext/templates/pages/projects.html b/erpnext/templates/pages/projects.html
index 4ec0c55..b348674 100644
--- a/erpnext/templates/pages/projects.html
+++ b/erpnext/templates/pages/projects.html
@@ -2,13 +2,15 @@
 
 {% block title %}{{ doc.project_name }}{% endblock %}
 
+{%- from "templates/includes/projects/macros.html" import back_link -%}
+
 {% block breadcrumbs %}
-   <div class="page-breadcrumbs" data-html-block="breadcrumbs">	                    
+   <div class="page-breadcrumbs" data-html-block="breadcrumbs">
    	<ul class="breadcrumb">
    		<li>
    			<span class="icon icon-angle-left"></span>
    			<a href="/project">Projects</a>
-   		</li>	
+   		</li>
    	</ul>
    </div>
 {% endblock %}
@@ -23,7 +25,7 @@
 	<style>
 		{% include "templates/includes/projects.css" %}
 	</style>
-{% endblock %} 
+{% endblock %}
 
 
 {% block page_content %}
@@ -43,16 +45,15 @@
 		{% endif %}
 {% endif %}
 
-{% if doc.tasks %}  
+<div class='padding'></div>
+
+<h3>{{ _("Tasks") }}</h3>
+
+{% if doc.tasks %}
 	<div class='project-tasks-section'>
-		<div>
-			<a class="btn btn-xs btn-primary pull-right" 
-			href='/tasks?new=1&project={{ doc.project_name }}'>New</a>
-			<h3>{{ _("Tasks") }}</h3>
-		</div>
-		<div class="btn-group btn-toggle"> 
+		<div class="btn-group btn-toggle">
 			<button class="btn btn-link btn-open-tasks"><span class="indicator orange"></span>Open</button>
-			<button class="btn btn-link btn-closed-tasks"><span class="indicator green"></span>Closed</button>	
+			<button class="btn btn-link btn-closed-tasks"><span class="indicator green"></span>Closed</button>
 		</div>
 		<div class='project-tasks'>
 		{% include "erpnext/templates/includes/projects/project_tasks.html" %}
@@ -66,16 +67,16 @@
 	<p class="text-muted">No tasks</p>
 {% endif %}
 
+<p><a href='/tasks?new=1&project={{ doc.project_name }}{{ back_link(doc) }}'>Add a new task</a></p>
+
+<div class='padding'></div>
+<h3>{{ _("Issues") }}</h3>
+
 {% if doc.issues %}
 	<div class='project-issues-section'>
-		<div>
-			<a class="btn btn-xs btn-primary pull-right" 
-			href='/issues?new=1&project={{ doc.project_name }}'>New</a>
-			<h3>{{ _("Issues") }}</h3>
-		</div>
-		<div class="btn-group btn-toggle"> 
+		<div class="btn-group btn-toggle">
 			<button class="btn btn-link btn-open-issues"><span class="indicator red"></span>Open</button>
-			<button class="btn btn-link btn-closed-issues"><span class="indicator green"></span>Closed</button>	
+			<button class="btn btn-link btn-closed-issues"><span class="indicator green"></span>Closed</button>
 		</div>
 		<div class='project-issues'>
 		{% include "erpnext/templates/includes/projects/project_issues.html" %}
@@ -84,13 +85,18 @@
 		{% if doc.issues|length > 9 %}
 			<p><a id='more-issues' class='more-issues small underline'>{{ _("More") }}</a><p>
 		{% endif %}
-	</div>	
+	</div>
 {% else %}
 	<p class="text-muted">No Issues</p>
 {% endif %}
 
+<p>	<a href='/issues?new=1&project={{ doc.project_name }}{{ back_link(doc) }}'>Add a new issue</a></p>
+
+<div class='padding'></div>
+
+<h3>{{ _("Time Logs") }}</h3>
+
 {% if doc.timelogs %}
-	<h3>{{ _("Time Logs") }}</h3>
 	<div class='project-timelogs'>
 	{% include "erpnext/templates/includes/projects/project_timelogs.html" %}
 	</div>
diff --git a/erpnext/templates/pages/projects.py b/erpnext/templates/pages/projects.py
index 0b084b4..8cec2b7 100644
--- a/erpnext/templates/pages/projects.py
+++ b/erpnext/templates/pages/projects.py
@@ -3,8 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-
-from frappe import _
+import json
 
 def get_context(context):
 	context.no_cache = 1
@@ -17,46 +16,52 @@
 	fields=['subject', 'opening_date', 'resolution_date', 'status', 'name', 'resolution_details','modified','modified_by'])
 
 	project.tasks = get_tasks(project.name, start=0, search=frappe.form_dict.get("q"))
-	
+
 	project.timelogs = get_timelogs(project.name, start=0, search=frappe.form_dict.get("q"))
-	
+
 	project.issues = get_issues(project.name, start=0, search=frappe.form_dict.get("q"))
-	
+
 	project.timelines = get_timeline(project.project_name, start=0)
-	
-	
+
+
 
 	context.doc = project
-	
-	
+
+
 def get_timeline(project, start=10):
-	issue_names = '({0})'.format(", ".join(["'{0}'".format(i.name) for i in get_issues(project)]))
-	
-	
+	'''Get timeline from project, tasks, issues'''
+	issues_condition = ''
+	project_issues = get_issues(project)
+
+	if project_issues:
+		issue_names = '({0})'.format(", ".join(["'{0}'".format(i.name) for i in project_issues]))
+		issues_condition = """or (reference_doctype='Issue' and reference_name IN {issue_names})""".format(issue_names=issue_names)
+
+
 	timelines = frappe.db.sql("""
-		select 
-			sender_full_name, 
-			subject, communication_date, comment_type, name, creation, modified_by, reference_doctype, reference_name, 
-			_liked_by, comment_type, _comments 
-		from 
-			tabCommunication 
-		where 
+		select
+			sender_full_name,
+			subject, communication_date, comment_type, name, creation, modified_by, reference_doctype, reference_name,
+			_liked_by, comment_type, _comments
+		from
+			tabCommunication
+		where
 			(reference_doctype='Project' and reference_name=%s)
 			or (timeline_doctype='Project' and timeline_name=%s)
-			or (reference_doctype='Issue' and reference_name IN {issue_names})
-		order by 
+			{issues_condition}
+		order by
 			modified DESC limit {start}, {limit}""".format(
-			issue_names=issue_names, start=start, limit=10), 
+			issues_condition=issues_condition, start=start, limit=10),
 			(project, project), as_dict=True);
 	for timeline in timelines:
  		timeline.user_image = frappe.db.get_value('User', timeline.modified_by, 'user_image')
-	return timelines	
-		
+	return timelines
+
 @frappe.whitelist()
 def get_timelines_html(project, start=0):
-	return frappe.render_template("erpnext/templates/includes/projects/timeline.html", 
-		{"doc": {"timelines": get_timeline(project, start)}}, is_path=True)			
-		
+	return frappe.render_template("erpnext/templates/includes/projects/timeline.html",
+		{"doc": {"timelines": get_timeline(project, start)}}, is_path=True)
+
 def get_issue_list(project):
 	return [issue.name for issue in get_issues(project)]
 
@@ -64,12 +69,12 @@
 	filters = {"project": project}
 	if search:
 		filters["subject"] = ("like", "%{0}%".format(search))
-	if item_status:	
-		filters = {"status": item_status}	
-	tasks = frappe.get_all("Task", filters=filters, 
-		fields=["name", "subject", "status", "exp_start_date", "exp_end_date", "priority"], 
-		limit_start=start, limit_page_length=10)	
-		
+	if item_status:
+		filters = {"status": item_status}
+	tasks = frappe.get_all("Task", filters=filters,
+		fields=["name", "subject", "status", "exp_start_date", "exp_end_date", "priority"],
+		limit_start=start, limit_page_length=10)
+
 	for task in tasks:
 		print task._comments
 		task.todo = frappe.get_all('ToDo',filters={'reference_name':task.name, 'reference_type':'Task'},
@@ -78,67 +83,66 @@
 			task.todo=task.todo[0]
 			task.todo.user_image = frappe.db.get_value('User', task.todo.owner, 'user_image')
 		if task._comments:
-			task.comment_count = len(json.loads(_comments or "[]"))				
+			task.comment_count = len(json.loads(task._comments or "[]"))
 	return tasks
 
 @frappe.whitelist()
 def get_tasks_html(project, start=0, item_status=None):
-	return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html", 
+	return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
 		{"doc": {"tasks": get_tasks(project, start, item_status=item_status)}}, is_path=True)
-		
-		
+
+
 def get_issues(project, start=0, search=None, item_status=None):
 	filters = {"project": project}
 	if search:
 		filters["subject"] = ("like", "%{0}%".format(search))
-	if item_status:	
-		filters = {"status": item_status}	
-	issues = frappe.get_all("Issue", filters=filters, 
-		fields=["name", "subject", "status", "opening_date", "resolution_date", "resolution_details"], 
+	if item_status:
+		filters = {"status": item_status}
+	issues = frappe.get_all("Issue", filters=filters,
+		fields=["name", "subject", "status", "opening_date", "resolution_date", "resolution_details"],
 		order_by='modified desc',
-		limit_start=start, limit_page_length=10)	
-		
+		limit_start=start, limit_page_length=10)
+
 	for issue in issues:
 		issue.todo = frappe.get_all('ToDo',filters={'reference_name':issue.name, 'reference_type':'Issue'},
 		fields=["assigned_by", "owner", "modified", "modified_by"])
 		if issue.todo:
 			issue.todo=issue.todo[0]
 			issue.todo.user_image = frappe.db.get_value('User', issue.todo.owner, 'user_image')
-			
+
 	return issues
 
 @frappe.whitelist()
 def get_issues_html(project, start=0, item_status=None):
-	return frappe.render_template("erpnext/templates/includes/projects/project_issues.html", 
-		{"doc": {"issues": get_issues(project, start, item_status=item_status)}}, is_path=True)		
-		
+	return frappe.render_template("erpnext/templates/includes/projects/project_issues.html",
+		{"doc": {"issues": get_issues(project, start, item_status=item_status)}}, is_path=True)
+
 def get_timelogs(project, start=0, search=None):
 	filters = {"project": project}
 	if search:
 		filters["title"] = ("like", "%{0}%".format(search))
-	
-	timelogs = frappe.get_all('Time Log', filters=filters, 
+
+	timelogs = frappe.get_all('Time Log', filters=filters,
 	fields=['name','title','task','activity_type','from_time','to_time','hours','status','modified','modified_by'],
-	limit_start=start, limit_page_length=10)	
+	limit_start=start, limit_page_length=10)
 	for timelog in timelogs:
-		timelog.user_image = frappe.db.get_value('User', timelog.modified_by, 'user_image')	
+		timelog.user_image = frappe.db.get_value('User', timelog.modified_by, 'user_image')
 	return timelogs
 
 @frappe.whitelist()
 def get_timelogs_html(project, start=0):
-	return frappe.render_template("erpnext/templates/includes/projects/project_timelogs.html", 
-		{"doc": {"timelogs": get_timelogs(project, start)}}, is_path=True)		
-		
-@frappe.whitelist()	
+	return frappe.render_template("erpnext/templates/includes/projects/project_timelogs.html",
+		{"doc": {"timelogs": get_timelogs(project, start)}}, is_path=True)
+
+@frappe.whitelist()
 def set_task_status(project, item_name):
 	task = frappe.get_doc("Task", item_name)
 	task.status = 'Closed'
 	task.save(ignore_permissions=True)
-		
-@frappe.whitelist()			
+
+@frappe.whitelist()
 def set_issue_status(project, item_name):
 	issue = frappe.get_doc("Issue", item_name)
 	issue.status = 'Closed'
 	issue.save(ignore_permissions=True)
-			
-					
\ No newline at end of file
+