From 6b7dc3fe182cb4eb073be549354d5e2268a423c2 Mon Sep 17 00:00:00 2001 From: nikhila05 Date: Tue, 10 Sep 2019 11:17:05 +0530 Subject: [PATCH] added duplicate contacts tabs, fixed time format in marketing campaign list page, added test cases in marketing, added contacts list filter in contacts page (#284) * updated testcases, update code for account view page, modified code for attachments and comments for assigned user * updated testcases in events, invoices, tasks modules * added duplicate contacts tabs, fixed time format in marketing campaign list page, added test cases in marketing, added contacts list filter in contacts page --- .coveragerc | 28 + .gitlab-ci.yml | 4 +- .travis.yml | 4 +- accounts/templates/accounts.html | 16 +- accounts/tests_celery_tasks.py | 34 + cases/templates/cases.html | 8 +- cases/tests_celery_tasks.py | 16 + common/templates/create.html | 17 +- common/templates/doc_list_1.html | 8 +- common/templates/list.html | 20 +- common/templates/settings/list.html | 386 +++++- common/templates/user_detail.html | 268 ++-- common/tests.py | 2 +- common/tests_celery_tasks.py | 223 ++++ common/views.py | 145 +- contacts/templates/contacts.html | 6 +- contacts/tests_celery_tasks.py | 18 + .../assigned_to_email_template_event.html | 4 +- events/templates/events_list.html | 6 +- events/tests_celery_tasks.py | 15 + .../templates/assigned_to_email_template.html | 2 +- invoices/templates/invoice_cancelled.html | 4 +- invoices/templates/invoice_detail_email.html | 4 +- invoices/templates/invoices_list.html | 20 +- invoices/tests.py | 1 + invoices/tests_celery_tasks.py | 22 + leads/tasks.py | 6 +- leads/templates/leads.html | 14 +- leads/tests.py | 3 +- leads/tests_celery_tasks.py | 50 + leads/views.py | 34 +- marketing/forms.py | 100 +- .../migrations/0011_auto_20190904_1143.py | 26 + marketing/models.py | 89 +- marketing/tasks.py | 16 +- .../templates/add_email_for_campaign.html | 4 +- marketing/templatetags/digg_paginator.py | 2 +- marketing/tests.py | 1170 ++++++++++++++++- marketing/tests_celery_tasks.py | 66 + marketing/urls.py | 26 +- marketing/views.py | 495 +++---- opportunity/tasks.py | 1 + opportunity/templates/opportunity.html | 6 +- opportunity/tests_celery_tasks.py | 16 + requirements.txt | 71 +- requirements_with_no_dependencies.txt | 22 +- tasks/templates/task_create.html | 5 +- tasks/templates/tasks_tasks_list.html | 18 +- tasks/tests_celery_tasks.py | 15 + teams/templates/teams.html | 6 +- templates/assigned_to/account_assigned.html | 2 +- templates/assigned_to/cases_assigned.html | 2 +- templates/assigned_to/contact_assigned.html | 2 +- templates/assigned_to/leads_assigned.html | 16 +- .../assigned_to/opportunity_assigned.html | 2 +- templates/marketing/campaign/index.html | 7 +- templates/marketing/email_template/index.html | 6 +- templates/marketing/lists/all.html | 22 +- templates/marketing/lists/detail.html | 183 ++- templates/marketing/lists/index.html | 18 +- templates/profile.html | 12 + templates/root_email_template_new.html | 2 +- 62 files changed, 3070 insertions(+), 746 deletions(-) create mode 100644 .coveragerc create mode 100644 accounts/tests_celery_tasks.py create mode 100644 cases/tests_celery_tasks.py create mode 100644 common/tests_celery_tasks.py create mode 100644 contacts/tests_celery_tasks.py create mode 100644 events/tests_celery_tasks.py create mode 100644 invoices/tests_celery_tasks.py create mode 100644 leads/tests_celery_tasks.py create mode 100644 marketing/migrations/0011_auto_20190904_1143.py create mode 100644 marketing/tests_celery_tasks.py create mode 100644 opportunity/tests_celery_tasks.py create mode 100644 tasks/tests_celery_tasks.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..9d3635f4 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,28 @@ +[report] +exclude_lines = + # lines with this comment are not hit + pragma: no cover + + # Don't complain about missing debug-only code: + def __unicode__ + def __repr__ + def __str__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + + except Exception as e: + except Exception: + +omit = + *tests* + ./settings/* + ./*/migrations/* + ./*/apps.py + ./*/admin.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27f57205..c3ccb780 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,8 +4,8 @@ Python 3.5.2: - virtualenv -p python3 env - source env/bin/activate - pip install --no-cache-dir -r requirements.txt - - python manage.py test --noinput - - coverage run --source=accounts,cases,common,contacts,emails,leads,opportunity,planner,tasks,invoices,events,teams manage.py test --noinput + - python manage.py test --keepdb --noinput + - coverage run --source=accounts,cases,common,contacts,leads,opportunity,tasks,invoices,events,teams,marketing manage.py test --keepdb --noinput - coverage report -m except: - tags diff --git a/.travis.yml b/.travis.yml index 417a62d2..cb9f0654 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,8 @@ install: # command to run tests script: - - python manage.py test - - coverage run --source=accounts,common manage.py test accounts common + - python manage.py test --keepdb + - coverage run --source=accounts,cases,common,contacts,leads,opportunity,tasks,invoices,events,teams,marketing manage.py test --keepdb --noinput - coverage xml - pytest - python-codacy-coverage -r coverage.xml diff --git a/accounts/templates/accounts.html b/accounts/templates/accounts.html index 91355797..4b9d5fe5 100644 --- a/accounts/templates/accounts.html +++ b/accounts/templates/accounts.html @@ -173,16 +173,16 @@ {% if each_account.contacts.all %} + data-toggle="modal" data-target="#send_email_to_contacts" title="Send Mail"> {% endif %} - - + class="btn btn-danger delete remove_account" title="Delete"> {% endfor %} @@ -269,12 +269,12 @@ {% endwith %} - - + class="btn btn-danger delete remove_account" title="Delete" > {% endfor %} diff --git a/accounts/tests_celery_tasks.py b/accounts/tests_celery_tasks.py new file mode 100644 index 00000000..a92c9c4b --- /dev/null +++ b/accounts/tests_celery_tasks.py @@ -0,0 +1,34 @@ +from datetime import datetime, timedelta + +from django.test import TestCase +from django.test.utils import override_settings + +from accounts.models import Email +from accounts.tasks import (send_email, send_email_to_assigned_user, + send_scheduled_emails) +from accounts.tests import AccountCreateTest + + +class TestCeleryTasks(AccountCreateTest, TestCase): + + @override_settings(CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, + CELERY_ALWAYS_EAGER=True, + BROKER_BACKEND='memory') + def test_celery_tasks(self): + email_scheduled = Email.objects.create( + message_subject='message subject', message_body='message body', + scheduled_later=True, timezone='Asia/Kolkata', + from_account=self.account, + scheduled_date_time=(datetime.now() - timedelta(minutes=5)), + from_email='from@email.com' + ) + email_scheduled.recipients.add(self.contact.id, self.contact_user1.id) + task = send_scheduled_emails.apply() + self.assertEqual('SUCCESS', task.state) + + task = send_email.apply((email_scheduled.id,)) + self.assertEqual('SUCCESS', task.state) + + task = send_email_to_assigned_user.apply( + ([self.user.id, self.user1.id, ], self.account.id,),) + self.assertEqual('SUCCESS', task.state) diff --git a/cases/templates/cases.html b/cases/templates/cases.html index 9e89eecc..cc80882b 100644 --- a/cases/templates/cases.html +++ b/cases/templates/cases.html @@ -137,15 +137,15 @@ {{ case.priority }} {{ case.created_on_arrow }} - - {% if request.user == case.created_by or request.user.role == "ADMIN" or request.user.is_superuser %} - {% if case.status != 'Closed' %} - {% endif %} {% endif %} diff --git a/cases/tests_celery_tasks.py b/cases/tests_celery_tasks.py new file mode 100644 index 00000000..934a898c --- /dev/null +++ b/cases/tests_celery_tasks.py @@ -0,0 +1,16 @@ +from django.test import TestCase +from django.test.utils import override_settings + +from cases.tasks import send_email_to_assigned_user +from cases.tests import CaseCreation + + +class TestCeleryTasks(CaseCreation, TestCase): + + @override_settings(CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, + CELERY_ALWAYS_EAGER=True, + BROKER_BACKEND='memory') + def test_celery_tasks(self): + task = send_email_to_assigned_user.apply( + ([self.user.id, self.user1.id, ], self.case.id,),) + self.assertEqual('SUCCESS', task.state) diff --git a/common/templates/create.html b/common/templates/create.html index 8161fdeb..8c31f68a 100644 --- a/common/templates/create.html +++ b/common/templates/create.html @@ -151,10 +151,23 @@

+ {% comment %} + {% if request.user.role == 'ADMIN' or request.user.is_superuser %} + {% if request.user.id|slugify in request.path %} +

true

+ {% endif %} + {% endif %} + {% endcomment %}
- Cancel + Cancel
diff --git a/common/templates/doc_list_1.html b/common/templates/doc_list_1.html index 83af8e72..00f587c8 100644 --- a/common/templates/doc_list_1.html +++ b/common/templates/doc_list_1.html @@ -232,15 +232,15 @@
{% if request.user == document.created_by or request.user.role == 'ADMIN' %} - - - {% endif %} {% if request.user in document.shared_to.all or request.user == document.created_by or request.user.role == 'ADMIN' %} - {% endif %}
diff --git a/common/templates/list.html b/common/templates/list.html index 85063da9..756f20e1 100644 --- a/common/templates/list.html +++ b/common/templates/list.html @@ -75,6 +75,19 @@ +
+
+ + +
+
@@ -184,7 +197,7 @@ class="fas fa-trash-alt">Delete {% if user.email != admin_email and request.user != user %} {% endif %} @@ -264,7 +277,7 @@ class="fas fa-trash-alt">Delete {% if user.email != admin_email and request.user != user %} {% endif %} @@ -296,6 +309,9 @@ $(".filter_toggle").click(function () { $(".list_filter_row").toggle(); }); + if ($('#id_user_status').val() === 'False') { + $('#close-tab').click() + } }); $('.trash').click(function (e) { diff --git a/common/templates/settings/list.html b/common/templates/settings/list.html index f00a8a10..fbd0c9f6 100644 --- a/common/templates/settings/list.html +++ b/common/templates/settings/list.html @@ -1,90 +1,354 @@ {% extends 'sales/base.html' %} {% load staticfiles %} {% load paginate %} +{% load thumbnail %} +{% block extralinks %} + +{% endblock extralinks %} {% block content %} +
- - -
+ + + +
-
- Settings - {% if show_pageitems %} {% show_pageitems %}{% else %} {{ settings|length }}{% endif %} - - - -
-
- - - {% if settings|length > 0 %} - - - - - - - - {% endif %} - - - {% if per_page %} - {% paginate per_page settings %} - {% else %} - {% paginate 10 settings %} - {% endif %} - {% for setting in settings %} - - - - - - - - {% endfor %} - -
TitleAssign ToUserActions
{{ setting.title }} - {% for user in setting.lead_assigned_to.all %} - {{user.email}}{% if forloop.counter < setting.lead_assigned_to.all|length %}, {% endif %} - {% empty %} - Not Assigned Yet! - {% endfor %} - {% if setting.created_by %}{{ setting.created_by.email }}{% else %}No user!{% endif %} - - - -
-
- {% ifequal settings|length 0 %} -
No Settings Found!
- {% endifequal %} -
- {% show_pages %} -
+
+
+
Filter Settings
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + Clear +
+
+
+
+
+ + + +
+
+
+
+
+
+
Filter Contacts
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + Clear +
+
+
+
+
+
+
+
+
+ + + + + +
+
+
+
+ +
+
+
+
+
+ Contacts - {% if show_pageitems %} + {% show_pageitems %}{% else %} + {{ contacts|length }}{% endif %} + + + +
+
+ + + {% if contacts|length > 0 %} + + + + + + + + + {% endif %} + + + {% if per_page %} + {% paginate per_page contacts %} + {% else %} + {% paginate 10 contacts %} + {% endif %} + {% for contact in contacts %} + + + + + + + + + {% endfor %} + +
ID NameEmailCreated byCreated OnActions
{{ forloop.counter }}{{ contact.name }} + {{contact.email}} + + {% if contact.created_by %} + {% if contact.created_by.profile_pic %} + {% thumbnail contact.created_by.profile_pic "40x40" crop="center" as im %} + + {% endthumbnail %} + {% else %} + + {% endif %} + {% else %} + + {% endif %} + {{ contact.created_on_arrow }} + {% if request.user.role == 'ADMIN' or reques.user.is_superuser %} + + + {% endif %} +
+
+ {%ifequal contacts|length 0%} +
No Contacts Found
+ {%endifequal%} +
+ {% show_pages %} +
+
+
+
+
+
+
+
+ Settings - {% if show_pageitems %} {% show_pageitems %}{% else %} + {{ settings|length }}{% endif %} + + + +
+
+ + + {% if settings|length > 0 %} + + + + + + + + {% endif %} + + + {% if per_page %} + {% paginate per_page settings %} + {% else %} + {% paginate 10 settings %} + {% endif %} + {% for setting in settings %} + + + + + + + + {% endfor %} + +
TitleAssign ToUserActions
{{ setting.title }} + + {% with lead_users=setting.lead_assigned_to.all %} + {% for user in lead_users %} + {% if user.profile_pic %} + {% thumbnail user.profile_pic "40x40" crop="center" as im %} + + + + {% endthumbnail %} + {% else %} + + + + {% endif %} + {% empty %} + None + {% endfor %} + {% endwith %} + {% if setting.created_by %}{{ setting.created_by.email }}{% else %}No user!{% endif %} + + + + +
+
+ {% ifequal settings|length 0 %} +
No Settings Found!
+ {% endifequal %} +
+ {% show_pages %} +
+
+
+
+
+
+
+
+
+
+
{% endblock %} {% block js_block %} -{% endblock js_block %} + $('.assigned_users').select2(); + $(".list_filter_row_contacts").hide() + $(".filter_toggle").click(function () { + $(".list_filter_row").toggle(); + $(".list_filter_row_contacts").hide(); + }); + $(".filter_toggle_contacts").click(function () { + $(".list_filter_row_contacts").toggle(); + $(".list_filter_row").hide(); + }); + + $("#close a[rel='page']").click(function (e) { + e.preventDefault(); + $('#settings_filter').attr("action", $(this).attr("href")); + $('#settings_filter').submit(); + }); + + $("#open a[rel='page']").click(function (e) { + e.preventDefault(); + $('#contacts_filter').attr("action", $(this).attr("href")); + $('#contacts_filter').submit(); + }); + +{% endblock js_block %} \ No newline at end of file diff --git a/common/templates/user_detail.html b/common/templates/user_detail.html index 5da42dd9..103775fd 100644 --- a/common/templates/user_detail.html +++ b/common/templates/user_detail.html @@ -4,7 +4,7 @@ {% load thumbnail %} @@ -18,14 +18,14 @@
-
+
Overview @@ -35,7 +35,7 @@
{% if user_obj.first_name %}
-
+
@@ -69,7 +69,7 @@
- +
{% endif %} @@ -89,6 +89,18 @@
+ {% with teams=user_obj.user_teams.all %} + {% if teams %} +
+
+ + {% for team in teams %} + + {% endfor %} +
+
+ {% endif %} + {% endwith %}
@@ -106,11 +118,13 @@
- +

- +
@@ -120,10 +134,12 @@
  • {% if request.user.is_superuser or request.user.role == 'ADMIN' or request.user == comment.commented_by %}
    - +
  • -
    + {% with teams=user_obj.user_teams.all %} + {% if teams %} +
    +
    + + {% for team in teams %} + + {% endfor %} +
    +
    + {% endif %} + {% endwith %}
    diff --git a/templates/root_email_template_new.html b/templates/root_email_template_new.html index e6d6e6e1..1880615e 100644 --- a/templates/root_email_template_new.html +++ b/templates/root_email_template_new.html @@ -40,7 +40,7 @@ - + {% block content_body %}