From 31a5340aa329081be2dcef93b2cc9aa27c523938 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Sat, 22 Feb 2020 17:51:06 +0530 Subject: [PATCH 1/2] added docs --- accounts/forms.py | 2 +- accounts/templates/create_account.html | 197 ++- accounts/tests.py | 8 +- accounts/urls.py | 5 +- accounts/views.py | 12 + cases/templates/create_cases.html | 192 ++- cases/urls.py | 4 +- cases/views.py | 11 + common/templates/doc_create.html | 191 ++- common/templates/doc_list.html | 2 +- common/templates/doc_list_1.html | 8 +- common/templates/list.html | 33 +- common/templates/settings/list.html | 42 +- common/templatetags/common_tags.py | 21 + common/urls.py | 4 +- common/views.py | 46 +- contacts/forms.py | 2 +- contacts/templates/contacts.html | 6 +- contacts/templates/create_contact.html | 192 ++- contacts/urls.py | 3 +- contacts/views.py | 16 +- crm/settings.py | 67 +- docs/Makefile | 183 ++- docs/__init__.py | 0 docs/make.bat | 35 - docs/source/Accounts.rst | 39 + docs/source/Cases.rst | 20 + docs/source/Change Password.rst | 11 + docs/source/Contacts.rst | 23 + docs/source/Documents.rst | 18 + docs/source/Forget Password.rst | 43 + docs/source/Leads.rst | 18 + docs/source/Login.rst | 6 + docs/source/Opportunity.rst | 23 + docs/source/Profile.rst | 88 ++ docs/source/apps/crm/accounts.rst | 9 - docs/source/apps/crm/cases.rst | 10 - docs/source/apps/crm/contacts.rst | 9 - docs/source/apps/crm/dashboard.rst | 11 - docs/source/apps/crm/documents.rst | 9 - docs/source/apps/crm/events.rst | 12 - docs/source/apps/crm/invoices.rst | 15 - docs/source/apps/crm/leads.rst | 14 - docs/source/apps/crm/opportunity.rst | 10 - docs/source/apps/crm/tasks.rst | 7 - docs/source/apps/crm/teams.rst | 9 - .../source/apps/internals/change_password.rst | 6 - .../source/apps/internals/forgot_password.rst | 5 - docs/source/apps/internals/profile.rst | 5 - docs/source/apps/internals/settings.rst | 7 - docs/source/apps/internals/users.rst | 7 - docs/source/apps/marketing/campaign.rst | 12 - docs/source/apps/marketing/contact-list.rst | 9 - docs/source/apps/marketing/contacts.rst | 8 - docs/source/apps/marketing/dashboard.rst | 9 - .../source/apps/marketing/email-templates.rst | 7 - docs/source/conf.py | 257 +++- docs/source/index.rst | 112 +- .../screenshots/accountcreate.png | Bin .../screenshots/accountshome.png | Bin .../screenshots/accountshome1.png | Bin .../{_static => }/screenshots/casescreate.png | Bin .../{_static => }/screenshots/caseshome.png | Bin .../{_static => }/screenshots/caseshome1.png | Bin .../screenshots/changepassword.png | Bin .../screenshots/contactscreate.png | Bin .../screenshots/contactshome.png | Bin .../screenshots/contactshome1.png | Bin .../screenshots/createsettings.png | Bin .../{_static => }/screenshots/createuser.png | Bin .../screenshots/documentscreate.png | Bin .../screenshots/documentshome.png | Bin .../screenshots/documentshome1.png | Bin .../{_static => }/screenshots/dropdown.png | Bin .../{_static => }/screenshots/editprofile.png | Bin .../{_static => }/screenshots/edituser.png | Bin .../{_static => }/screenshots/email.png | Bin .../screenshots/forgetpasswordpage.png | Bin .../{_static => }/screenshots/homepage.png | Bin .../{_static => }/screenshots/leadscreate.png | Bin .../{_static => }/screenshots/leadshome.png | Bin .../{_static => }/screenshots/leadshome1.png | Bin .../{_static => }/screenshots/login.png | Bin .../{_static => }/screenshots/mailsent.png | Bin .../screenshots/opportunitycreate.png | Bin .../screenshots/opportunityhome.png | Bin .../screenshots/opportunityhome1.png | Bin .../{_static => }/screenshots/profilehome.png | Bin .../screenshots/resetpassword.png | Bin .../screenshots/resetsuccessful.png | Bin .../screenshots/settingshome.png | Bin .../{_static => }/screenshots/usershome.png | Bin docs/source/setup/index.rst | 169 --- docs/source/setup/packages_used.rst | 58 - docs/source/setup/ubuntu-18.04-dev.rst | 4 - docs/source/setup/ubuntu-18.04-server.rst | 4 - events/templates/event_create.html | 203 ++- events/templates/events_list.html | 6 +- events/urls.py | 1 + events/views.py | 58 +- invoices/forms.py | 2 +- invoices/templates/invoice_create_1.html | 184 ++- invoices/templates/invoices_list.html | 4 +- invoices/urls.py | 1 + invoices/views.py | 21 +- leads/forms.py | 20 +- leads/models.py | 2 +- leads/tasks.py | 35 +- leads/templates/create_lead.html | 3 +- leads/templates/leads.html | 28 +- leads/templates/view_leads.html | 19 +- leads/tests.py | 10 +- leads/views.py | 24 +- marketing/forms.py | 38 +- marketing/search_backends.py | 20 + marketing/search_indexes.py | 10 +- marketing/tasks.py | 2 +- marketing/templates/add_blocked_domain.html | 4 +- marketing/templates/add_blocked_email.html | 4 +- .../templates/add_email_for_campaign.html | 4 +- .../templates/search_contact_emails.html | 13 +- marketing/tests.py | 22 +- marketing/urls.py | 2 +- marketing/views.py | 91 +- opportunity/templates/create_opportunity.html | 191 ++- opportunity/urls.py | 4 +- opportunity/views.py | 57 +- requirements.txt | 4 +- static/css/main.scss | 1083 +++++++++-------- tasks/templates/task_create.html | 192 ++- tasks/templates/task_detail.html | 4 +- tasks/templates/tasks_tasks_list.html | 25 +- tasks/tests.py | 2 +- tasks/views.py | 75 +- teams/tasks.py | 67 +- teams/templates/teams.html | 4 +- teams/views.py | 15 +- templates/marketing/campaign/index.html | 10 +- templates/marketing/email_template/index.html | 7 + templates/marketing/lists/index.html | 18 + 140 files changed, 3371 insertions(+), 1583 deletions(-) create mode 100644 docs/__init__.py delete mode 100644 docs/make.bat create mode 100644 docs/source/Accounts.rst create mode 100644 docs/source/Cases.rst create mode 100644 docs/source/Change Password.rst create mode 100644 docs/source/Contacts.rst create mode 100644 docs/source/Documents.rst create mode 100644 docs/source/Forget Password.rst create mode 100644 docs/source/Leads.rst create mode 100644 docs/source/Login.rst create mode 100644 docs/source/Opportunity.rst create mode 100644 docs/source/Profile.rst delete mode 100644 docs/source/apps/crm/accounts.rst delete mode 100644 docs/source/apps/crm/cases.rst delete mode 100644 docs/source/apps/crm/contacts.rst delete mode 100644 docs/source/apps/crm/dashboard.rst delete mode 100644 docs/source/apps/crm/documents.rst delete mode 100644 docs/source/apps/crm/events.rst delete mode 100644 docs/source/apps/crm/invoices.rst delete mode 100644 docs/source/apps/crm/leads.rst delete mode 100644 docs/source/apps/crm/opportunity.rst delete mode 100644 docs/source/apps/crm/tasks.rst delete mode 100644 docs/source/apps/crm/teams.rst delete mode 100644 docs/source/apps/internals/change_password.rst delete mode 100644 docs/source/apps/internals/forgot_password.rst delete mode 100644 docs/source/apps/internals/profile.rst delete mode 100644 docs/source/apps/internals/settings.rst delete mode 100644 docs/source/apps/internals/users.rst delete mode 100644 docs/source/apps/marketing/campaign.rst delete mode 100644 docs/source/apps/marketing/contact-list.rst delete mode 100644 docs/source/apps/marketing/contacts.rst delete mode 100644 docs/source/apps/marketing/dashboard.rst delete mode 100644 docs/source/apps/marketing/email-templates.rst rename docs/source/{_static => }/screenshots/accountcreate.png (100%) rename docs/source/{_static => }/screenshots/accountshome.png (100%) rename docs/source/{_static => }/screenshots/accountshome1.png (100%) rename docs/source/{_static => }/screenshots/casescreate.png (100%) rename docs/source/{_static => }/screenshots/caseshome.png (100%) rename docs/source/{_static => }/screenshots/caseshome1.png (100%) rename docs/source/{_static => }/screenshots/changepassword.png (100%) rename docs/source/{_static => }/screenshots/contactscreate.png (100%) rename docs/source/{_static => }/screenshots/contactshome.png (100%) rename docs/source/{_static => }/screenshots/contactshome1.png (100%) rename docs/source/{_static => }/screenshots/createsettings.png (100%) rename docs/source/{_static => }/screenshots/createuser.png (100%) rename docs/source/{_static => }/screenshots/documentscreate.png (100%) rename docs/source/{_static => }/screenshots/documentshome.png (100%) rename docs/source/{_static => }/screenshots/documentshome1.png (100%) rename docs/source/{_static => }/screenshots/dropdown.png (100%) rename docs/source/{_static => }/screenshots/editprofile.png (100%) rename docs/source/{_static => }/screenshots/edituser.png (100%) rename docs/source/{_static => }/screenshots/email.png (100%) rename docs/source/{_static => }/screenshots/forgetpasswordpage.png (100%) rename docs/source/{_static => }/screenshots/homepage.png (100%) rename docs/source/{_static => }/screenshots/leadscreate.png (100%) rename docs/source/{_static => }/screenshots/leadshome.png (100%) rename docs/source/{_static => }/screenshots/leadshome1.png (100%) rename docs/source/{_static => }/screenshots/login.png (100%) rename docs/source/{_static => }/screenshots/mailsent.png (100%) rename docs/source/{_static => }/screenshots/opportunitycreate.png (100%) rename docs/source/{_static => }/screenshots/opportunityhome.png (100%) rename docs/source/{_static => }/screenshots/opportunityhome1.png (100%) rename docs/source/{_static => }/screenshots/profilehome.png (100%) rename docs/source/{_static => }/screenshots/resetpassword.png (100%) rename docs/source/{_static => }/screenshots/resetsuccessful.png (100%) rename docs/source/{_static => }/screenshots/settingshome.png (100%) rename docs/source/{_static => }/screenshots/usershome.png (100%) delete mode 100644 docs/source/setup/index.rst delete mode 100644 docs/source/setup/packages_used.rst delete mode 100644 docs/source/setup/ubuntu-18.04-dev.rst delete mode 100644 docs/source/setup/ubuntu-18.04-server.rst create mode 100644 marketing/search_backends.py diff --git a/accounts/forms.py b/accounts/forms.py index dafcb2e6..dc1c026f 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -23,7 +23,7 @@ class AccountForm(forms.ModelForm): self.fields['status'].required = False for key, value in self.fields.items(): if key == 'phone': - value.widget.attrs['placeholder'] = "+91-123-456-7890" + value.widget.attrs['placeholder'] = "+911234567890" else: value.widget.attrs['placeholder'] = value.label diff --git a/accounts/templates/create_account.html b/accounts/templates/create_account.html index ae0dc14d..c8bc4ce3 100644 --- a/accounts/templates/create_account.html +++ b/accounts/templates/create_account.html @@ -15,7 +15,7 @@ {% endblock %} {% block content %} -{% if contact_count %} +{% if contact_count or edit_view%}
@@ -187,14 +187,14 @@ - {{ account_form.assigned_to.errors }} + {{ account_form.assigned_to.errors }} {% endblock %} {% block js_block %} + + + + -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/common/templates/settings/list.html b/common/templates/settings/list.html index be73dfdb..a537d708 100644 --- a/common/templates/settings/list.html +++ b/common/templates/settings/list.html @@ -276,11 +276,11 @@ {{ contact.created_on_arrow }} - {% if request.user.role == 'ADMIN' or reques.user.is_superuser %} + {% if request.user.role == 'ADMIN' or request.user.is_superuser %} {% endif %} @@ -353,11 +353,11 @@ {{ domain.created_on_arrow }} - {% if request.user.role == 'ADMIN' or reques.user.is_superuser %} + {% if request.user.role == 'ADMIN' or request.user.is_superuser %} {% endif %} @@ -431,11 +431,11 @@ {{ email.created_on_arrow }} - {% if request.user.role == 'ADMIN' or reques.user.is_superuser %} + {% if request.user.role == 'ADMIN' or request.user.is_superuser %} {% endif %} @@ -468,6 +468,8 @@ -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/common/templatetags/common_tags.py b/common/templatetags/common_tags.py index 61761671..87c4585b 100644 --- a/common/templatetags/common_tags.py +++ b/common/templatetags/common_tags.py @@ -7,20 +7,24 @@ def is_document_file_image(ext): 'tga', 'thm', 'tif', 'tiff', 'yuv'] return ext.lower() in image_ext_list + def is_document_file_audio(ext): audio_ext_list = ['aif', 'iff', 'm3u', 'm4a', 'mid', 'mp3', 'mpa', 'wav', 'wma'] return ext.lower() in audio_ext_list + def is_document_file_video(ext): video_ext_list = ['3g2', '3gp', 'asf', 'avi', 'flv', 'm4v', 'mov', 'mp4', 'mpg', 'rm', 'srt', 'swf', 'vob', 'wmv'] return ext.lower() in video_ext_list + def is_document_file_pdf(ext): pdf_ext_list = ['indd', 'pct', 'pdf'] return ext.lower() in pdf_ext_list + def is_document_file_code(ext): code_ext_list = ['aspx', 'json', 'jsp', 'do', 'htm', 'html', 'ser', 'php', 'jad', 'cfm', 'xml', 'js', 'pod', 'asp', @@ -96,16 +100,19 @@ def is_document_file_code(ext): 'drc', 'appxsym'] return ext.lower() in code_ext_list + def is_document_file_text(ext): text_ext_list = ['doc', 'docx', 'log', 'msg', 'odt', 'pages', 'rtf', 'tex', 'txt', 'wpd', 'wps'] return ext.lower() in text_ext_list + def is_document_file_sheet(ext): sheet_ext_list = ['csv', 'xls', 'xlsx', 'xlsm', 'xlsb', 'xltx', 'xltm', 'xlt'] return ext.lower() in sheet_ext_list + def is_document_file_zip(ext): ext_list = ['zip', '7Z', 'gz', 'rar', 'ZIPX', 'ACE', 'tar', ] return ext.lower() in ext_list @@ -114,3 +121,17 @@ def is_document_file_zip(ext): @register.filter def subtract(value, arg): return value - int(arg) + + +@register.filter +def delete_condition(user, task): + if user == task.created_by or user.role == 'ADMIN': + return True + return False + + +@register.filter +def view_edit_condition(user, task): + if user == task.created_by or user.role == 'ADMIN' or user.has_sales_access or user in task.assigned_to.all: + return True + return False diff --git a/common/urls.py b/common/urls.py index bee310dd..4af4f84d 100644 --- a/common/urls.py +++ b/common/urls.py @@ -7,7 +7,7 @@ from common.views import ( UsersListView, CreateUserView, UpdateUserView, UserDetailView, UserDeleteView, PasswordResetView, DocumentListView, document_create, document_update, - DocumentDetailView, DocumentDeleteView, + DocumentDetailView, DocumentDeleteView,get_teams_and_users, download_document, change_user_status, download_attachment, add_comment, edit_comment, remove_comment, api_settings, add_api_settings, view_api_settings, @@ -93,6 +93,8 @@ urlpatterns = [ # user activate link path('activate-user////', activate_user, name='activate_user'), path('resend_activation_link//', resend_activation_link, name='resend_activation_link'), + path('get_teams_and_users/', get_teams_and_users, name="get_teams_and_users") + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/common/views.py b/common/views.py index 63e96d97..709c0fd6 100644 --- a/common/views.py +++ b/common/views.py @@ -1,7 +1,7 @@ import datetime import json import os - +import phonenumbers import boto3 import botocore import requests @@ -40,12 +40,12 @@ from common.models import (APISettings, Attachments, Comment, Document, Google, from common.tasks import (resend_activation_link_to_user, send_email_to_new_user, send_email_user_delete, send_email_user_status) from common.token_generator import account_activation_token -from common.utils import ROLES +from common.utils import ROLES, COUNTRIES from contacts.models import Contact from leads.models import Lead from opportunity.models import Opportunity from teams.models import Teams -from marketing.models import ContactEmailCampaign, BlockedDomain, BlockedEmail +from marketing.models import ContactEmailCampaign, BlockedDomain, BlockedEmail def handler404(request, exception): @@ -56,6 +56,17 @@ def handler500(request): return render(request, '500.html', status=500) +@login_required +def get_teams_and_users(request): + data = {} + teams = Teams.objects.all() + teams_data = [{'team': team.id, 'users': [user.id for user in team.users.all()]} for team in teams] + users = User.objects.all().values_list("id", flat=True) + data['teams'] = teams_data + data['users'] = list(users) + return JsonResponse(data) + + class AdminRequiredMixin(AccessMixin): def dispatch(self, request, *args, **kwargs): @@ -519,7 +530,7 @@ class DocumentListView(SalesAccessRequiredMixin, LoginRequiredMixin, TemplateVie def get_context_data(self, **kwargs): context = super(DocumentListView, self).get_context_data(**kwargs) context["users"] = User.objects.filter( - is_active=True).order_by('email') + is_active=True).order_by('username') context["documents"] = self.get_queryset() context["status_choices"] = Document.DOCUMENT_STATUS_CHOICE context["sharedto_list"] = [ @@ -640,7 +651,6 @@ def download_document(request, pk): request.user not in doc_obj.shared_to.all()): raise PermissionDenied if settings.STORAGE_TYPE == "normal": - # print('no no no no') path = doc_obj.document_file.path file_path = os.path.join(settings.MEDIA_ROOT, path) if os.path.exists(file_path): @@ -653,14 +663,11 @@ def download_document(request, pk): else: file_path = doc_obj.document_file file_name = doc_obj.title - # print(file_path) - # print(file_name) BUCKET_NAME = "django-crm-demo" KEY = str(file_path) s3 = boto3.resource('s3') try: s3.Bucket(BUCKET_NAME).download_file(KEY, file_name) - # print('got it') with open(file_name, 'rb') as fh: response = HttpResponse( fh.read(), content_type="application/vnd.ms-excel") @@ -694,8 +701,6 @@ def download_attachment(request, pk): # pragma: no cover else: file_path = attachment_obj.attachment file_name = attachment_obj.file_name - # print(file_path) - # print(file_name) BUCKET_NAME = "django-crm-demo" KEY = str(file_path) s3 = boto3.resource('s3') @@ -713,8 +718,6 @@ def download_attachment(request, pk): # pragma: no cover print("The object does not exist.") else: raise - # if file_path: - # print('yes tus pus') raise Http404 @@ -797,6 +800,7 @@ def api_settings(request): } if request.method == 'POST': + # settings = api_settings # if request.POST.get('api_settings', None): # if request.POST.get('title', None): @@ -1053,9 +1057,25 @@ def create_lead_from_site(request): # pragma: no cover if (request.get_host() in ['sales.micropyramid.com', ] and request.POST.get('origin_domain') in allowed_domains): if request.method == 'POST': if request.POST.get('full_name', None): + try: + description = request.POST.get('enquiry_type') + '\n' + request.POST.get('message') + except Exception as e: + print("e:::",e) + country = request.POST.get('country').title() + country_codes = list(COUNTRIES) + for count in country_codes: + if country == count[1]: + country = count[0] + break + phone=request.POST.get('phone') + phone_number = phonenumbers.parse(phone, country) lead = Lead.objects.create(title=request.POST.get('full_name'), email=request.POST.get( - 'email'), phone=request.POST.get('phone'), description=request.POST.get('message'), + 'email'), phone=phone_number, + description=description, + country=country, created_from_site=True) + lead.source = 'micropyramid' + lead.save() recipients = User.objects.filter( role='ADMIN').values_list('id', flat=True) lead.assigned_to.add(*recipients) diff --git a/contacts/forms.py b/contacts/forms.py index 8f4c4c69..31dc9ee4 100644 --- a/contacts/forms.py +++ b/contacts/forms.py @@ -21,7 +21,7 @@ class ContactForm(forms.ModelForm): for key, value in self.fields.items(): if key == 'phone': - value.widget.attrs['placeholder'] = "+91-123-456-7890" + value.widget.attrs['placeholder'] = "+911234567890" else: value.widget.attrs['placeholder'] = value.label self.fields["teams"].choices = [(team.get('id'), team.get('name')) for team in Teams.objects.all().values('id', 'name')] diff --git a/contacts/templates/contacts.html b/contacts/templates/contacts.html index ab4fd4a6..7946fdc4 100644 --- a/contacts/templates/contacts.html +++ b/contacts/templates/contacts.html @@ -47,8 +47,8 @@
@@ -319,4 +319,4 @@ $('#contacts_filter').submit(); }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/contacts/templates/create_contact.html b/contacts/templates/create_contact.html index c761da37..772e35cb 100644 --- a/contacts/templates/create_contact.html +++ b/contacts/templates/create_contact.html @@ -105,7 +105,7 @@ id="id_assigned_to"> {% for user in users %} {% endfor %} @@ -217,36 +217,170 @@ } } - $("#id_teams").change(function (e) { - try { - var users = [] - $('#id_teams option:selected').each(function () { - // users.push($(this).attr('data-users')) - _data = $(this).attr('data-users'); - if (!users) { - // users = [] - } else { - users = users.concat(_data.split(',')) - } - }) - // users = $('option:selected', this).attr('data-users') - // if (!users) { - // users = [] - // } else { - // users = users.split(',') - // } - console.log('selected users teams data', users) - var existingUsers = $('#id_assigned_to').val(); - var allUsers = users.concat(existingUsers) - console.log(existingUsers) - if (users.length) { - $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + function find_dict(dict, id){ + var index = dict.map(function(o) { return o.team; }).indexOf(parseInt(id)); + return dict[index]['users'] + } + $("#id_teams").change(function (e) { + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'contacts:get_teams_and_users' %}", function(data){ + // console.log(data) + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2().trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + // console.log("s_users", selected_users) + var un_select_users = [].concat.apply([], selected_users) + // console.log('un select users', un_select_users); + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + // console.log(' selected', $(this).attr('data-users').split(',')) + // console.log('selected', $(this).attr('data-users')) + } + else { + _unselected = $(this).attr('data-users').split(',') + // console.log('un selected', $(this).attr('data-users').split(',')) + } + }); + // console.log('selected users teams data', users) + var existingUsers = $('#id_assigned_to').val(); + var allUsers = users + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); } - } catch (error) { - console.log(error) - $('#_id_assigned_to').select2().val(existingUsers).trigger('change'); - } + }) + + }); + + $(document).ready(function($) { + + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'contacts:get_teams_and_users' %}", function(data){ + + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + // $('#id_assigned_to').select2().val([]).trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + var un_select_users = [].concat.apply([], selected_users) + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + // $(this).attr('disabled', 'disabled') + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + } + else { + _unselected = $(this).attr('data-users').split(',') + } + }); + var existingUsers = $('#id_assigned_to').val(); + // var allUsers = users.concat(existingUsers) + var allUsers = users + // console.log(existingUsers) + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); + } + }) }); diff --git a/contacts/urls.py b/contacts/urls.py index baa735fc..50daa0a4 100644 --- a/contacts/urls.py +++ b/contacts/urls.py @@ -1,7 +1,7 @@ from django.urls import path from contacts.views import ( ContactsListView, CreateContactView, ContactDetailView, - UpdateContactView, RemoveContactView, + UpdateContactView, RemoveContactView, get_teams_and_users, GetContactsView, AddCommentView, UpdateCommentView, DeleteCommentView, AddAttachmentsView, DeleteAttachmentsView) @@ -30,4 +30,5 @@ urlpatterns = [ name="add_attachment"), path('attachment/remove/', DeleteAttachmentsView.as_view(), name="remove_attachment"), + path('get_teams_and_users/', get_teams_and_users, name="get_teams_and_users") ] diff --git a/contacts/views.py b/contacts/views.py index f0c1f05d..365c935e 100644 --- a/contacts/views.py +++ b/contacts/views.py @@ -1,6 +1,7 @@ import json from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.sites.shortcuts import get_current_site +from django.contrib.auth.decorators import login_required from django.core.mail import EmailMessage from django.http import JsonResponse from django.shortcuts import get_object_or_404, redirect @@ -24,13 +25,24 @@ from common.access_decorators_mixins import ( from teams.models import Teams +@login_required +def get_teams_and_users(request): + data = {} + teams = Teams.objects.all() + teams_data = [{'team': team.id, 'users': [user.id for user in team.users.all()]} for team in teams] + users = User.objects.all().values_list("id", flat=True) + data['teams'] = teams_data + data['users'] = list(users) + return JsonResponse(data) + + class ContactsListView(SalesAccessRequiredMixin, LoginRequiredMixin, TemplateView): model = Contact context_object_name = "contact_obj_list" template_name = "contacts.html" def get_queryset(self): - queryset = self.model.objects.all() + queryset = self.model.objects.all().order_by('-created_on') if (self.request.user.role != "ADMIN" and not self.request.user.is_superuser): queryset = queryset.filter( @@ -61,7 +73,7 @@ class ContactsListView(SalesAccessRequiredMixin, LoginRequiredMixin, TemplateVie context["contact_obj_list"] = self.get_queryset() context["per_page"] = self.request.POST.get('per_page') context["users"] = User.objects.filter( - is_active=True).order_by('email') + is_active=True).order_by('username') context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i] search = False diff --git a/crm/settings.py b/crm/settings.py index 9e4d8b5b..fce08c78 100644 --- a/crm/settings.py +++ b/crm/settings.py @@ -27,7 +27,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'simple_pagination', 'compressor', - 'haystack', + # 'haystack', 'common', 'accounts', 'cases', @@ -158,8 +158,10 @@ elif STORAGE_TYPE == 's3-storage': AWS_STORAGE_BUCKET_NAME = AWS_BUCKET_NAME = os.getenv('AWSBUCKETNAME', '') AM_ACCESS_KEY = AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID', '') - AM_PASS_KEY = AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY', '') - S3_DOMAIN = AWS_S3_CUSTOM_DOMAIN = str(AWS_BUCKET_NAME) + '.s3.amazonaws.com' + AM_PASS_KEY = AWS_SECRET_ACCESS_KEY = os.getenv( + 'AWS_SECRET_ACCESS_KEY', '') + S3_DOMAIN = AWS_S3_CUSTOM_DOMAIN = str( + AWS_BUCKET_NAME) + '.s3.amazonaws.com' AWS_S3_OBJECT_PARAMETERS = { 'CacheControl': 'max-age=86400', @@ -292,7 +294,7 @@ if SENTRY_ENABLED and not DEBUG: MIDDLEWARE = [ 'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware', 'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', - ] + MIDDLEWARE + ] + MIDDLEWARE LOGGING = { 'version': 1, 'disable_existing_loggers': True, @@ -335,17 +337,53 @@ if SENTRY_ENABLED and not DEBUG: }, } -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'haystack.backends.elasticsearch2_backend.Elasticsearch2SearchEngine', - 'URL': 'http://127.0.0.1:9200/', - 'INDEX_NAME': 'haystack', - }, -} +# HAYSTACK_CONNECTIONS = { +# 'default': { +# # 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', +# 'ENGINE': 'marketing.search_backends.CustomElasticsearchSearchEngine', +# 'URL': 'http://127.0.0.1:9200/', +# 'INDEX_NAME': 'haystack', +# }, +# } -HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' +# HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' -HAYSTACK_SEARCH_RESULTS_PER_PAGE = 10 +# HAYSTACK_SEARCH_RESULTS_PER_PAGE = 10 + +# ELASTICSEARCH_INDEX_SETTINGS = { +# "settings": { +# "analysis": { +# "analyzer": { +# "ngram_analyzer": { +# "type": "custom", +# "tokenizer": "custom_ngram_tokenizer", +# "filter": ["asciifolding", "lowercase"] +# }, +# "edgengram_analyzer": { +# "type": "custom", +# "tokenizer": "custom_edgengram_tokenizer", +# "filter": ["asciifolding", "lowercase"] +# } +# }, +# "tokenizer": { +# "custom_ngram_tokenizer": { +# "type": "nGram", +# "min_gram": 3, +# "max_gram": 12, +# "token_chars": ["letter", "digit"] +# }, +# "custom_edgengram_tokenizer": { +# "type": "edgeNGram", +# "min_gram": 2, +# "max_gram": 12, +# "token_chars": ["letter", "digit"] +# } +# } +# } +# } +# } + +# HAYSTACK_DEFAULT_OPERATOR = 'AND' # Load the local settings file if it exists if os.path.isfile('crm/local_settings.py'): @@ -361,4 +399,5 @@ CACHES = { } } -PASSWORD_RESET_MAIL_FROM_USER = os.getenv('PASSWORD_RESET_MAIL_FROM_USER', 'no-reply@django-crm.com') +PASSWORD_RESET_MAIL_FROM_USER = os.getenv( + 'PASSWORD_RESET_MAIL_FROM_USER', 'no-reply@django-crm.com') diff --git a/docs/Makefile b/docs/Makefile index d0c3cbf1..182d33ac 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,20 +1,177 @@ -# Minimal makefile for Sphinx documentation +# Makefile for Sphinx documentation # -# You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -SOURCEDIR = source +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = BUILDDIR = build -# Put it first so that "make" without argument is like "make help". +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" -.PHONY: help Makefile +clean: + rm -rf $(BUILDDIR)/* -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/MicroSite.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/MicroSite.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/MicroSite" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/MicroSite" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/__init__.py b/docs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/docs/make.bat b/docs/make.bat deleted file mode 100644 index 6247f7e2..00000000 --- a/docs/make.bat +++ /dev/null @@ -1,35 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=source -set BUILDDIR=build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd diff --git a/docs/source/Accounts.rst b/docs/source/Accounts.rst new file mode 100644 index 00000000..e548b8ee --- /dev/null +++ b/docs/source/Accounts.rst @@ -0,0 +1,39 @@ +Accounts +******** + +| These have the user roles i.e Admin and User. User Role will have permissions where Admin can access. + +| Create your Accounts - new account can be created for different users and contacts and leads can create in accounts itself in their view pages + + +.. image:: screenshots/accountshome1.png + +| **Fig** Accounts page + +| This page view describes us about the accounts available and basic information. + +| There are 2 types of accounts i.e Open/Closed accounts. + +| We can Edit/Delete accounts here + +| To create an account we have a option "Add New Account" at the top right corner On Clicking it you will be redirected to the below page. + +| **Optional:** We can filter the users based on name,city,tags . + +.. image:: screenshots/accountcreate.png + +| **Fig** Account create page + +| Here while we are creating an account, it is mandatory to have minimum one contact and one lead. + +| **Note:** Fields having ``*`` are mandatory + + + + + +.. | Rules to follow:- + +.. 1.writing test cases for the code + +.. 2.test cases coverage percent should be above 90% diff --git a/docs/source/Cases.rst b/docs/source/Cases.rst new file mode 100644 index 00000000..a00ce200 --- /dev/null +++ b/docs/source/Cases.rst @@ -0,0 +1,20 @@ +Cases +***** + + +.. image:: screenshots/caseshome1.png + +| **Fig** cases Home Page + +| The above figure shows the cases view, this page gives details and list view of leads +| You can filter the results by name, status, priority, account. + +| Create a new Lead using the button on right corner ``+ Add New case`` + +.. image:: screenshots/casescreate.png + +| **Fig** cases Create Page + +| **Note:** Fields having ``*`` are mandatory. + +| **Note:** To create a cases user,accounts are required. \ No newline at end of file diff --git a/docs/source/Change Password.rst b/docs/source/Change Password.rst new file mode 100644 index 00000000..93f23f7c --- /dev/null +++ b/docs/source/Change Password.rst @@ -0,0 +1,11 @@ +Change Password +*************** + + +.. image:: screenshots/changepassword.png + +| **Fig** Password Change Page + +| The above figure shows the password change view, here enter the old password in "old password field" and enter new password in "new password field" and retype the new password in "confirm new password" field. + +| Click "Change Password" button to change the password successfully, otherwise cancel to cancel the process. diff --git a/docs/source/Contacts.rst b/docs/source/Contacts.rst new file mode 100644 index 00000000..a0f08c2c --- /dev/null +++ b/docs/source/Contacts.rst @@ -0,0 +1,23 @@ +Contacts +******** + +| Contacts can be created and can be assigned to Accounts + + + +.. image:: screenshots/contactshome1.png + +| **Fig** Contacts Home Page + +| The above figure shows the contacts view, this page gives details and list view of leads +| You can filter the results by name, city, assigned user. + +| Create a new Lead using the button on right corner ``+ Add New contact`` + +.. image:: screenshots/contactscreate.png + +| **Fig** Contacts Create Page + +| **Note:** Fields having ``*`` are mandatory. + +| **Note:** To create a contacts lead is required. \ No newline at end of file diff --git a/docs/source/Documents.rst b/docs/source/Documents.rst new file mode 100644 index 00000000..4b7cad9f --- /dev/null +++ b/docs/source/Documents.rst @@ -0,0 +1,18 @@ +Documents +********* + + +.. image:: screenshots/documentshome1.png + +| **Fig** documents Home Page + +| The above figure shows the documents view, this page gives details and list view of leads +| You can filter the results by title, status, shared to. + +| Create a new Document using the button on right corner ``+ Add New Document`` + +.. image:: screenshots/documentscreate.png + +| **Fig** Documents Create Page + +| **Note:** Fields having ``*`` are mandatory. diff --git a/docs/source/Forget Password.rst b/docs/source/Forget Password.rst new file mode 100644 index 00000000..c15aa7a1 --- /dev/null +++ b/docs/source/Forget Password.rst @@ -0,0 +1,43 @@ +Forget Password +*************** + +.. image:: screenshots/forgetpasswordpage.png + +| **Fig** Forget Password Page View + +| Enter the registered email id and click submit, then you will be sent a email to the registered email address, and redirect to the acknowledge page as below figure + +.. image:: screenshots/mailsent.png + +| **Fig** Email Sent acknowledgement view + +| When you check the mail you will recieve a email similar to the below figure. + +.. image:: screenshots/email.png + +| **Fig** Email recieved + +| When you click on the link in the mail, you will get a page as below + +.. image:: screenshots/resetpassword.png + +| **Fig** Password Reset view + + +| After you successful change the password you will get below page + +.. image:: screenshots/resetsuccessful.png + +| **Fig** Password Reset Successful view + +| Now click on login and enter your credentials + +| After successful login you will be redirected to Dashboard which looks similiar to the below figure + +.. image:: screenshots/homepage.png + +| **Fig** Dashboard view + +| The home page/Dashboard have access to all the modules of the CRM + +| **Note:** The numbers below accounts, contacts, leads, opportunities represent the total count of each module. \ No newline at end of file diff --git a/docs/source/Leads.rst b/docs/source/Leads.rst new file mode 100644 index 00000000..86bd596c --- /dev/null +++ b/docs/source/Leads.rst @@ -0,0 +1,18 @@ +Leads +***** + + +.. image:: screenshots/leadshome1.png + +| **Fig** Accounts Home Page + +| The above figure shows the leads view, this page gives details and list view of leads +| You can filter the results by name, source, assigned user, status, tags + +| Create a new Lead using the button on right corner ``+ Add New Lead`` + +.. image:: screenshots/leadscreate.png + +| **Fig** Leads Create Page + +| **Note:** Fields having ``*`` are mandatory diff --git a/docs/source/Login.rst b/docs/source/Login.rst new file mode 100644 index 00000000..d91ff903 --- /dev/null +++ b/docs/source/Login.rst @@ -0,0 +1,6 @@ +Login +***** + +.. image:: screenshots/login.png + +| **Fig** Login Page diff --git a/docs/source/Opportunity.rst b/docs/source/Opportunity.rst new file mode 100644 index 00000000..39a076d3 --- /dev/null +++ b/docs/source/Opportunity.rst @@ -0,0 +1,23 @@ +Opportunity +*********** + +| New Opportunities can be added and can be assigned to accounts and contacts. + + +.. image:: screenshots/opportunityhome1.png + +| **Fig** Opportunity Home Page + +| The above figure shows the Opportunity view, this page gives details and list view of leads +| They are two types of leads open and closed +| You can filter the results by name, stage, account, lead source + +| Create a new Lead using the button on right corner ``+ Add New Opportunity`` + +.. image:: screenshots/opportunitycreate.png + +| **Fig** Opportunity Create Page + +| **Note:** Fields having ``*`` are mandatory. + +| **Note:** To create a Opportunity lead is required. \ No newline at end of file diff --git a/docs/source/Profile.rst b/docs/source/Profile.rst new file mode 100644 index 00000000..c008c89e --- /dev/null +++ b/docs/source/Profile.rst @@ -0,0 +1,88 @@ +Profile +******* + +Dropdown menu for user settings + +.. image:: screenshots/dropdown.png + :align: center + +| **Fig** Dropdown menu + +Here in this drop down all the essential options for the user profile management are available i.e. + +Users +~~~~~ + +| On clicking users, the following page is shown + +.. image:: screenshots/usershome.png + :align: center + +| **Fig:** Users view + +| Here the user can activate/deactivate, edit/delete user data. + +| To create new user click on `` + Add New User``. + +| One clicking `` + Add New User`` the following page is shown: + +.. image:: screenshots/createuser.png + :align: center + +| **Fig** User create page + +| **Note:** Fields having ``*`` are mandatory. + +.. image:: screenshots/edituser.png + :align: center + +| **Fig:** User Edit User page + +Settings +~~~~~~~~~ +| On clicking settings, the following page is shown: + +.. image:: screenshots/settingshome.png + :align: center + +| **Fig:** User Settings page + +| Click on `` + Add New Setting`` + +.. image:: screenshots/createsettings.png + :align: center + +| **Fig:** User Create Setting page + + +Change Password +~~~~~~~~~~~~~~~ + +| On clicking settings, the following page is shown: + +.. image:: screenshots/changepassword.png + :align: center + +| **Fig:** User Change password page + +Profile +~~~~~~~ + +| On clicking settings, the following page is shown: + +.. image:: screenshots/profilehome.png + :align: center + +| **Fig:** User profile page + +.. image:: screenshots/editprofile.png + :align: center + +| **Fig:** User edit profile page + +| Here user can edit his personal details. + + +Logout +~~~~~~~ +On Clicking logout you will be logged out from the account and redirected to Login page. \ No newline at end of file diff --git a/docs/source/apps/crm/accounts.rst b/docs/source/apps/crm/accounts.rst deleted file mode 100644 index 211ab268..00000000 --- a/docs/source/apps/crm/accounts.rst +++ /dev/null @@ -1,9 +0,0 @@ -======== -Accounts -======== - -Accounts are nothing but converted leads. It has all the information of the company like Contacts, Opportunities, Cases, Tasks, Invoices, Mails history associated with this account. - -Here you can able to create a new account, check the existing accounts and update accounts. Here we have 2 types of accounts, Open & Closed accounts. Open accounts are the active accounts. You can filter accounts by account title, city, tags. - -In the account view page, you can attach any kind of documents and you can add comments if you have any updates. diff --git a/docs/source/apps/crm/cases.rst b/docs/source/apps/crm/cases.rst deleted file mode 100644 index 18b89dbd..00000000 --- a/docs/source/apps/crm/cases.rst +++ /dev/null @@ -1,10 +0,0 @@ -===== -Cases -===== - - -Any customer issues or help will be logged here. Each case will be assigned to respective team or user. Cases can be individual or it can be related to accounts or contacts. - -From cases list page, you can create a new case and you can manage existing cases like edit, delete and close cases. - -You can filter cases by its name, status, priority and assigned users. diff --git a/docs/source/apps/crm/contacts.rst b/docs/source/apps/crm/contacts.rst deleted file mode 100644 index f7d72a08..00000000 --- a/docs/source/apps/crm/contacts.rst +++ /dev/null @@ -1,9 +0,0 @@ -======== -Contacts -======== - -Contacts relate to individual persons of the company. Each account or lead may have more than one contact and one contact may associate with multiple accounts. - -You can create a new contact, manage existing contacts. In the contact view page, you can see the detailed view with associated Tasks, comments and attachments if any. - -You can filter contacts by name, city and assigned user. diff --git a/docs/source/apps/crm/dashboard.rst b/docs/source/apps/crm/dashboard.rst deleted file mode 100644 index e24bffa0..00000000 --- a/docs/source/apps/crm/dashboard.rst +++ /dev/null @@ -1,11 +0,0 @@ -========= -Dashboard -========= - -This is the first page you'll see when you login. Here you can see the general overview of your sales activity at a glance. Which displays count of your total Accounts, Contacts, Leads, Opportunities, Recently created accounts & opportunities. - -* **Recent Accounts:** Here you can see recently created 10 accounts with respective info like account title, tags, assigned user. By clicking on account title you will be redirected to account view page with detailed info. - -* **Recent Opportunities:** Here you can see recently created 10 opportunities with respective info like opportunity title, tags, assigned user. By clicking on opportunity title you will be redirected to opportunity view page with detailed info. - - diff --git a/docs/source/apps/crm/documents.rst b/docs/source/apps/crm/documents.rst deleted file mode 100644 index 90208500..00000000 --- a/docs/source/apps/crm/documents.rst +++ /dev/null @@ -1,9 +0,0 @@ -========= -Documents -========= - - -Here you can upload any kind of documents and assign to either team or individual person. In list page, you can see existing documents in a grid view with view, edit, delete and download options. - -Assigned users can able to manage and download the documents from the list page. You can filter documents by it’s name, status and assigned users. - diff --git a/docs/source/apps/crm/events.rst b/docs/source/apps/crm/events.rst deleted file mode 100644 index da1e919b..00000000 --- a/docs/source/apps/crm/events.rst +++ /dev/null @@ -1,12 +0,0 @@ -====== -Events -====== - -It is to schedule calls or meetings. There are 2 types of events, - -Recurring - Based on the day selection, start & end dates, you can create recurring events -Non-recurring - You can create events for a specific date - -When you assign an event for an user, they will receive a notification email reg: the event. You can upload attachments in the events view page. After completion of call or meeting, they can add comments in the event view page. - -You can filter events by name, created by, assigned users, date of meeting. diff --git a/docs/source/apps/crm/invoices.rst b/docs/source/apps/crm/invoices.rst deleted file mode 100644 index ca0e5f86..00000000 --- a/docs/source/apps/crm/invoices.rst +++ /dev/null @@ -1,15 +0,0 @@ -======== -Invoices -======== - -Which helps to generate a bill for your client or account based on the services you have provided. By doing this, you can measure how much of revenue is generating for your company. You can create invoices for individuals and assign to clients. - -You can save invoice as either draft or send. Total there are 5 options in the invoice - Draft, Send, Pending, Paid, Cancel. - -* **Draft -** It will be used for future purpose -* **Send -** If you choose the invoice status as send, then it will be shared with the respective client -* **Pending -** Waiting for the payment -* **Paid -** Invoice amount has been paid by client -* **Cancel -** It will close the invoice - -From invoice list page, you can change the invoice status, view, manage invoices. You can filer invoices by title, invoice number, created by, assigned users, status, total amount. diff --git a/docs/source/apps/crm/leads.rst b/docs/source/apps/crm/leads.rst deleted file mode 100644 index a5c2e60b..00000000 --- a/docs/source/apps/crm/leads.rst +++ /dev/null @@ -1,14 +0,0 @@ -===== -Leads -===== - -Leads plays a crucial role in the sales module. If anyone is interested towards your services, you can add them here. These leads are not confirmed. Once a lead is qualified, you can convert them as an account. - -You can create leads in two ways, - -* **By creating manually -** You can create only one lead at a time. -* **By uploading CSV file -** You can create more than one lead in a single click. - -There are 2 types of leads, open & closed leads. Open leads are the active leads. From the lead list page, you can view, update or delete a lead. - -From lead list page, click on the lead title, to check lead quick view. By clicking on the eye icon from table, you can see the detailed view of a lead. diff --git a/docs/source/apps/crm/opportunity.rst b/docs/source/apps/crm/opportunity.rst deleted file mode 100644 index 815696a6..00000000 --- a/docs/source/apps/crm/opportunity.rst +++ /dev/null @@ -1,10 +0,0 @@ -=========== -Opportunity -=========== - - -Requested services of the company are meant to be opportunities. New opportunities can be added and can be assigned to accounts & contacts. - -You can access opportunity view, edit and delete from the list page. In the list page, you can check which accounts are linked to opportunities. - -In the view page, you can check the detailed info an opportunity, uploaded attachments and comments. diff --git a/docs/source/apps/crm/tasks.rst b/docs/source/apps/crm/tasks.rst deleted file mode 100644 index 08983076..00000000 --- a/docs/source/apps/crm/tasks.rst +++ /dev/null @@ -1,7 +0,0 @@ -===== -Tasks -===== - -Project requirements are called as tasks. Each project will be divided into multiple tasks and if you finish tasks on time, then you can be able to complete a project with good productivity. - -You can create tasks with deadlines to track easily. From the task list page, you can create a new task, view, update and delete a task. In the task view page, you can check the uploaded documents and comments section. diff --git a/docs/source/apps/crm/teams.rst b/docs/source/apps/crm/teams.rst deleted file mode 100644 index a1cd9e7e..00000000 --- a/docs/source/apps/crm/teams.rst +++ /dev/null @@ -1,9 +0,0 @@ -===== -Teams -===== - -You can group users into teams. Instead of assigning leads, accounts etc. to multiple people, you can create a team and assign them. For ex: You can create teams like sales, marketing etc. - -In teams list page, you can see which users are involved in each team. From list page, you can access team view, edit, delete features. - -You can filter teams by name, created by, assigned users. diff --git a/docs/source/apps/internals/change_password.rst b/docs/source/apps/internals/change_password.rst deleted file mode 100644 index de664b52..00000000 --- a/docs/source/apps/internals/change_password.rst +++ /dev/null @@ -1,6 +0,0 @@ -=============== -Change Password -=============== - -For security purpose, you can change the password for your account. You can navigate to change password page, from user drop down. You have to specify new & confirm password as per the instructions specified in this page. - diff --git a/docs/source/apps/internals/forgot_password.rst b/docs/source/apps/internals/forgot_password.rst deleted file mode 100644 index 5405f6af..00000000 --- a/docs/source/apps/internals/forgot_password.rst +++ /dev/null @@ -1,5 +0,0 @@ -=============== -Forgot Password -=============== - -From the login page, you can request for forgot password. To reset the password, you have to specify your email. After that, you will receive an email with instructions to set a new password for your account. diff --git a/docs/source/apps/internals/profile.rst b/docs/source/apps/internals/profile.rst deleted file mode 100644 index 5bd51298..00000000 --- a/docs/source/apps/internals/profile.rst +++ /dev/null @@ -1,5 +0,0 @@ -======= -Profile -======= - -You can view/edit basic info of an user. You can access this page from user drop down. In this page, you can see the name of your account, email, in which team you are involved, which module permissions you have like sales & marketing, profile picture. diff --git a/docs/source/apps/internals/settings.rst b/docs/source/apps/internals/settings.rst deleted file mode 100644 index 78b0c580..00000000 --- a/docs/source/apps/internals/settings.rst +++ /dev/null @@ -1,7 +0,0 @@ -======== -Settings -======== - -In settings page, you can add contacts, block domains, block emails. You can access this page from user drop down. Only admins can able to access settings page. - -If you add any contacts in this page, those users will receive an email if anyone in the organization runs a campaign. If you block any domain or email, then they don’t receive any campaign related emails. diff --git a/docs/source/apps/internals/users.rst b/docs/source/apps/internals/users.rst deleted file mode 100644 index daeff0fc..00000000 --- a/docs/source/apps/internals/users.rst +++ /dev/null @@ -1,7 +0,0 @@ -===== -Users -===== - -To access the CRM, you can create users here with required permissions like user role (Admin & User), module level permissions (sales & marketing). Based on these two, user can access CRM features, when they logged in. - -There are 2 types of users, active & inactive(deleted users). From list page, you activate or deactivate user account and you can reset the password for an user. diff --git a/docs/source/apps/marketing/campaign.rst b/docs/source/apps/marketing/campaign.rst deleted file mode 100644 index c69081ba..00000000 --- a/docs/source/apps/marketing/campaign.rst +++ /dev/null @@ -1,12 +0,0 @@ -======== -Campaign -======== - -It will be useful to send promotional campaigns for multiple contacts and to generate more no. of leads. In campaign create page, you can choose existing contact list & email templates. - -Here you can choose option as whether to receive your replies to your account or CRM application. You can specify the placeholders in the template. Placeholders are like name, email, company etc. - -In the campaign view page, you can take a glance of everything. Like how many bounced contacts, unsubscribed users, opened emails etc. If there are any links in your email, you can also track which users opened that link or not. - -You can filter campaigns by name, created by. - diff --git a/docs/source/apps/marketing/contact-list.rst b/docs/source/apps/marketing/contact-list.rst deleted file mode 100644 index 02ca40d0..00000000 --- a/docs/source/apps/marketing/contact-list.rst +++ /dev/null @@ -1,9 +0,0 @@ -============ -Contact List -============ - -Use contact list to import bulk contacts into single list. In create page, you can download the sample file for your reference. - -It will be useful, at the time of sending a campaign. In contact list page, you can see name of the contact list, valid & invalid contacts of the list, bounced contacts, failed contacts, duplicate contacts. - -Click on the contact list title, to access view page. In view page, you can see detailed contacts info with count. Here you can either edit or delete contacts. diff --git a/docs/source/apps/marketing/contacts.rst b/docs/source/apps/marketing/contacts.rst deleted file mode 100644 index 6c20d72d..00000000 --- a/docs/source/apps/marketing/contacts.rst +++ /dev/null @@ -1,8 +0,0 @@ -======== -Contacts -======== - - -All the uploaded contacts will be appeared here. Here you can able to see valid, bounced, failed contacts with the count. You delete existing contacts from the list page. - -You filter contacts by email, domain name, created by, contact list. Click on each tab, to check contacts in a detailed view. diff --git a/docs/source/apps/marketing/dashboard.rst b/docs/source/apps/marketing/dashboard.rst deleted file mode 100644 index 3d114e6f..00000000 --- a/docs/source/apps/marketing/dashboard.rst +++ /dev/null @@ -1,9 +0,0 @@ -========= -Dashboard -========= - -Here you can see the general overview of your sales activity at a glance. Which display statistical view of latest 5 campaigns with required data. At bottom of this report, you can latest 5 records of contact list & campaigns - -* **Recent Contact List -** Here you can see contact list name, it’s tags. From here, you can switch to contact list view page. - -* **Recent Campaigns -** These are latest 5 campaigns with info of campaign title, tags, created on date. Click on the campaign title, to check it’s detailed view. diff --git a/docs/source/apps/marketing/email-templates.rst b/docs/source/apps/marketing/email-templates.rst deleted file mode 100644 index 39351ea0..00000000 --- a/docs/source/apps/marketing/email-templates.rst +++ /dev/null @@ -1,7 +0,0 @@ -=============== -Email Templates -=============== - -Email templates are used at the time of campaign creation. From the list page, click on the plus(+) icon to create a campaign using that template. - -Click on eye icon, to see how the template will look like. You can filter email templates by name, created by. diff --git a/docs/source/conf.py b/docs/source/conf.py index 86351d36..bc76997e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,57 +1,266 @@ -# Configuration file for the Sphinx documentation builder. +# -*- coding: utf-8 -*- # -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html +# django-blog-it documentation build configuration file, created by +# sphinx-quickstart on Mon Dec 29 20:41:44 2014. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +from recommonmark.parser import CommonMarkParser +source_parsers = { + '.md': CommonMarkParser, +} -# -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -# # import os # import sys # sys.path.insert(0, os.path.abspath('.')) +# -- General configuration ------------------------------------------------ -# -- Project information ----------------------------------------------------- - -project = 'Django-CRM' -copyright = '2019, MicroPyramid' -author = 'MicroPyramid' - -# The full version, including alpha/beta/rc tags -release = '0.9.0' - - -# -- General configuration --------------------------------------------------- +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ + 'sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon' ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ['ntemplates'] + +# The suffix of source filenames. +# source_suffix = '.rst' +source_suffix = ['.rst', '.md'] + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Django-CRM' +copyright = u'2017, MicroPyramid' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.6.0' +# The full version, including alpha/beta/rc tags. +release = '0.6.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. exclude_patterns = [] +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None -# -- Options for HTML output ------------------------------------------------- +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -# -html_theme = 'alabaster' +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ['nstatic'] -master_doc = "index" +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'Django-CRM-doc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'Django-CRM.tex', u'Django-CRM Documentation', + u'Django-CRM', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'Django-CRM', u'Django-CRM Documentation', + [u'Django-CRM'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'Django-CRM', u'Django-CRM Documentation', + u'Django-CRM', 'Django-CRM', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/source/index.rst b/docs/source/index.rst index 8efcb2c2..439a5845 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -2,72 +2,102 @@ Django CRM ========== -Django CRM is an opensource CRM on Django framework developed and maintained by `Micropyramid`_. It has all the basic features of Sales and Marketing to begin with and customise to meet industry needs. +Introduction: +============= -.. _Micropyramid: https://micropyramid.com/ +Django CRM is opensourse CRM developed on django framework. It has all the basic features of CRM to start with. We welcome code contributions and feature requests via github. -We welcome code contributions, suggestions, and feature requests via github. Source Code is available in `Micropyramid Repository`_. +Source Code is available in Micropyramid Repository() `Link `_. -.. _Micropyramid Repository: https://github.com/MicroPyramid/Django-CRM.git +Tech stack used: +================ -Installation -************ +* Python >= 3.4 +* Django >= 2.0 +* Redis +* django-simple-pagination + +Modules available in Django-CRM: +================================ + +User functionalites: +******************** .. toctree:: :maxdepth: 2 - - setup/index.rst - setup/packages_used.rst -Modules in Sales -**************** + Login + Forget Password + Profile + Change Password + + +Modules in crm: +*************** .. toctree:: - :maxdepth: 1 + :maxdepth: 2 - apps/crm/dashboard.rst - apps/crm/accounts.rst - apps/crm/contacts.rst - apps/crm/leads.rst - apps/crm/opportunity.rst - apps/crm/cases.rst - apps/crm/documents.rst - apps/crm/tasks.rst - apps/crm/invoices.rst - apps/crm/events.rst - apps/crm/teams.rst + Accounts + Contacts + Leads + Opportunity + Cases + Documents -Modules in Marketing -******************** +Rules to follow:- +================= +| 1.writing test cases for the code +| 2.test cases coverage percent should be above 90% -.. toctree:: - :maxdepth: 1 - apps/marketing/dashboard.rst - apps/marketing/contact-list.rst - apps/marketing/contacts.rst - apps/marketing/email-templates.rst - apps/marketing/campaign.rst -Internals +Setup On Local System +===================== + +On Windows +********** + +On Ubuntu ********* +| First Create a Virtual Environment in a local directory. +| Install Pip to install python packages. +| Then clone the source code from the repository `click here `_. +| Activate Virtual environment, then install the requirements.txt using the command -.. toctree:: - :maxdepth: 1 +:: - apps/internals/users.rst - apps/internals/settings.rst - apps/internals/profile.rst - apps/internals/change_password - apps/internals/forgot_password + pip install -r requirements.txt +| Then execute + +:: + + python manage.py runserver + +Now Go to browser, enter the url ``http://127.0.0.1:8000`` + +Installation - Requirements +=========================== + + +Ubuntu 64bit - 16.04 +********************* + +| $ sudo apt-get update && apt-get upgrade -y +| $ sudo apt-get install -y curl wget libpq-dev python3-dev gem ruby ruby-dev build-essential libssl-dev libffi-dev python-dev python-virtualenv python-pip git redis-server libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev libharfbuzz-dev libfribidi-dev tcl8.6-dev tk8.6-dev python-tk +| $ sudo gem install sass + +Visit our Django web development page [Here](https://micropyramid.com/django-ecommerce-development/) We welcome your feedback and support, raise github ticket if you want to report a bug or need new feature. -If you need any additional support? `Contact us here`_ +Need additional support? `Contact us here`_ .. _contact us here: https://micropyramid.com/contact-us/ or mailto:: "hello@micropyramid.com" + + diff --git a/docs/source/_static/screenshots/accountcreate.png b/docs/source/screenshots/accountcreate.png similarity index 100% rename from docs/source/_static/screenshots/accountcreate.png rename to docs/source/screenshots/accountcreate.png diff --git a/docs/source/_static/screenshots/accountshome.png b/docs/source/screenshots/accountshome.png similarity index 100% rename from docs/source/_static/screenshots/accountshome.png rename to docs/source/screenshots/accountshome.png diff --git a/docs/source/_static/screenshots/accountshome1.png b/docs/source/screenshots/accountshome1.png similarity index 100% rename from docs/source/_static/screenshots/accountshome1.png rename to docs/source/screenshots/accountshome1.png diff --git a/docs/source/_static/screenshots/casescreate.png b/docs/source/screenshots/casescreate.png similarity index 100% rename from docs/source/_static/screenshots/casescreate.png rename to docs/source/screenshots/casescreate.png diff --git a/docs/source/_static/screenshots/caseshome.png b/docs/source/screenshots/caseshome.png similarity index 100% rename from docs/source/_static/screenshots/caseshome.png rename to docs/source/screenshots/caseshome.png diff --git a/docs/source/_static/screenshots/caseshome1.png b/docs/source/screenshots/caseshome1.png similarity index 100% rename from docs/source/_static/screenshots/caseshome1.png rename to docs/source/screenshots/caseshome1.png diff --git a/docs/source/_static/screenshots/changepassword.png b/docs/source/screenshots/changepassword.png similarity index 100% rename from docs/source/_static/screenshots/changepassword.png rename to docs/source/screenshots/changepassword.png diff --git a/docs/source/_static/screenshots/contactscreate.png b/docs/source/screenshots/contactscreate.png similarity index 100% rename from docs/source/_static/screenshots/contactscreate.png rename to docs/source/screenshots/contactscreate.png diff --git a/docs/source/_static/screenshots/contactshome.png b/docs/source/screenshots/contactshome.png similarity index 100% rename from docs/source/_static/screenshots/contactshome.png rename to docs/source/screenshots/contactshome.png diff --git a/docs/source/_static/screenshots/contactshome1.png b/docs/source/screenshots/contactshome1.png similarity index 100% rename from docs/source/_static/screenshots/contactshome1.png rename to docs/source/screenshots/contactshome1.png diff --git a/docs/source/_static/screenshots/createsettings.png b/docs/source/screenshots/createsettings.png similarity index 100% rename from docs/source/_static/screenshots/createsettings.png rename to docs/source/screenshots/createsettings.png diff --git a/docs/source/_static/screenshots/createuser.png b/docs/source/screenshots/createuser.png similarity index 100% rename from docs/source/_static/screenshots/createuser.png rename to docs/source/screenshots/createuser.png diff --git a/docs/source/_static/screenshots/documentscreate.png b/docs/source/screenshots/documentscreate.png similarity index 100% rename from docs/source/_static/screenshots/documentscreate.png rename to docs/source/screenshots/documentscreate.png diff --git a/docs/source/_static/screenshots/documentshome.png b/docs/source/screenshots/documentshome.png similarity index 100% rename from docs/source/_static/screenshots/documentshome.png rename to docs/source/screenshots/documentshome.png diff --git a/docs/source/_static/screenshots/documentshome1.png b/docs/source/screenshots/documentshome1.png similarity index 100% rename from docs/source/_static/screenshots/documentshome1.png rename to docs/source/screenshots/documentshome1.png diff --git a/docs/source/_static/screenshots/dropdown.png b/docs/source/screenshots/dropdown.png similarity index 100% rename from docs/source/_static/screenshots/dropdown.png rename to docs/source/screenshots/dropdown.png diff --git a/docs/source/_static/screenshots/editprofile.png b/docs/source/screenshots/editprofile.png similarity index 100% rename from docs/source/_static/screenshots/editprofile.png rename to docs/source/screenshots/editprofile.png diff --git a/docs/source/_static/screenshots/edituser.png b/docs/source/screenshots/edituser.png similarity index 100% rename from docs/source/_static/screenshots/edituser.png rename to docs/source/screenshots/edituser.png diff --git a/docs/source/_static/screenshots/email.png b/docs/source/screenshots/email.png similarity index 100% rename from docs/source/_static/screenshots/email.png rename to docs/source/screenshots/email.png diff --git a/docs/source/_static/screenshots/forgetpasswordpage.png b/docs/source/screenshots/forgetpasswordpage.png similarity index 100% rename from docs/source/_static/screenshots/forgetpasswordpage.png rename to docs/source/screenshots/forgetpasswordpage.png diff --git a/docs/source/_static/screenshots/homepage.png b/docs/source/screenshots/homepage.png similarity index 100% rename from docs/source/_static/screenshots/homepage.png rename to docs/source/screenshots/homepage.png diff --git a/docs/source/_static/screenshots/leadscreate.png b/docs/source/screenshots/leadscreate.png similarity index 100% rename from docs/source/_static/screenshots/leadscreate.png rename to docs/source/screenshots/leadscreate.png diff --git a/docs/source/_static/screenshots/leadshome.png b/docs/source/screenshots/leadshome.png similarity index 100% rename from docs/source/_static/screenshots/leadshome.png rename to docs/source/screenshots/leadshome.png diff --git a/docs/source/_static/screenshots/leadshome1.png b/docs/source/screenshots/leadshome1.png similarity index 100% rename from docs/source/_static/screenshots/leadshome1.png rename to docs/source/screenshots/leadshome1.png diff --git a/docs/source/_static/screenshots/login.png b/docs/source/screenshots/login.png similarity index 100% rename from docs/source/_static/screenshots/login.png rename to docs/source/screenshots/login.png diff --git a/docs/source/_static/screenshots/mailsent.png b/docs/source/screenshots/mailsent.png similarity index 100% rename from docs/source/_static/screenshots/mailsent.png rename to docs/source/screenshots/mailsent.png diff --git a/docs/source/_static/screenshots/opportunitycreate.png b/docs/source/screenshots/opportunitycreate.png similarity index 100% rename from docs/source/_static/screenshots/opportunitycreate.png rename to docs/source/screenshots/opportunitycreate.png diff --git a/docs/source/_static/screenshots/opportunityhome.png b/docs/source/screenshots/opportunityhome.png similarity index 100% rename from docs/source/_static/screenshots/opportunityhome.png rename to docs/source/screenshots/opportunityhome.png diff --git a/docs/source/_static/screenshots/opportunityhome1.png b/docs/source/screenshots/opportunityhome1.png similarity index 100% rename from docs/source/_static/screenshots/opportunityhome1.png rename to docs/source/screenshots/opportunityhome1.png diff --git a/docs/source/_static/screenshots/profilehome.png b/docs/source/screenshots/profilehome.png similarity index 100% rename from docs/source/_static/screenshots/profilehome.png rename to docs/source/screenshots/profilehome.png diff --git a/docs/source/_static/screenshots/resetpassword.png b/docs/source/screenshots/resetpassword.png similarity index 100% rename from docs/source/_static/screenshots/resetpassword.png rename to docs/source/screenshots/resetpassword.png diff --git a/docs/source/_static/screenshots/resetsuccessful.png b/docs/source/screenshots/resetsuccessful.png similarity index 100% rename from docs/source/_static/screenshots/resetsuccessful.png rename to docs/source/screenshots/resetsuccessful.png diff --git a/docs/source/_static/screenshots/settingshome.png b/docs/source/screenshots/settingshome.png similarity index 100% rename from docs/source/_static/screenshots/settingshome.png rename to docs/source/screenshots/settingshome.png diff --git a/docs/source/_static/screenshots/usershome.png b/docs/source/screenshots/usershome.png similarity index 100% rename from docs/source/_static/screenshots/usershome.png rename to docs/source/screenshots/usershome.png diff --git a/docs/source/setup/index.rst b/docs/source/setup/index.rst deleted file mode 100644 index 89c7c8f2..00000000 --- a/docs/source/setup/index.rst +++ /dev/null @@ -1,169 +0,0 @@ -Installation & Configuration -============================ - -1. Create a django-crm directory using mkdir, move to it using cd - - .. code-block:: python - - mkdir django-crm - cd django-crm - -2. install virtualenv using the following command - - .. code-block:: python - - sudo apt-get install virtualenv - -3. create a python3 virtual environment and activate it using the following command - - .. code-block:: python - - virtualenv -p python3 env - source ../env/bin/activate - -4. create a django-crm directory again, move to it using cd - - .. code-block:: python - - mkdir django-crm - cd django-crm - -5. Install git using the following command and configure the account details - - .. code-block:: python - - sudo apt-get install git - - - .. code-block:: python - - git config --user.email - git config --user.name - -6. Intialize the git using the following command - - .. code-block:: python - - git init - - -7. Add django-crm repository using the following command - - .. code-block:: python - - git remote add origin https://github.com/MicroPyramid/Django-CRM.git - -7. Pull the latest code of django-crm using the following command - - .. code-block:: python - - git pull origin master - -8. Install project dependencies using the following commands - - .. code-block:: python - - curl -sL https://deb.nodesource.com/setup_10.x | bash - - sudo apt-get update - sudo apt-get apt install -y ruby-dev nodejs postgresql-client redis-server wkhtmltopdf memcache - gem install compass sass - npm -g install less - pip install --no-cache-dir redis - pip install --no-cache-dir -r requirements.txt - -9. We're using elasticsearch for searching emails in application. Install elasticsearch using the following command - - .. code-block:: python - - ### Install Java - - sudo add-apt-repository ppa:webupd8team/java - sudo apt-get update - sudo apt-get install oracle-java8-installer -y java -version - - .. code-block:: python - - ### Download and install the Public Signing Key - wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list - - .. code-block:: python - - ### Install Elasticsearch - sudo apt-get update && sudo apt-get install elasticsearch -y - # Start elasticsearch - sudo service elasticsearch start - - -10. open postgresql shell and create a database in postgresql using the following command - - .. code-block:: python - - sudo su - postgres - psql - create database dj_crm; - -11. we're loading third party related keys from virtual environment env. We need to add those keys to tun the application - - # sendgrid details - - SG_USER= - SG_PWD= - - #google developers account details - - GP_CLIENT_ID= - GP_CLIENT_SECRET= - ENABLE_GOOGLE_LOGIN= - - #sentry details - - SENTRYDSN= - SENTRY_ENABLED= - - #aws account details - - AWSBUCKETNAME= - AWS_ACCESS_KEY_ID= - AWS_SECRET_ACCESS_KEY= - - -12. Apply migrations to database using the following command - - .. code-block:: python - - python manage.py migrate - -13. Create superuser using the following command - - .. code-block:: python - - python manage.py createsuperuser - - - It'll ask for username, email, password for user - - -14. Run the application using the following command and open the browsr, visit http://localhost:8000 - - .. code-block:: python - - python manage.py runserver - - -15. Use the following command for indexing documents in elasticsearch - - - .. code-block:: python - - python manage.py rebuild_idex - -16. We're using celery for sending emails, other related tasks in the application. Run celery using the following commands - - .. code-block:: python - - celery -A crm worker -l info - - .. code-block:: python - - celery -A crm beat -l info - diff --git a/docs/source/setup/packages_used.rst b/docs/source/setup/packages_used.rst deleted file mode 100644 index 41326c3c..00000000 --- a/docs/source/setup/packages_used.rst +++ /dev/null @@ -1,58 +0,0 @@ -Packages Used -============= - -.. class:: center - - django - - celery - - django-simple-pagination - - django-compressor - - sorl-thumbnail - - django-phonenumber-field - - phonenumbers - - django-storages - - psycopg2-binary - - arrow - - requests - - boto3 - - lxml - - cssselect - - xlrd - - xlwt - - openpyxl - - pdfkit - - redis - - coverage - - raven - - sorl-thumbnail - - pytest - - pytest-django - - codacy-coverage - - django-haystack - - elasticsearch diff --git a/docs/source/setup/ubuntu-18.04-dev.rst b/docs/source/setup/ubuntu-18.04-dev.rst deleted file mode 100644 index a63a4683..00000000 --- a/docs/source/setup/ubuntu-18.04-dev.rst +++ /dev/null @@ -1,4 +0,0 @@ -Setup Dev system ----------------- - -Here you can see how to configure your dev machine to run Django-CRM diff --git a/docs/source/setup/ubuntu-18.04-server.rst b/docs/source/setup/ubuntu-18.04-server.rst deleted file mode 100644 index 831abe16..00000000 --- a/docs/source/setup/ubuntu-18.04-server.rst +++ /dev/null @@ -1,4 +0,0 @@ -Setup Dev system ----------------- - -Here you can see how to configure your server running ubuntu 18.04 to run Django-CRM diff --git a/events/templates/event_create.html b/events/templates/event_create.html index ed00c55a..513f912f 100644 --- a/events/templates/event_create.html +++ b/events/templates/event_create.html @@ -132,11 +132,18 @@ {% endif %}
- {{ form.assigned_to }} - {{ form.assigned_to.errors }} + {{ form.assigned_to.errors }} --> + + {{ form.assigned_to.errors }}
@@ -287,36 +294,170 @@ } }); - $("#id_teams").change(function (e) { - try { - var users = [] - $('#id_teams option:selected').each(function () { - // users.push($(this).attr('data-users')) - _data = $(this).attr('data-users'); - if (!users) { - // users = [] - } else { - users = users.concat(_data.split(',')) - } - }) - // users = $('option:selected', this).attr('data-users') - // if (!users) { - // users = [] - // } else { - // users = users.split(',') - // } - console.log('selected users teams data', users) - var existingUsers = $('#id_assigned_to').val(); - var allUsers = users.concat(existingUsers) - console.log(existingUsers) - if (users.length) { - $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + function find_dict(dict, id){ + var index = dict.map(function(o) { return o.team; }).indexOf(parseInt(id)); + return dict[index]['users'] + } + $("#id_teams").change(function (e) { + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'events:get_teams_and_users' %}", function(data){ + // console.log(data) + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2().trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + // console.log("s_users", selected_users) + var un_select_users = [].concat.apply([], selected_users) + // console.log('un select users', un_select_users); + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + // console.log(' selected', $(this).attr('data-users').split(',')) + // console.log('selected', $(this).attr('data-users')) + } + else { + _unselected = $(this).attr('data-users').split(',') + // console.log('un selected', $(this).attr('data-users').split(',')) + } + }); + // console.log('selected users teams data', users) + var existingUsers = $('#id_assigned_to').val(); + var allUsers = users + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); } - } catch (error) { - console.log(error) - $('#_id_assigned_to').select2().val(existingUsers).trigger('change'); - } + }) + + }); + + $(document).ready(function($) { + + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'events:get_teams_and_users' %}", function(data){ + + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + // $('#id_assigned_to').select2().val([]).trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + var un_select_users = [].concat.apply([], selected_users) + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + // $(this).attr('disabled', 'disabled') + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + } + else { + _unselected = $(this).attr('data-users').split(',') + } + }); + var existingUsers = $('#id_assigned_to').val(); + // var allUsers = users.concat(existingUsers) + var allUsers = users + // console.log(existingUsers) + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); + } + }) }); diff --git a/events/templates/events_list.html b/events/templates/events_list.html index 6d68edf3..c496405d 100644 --- a/events/templates/events_list.html +++ b/events/templates/events_list.html @@ -57,7 +57,7 @@
@@ -201,7 +201,7 @@ {% endif %} - {% if request.user == event.created_by or request.user.role == 'ADMIN' %} + {% if request.user == event.created_by or request.user.role == 'ADMIN' or request.user.has_sales_access %} -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/events/urls.py b/events/urls.py index dcd38ec4..89a645d7 100644 --- a/events/urls.py +++ b/events/urls.py @@ -18,4 +18,5 @@ urlpatterns = [ path('attachment/add/', AddAttachmentView.as_view(), name="add_attachment"), path('attachment/remove/', DeleteAttachmentsView.as_view(), name="remove_attachment"), + path('get_teams_and_users/', get_teams_and_users, name="get_teams_and_users") ] diff --git a/events/views.py b/events/views.py index c0eb3415..b62f123f 100644 --- a/events/views.py +++ b/events/views.py @@ -20,6 +20,18 @@ from common.access_decorators_mixins import ( from teams.models import Teams +@login_required +def get_teams_and_users(request): + data = {} + teams = Teams.objects.all() + teams_data = [{'team': team.id, 'users': [ + user.id for user in team.users.all()]} for team in teams] + users = User.objects.all().values_list("id", flat=True) + data['teams'] = teams_data + data['users'] = list(users) + return JsonResponse(data) + + @login_required @sales_access_required def events_list(request): @@ -35,7 +47,6 @@ def events_list(request): else: pass - if request.method == 'GET': context = {} if request.user.role == 'ADMIN' or request.user.is_superuser: @@ -43,12 +54,13 @@ def events_list(request): else: events = Event.objects.filter( Q(created_by=request.user) | Q(assigned_to=request.user)).distinct() - context['events'] = events.order_by('id') + context['events'] = events.order_by('-created_on') # context['status'] = status context['users'] = users user_ids = list(events.values_list('created_by', flat=True)) user_ids.append(request.user.id) - context['created_by_users'] = users.filter(is_active=True, id__in=user_ids) + context['created_by_users'] = users.filter( + is_active=True, id__in=user_ids) return render(request, 'events_list.html', context) if request.method == 'POST': @@ -79,10 +91,11 @@ def events_list(request): events = events.filter( date_of_meeting=request.POST.get('date_of_meeting')) - context['events'] = events.distinct().order_by('id') + context['events'] = events.distinct().order_by('-created_on') user_ids = list(events.values_list('created_by', flat=True)) user_ids.append(request.user.id) - context['created_by_users'] = users.filter(is_active=True, id__in=user_ids) + context['created_by_users'] = users.filter( + is_active=True, id__in=user_ids) return render(request, 'events_list.html', context) @@ -111,7 +124,8 @@ def event_create(request): event.save() form.save_m2m() if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = event.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -119,7 +133,8 @@ def event_create(request): if request.POST.getlist('teams', []): event.teams.add(*request.POST.getlist('teams')) - assigned_to_list = list(event.assigned_to.all().values_list('id', flat=True)) + assigned_to_list = list( + event.assigned_to.all().values_list('id', flat=True)) send_email.delay( event.id, assigned_to_list, domain=request.get_host(), protocol=request.scheme) @@ -146,7 +161,8 @@ def event_create(request): event.contacts.add(*request.POST.getlist('contacts')) event.assigned_to.add(*request.POST.getlist('assigned_to')) if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = event.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -154,9 +170,10 @@ def event_create(request): if request.POST.getlist('teams', []): event.teams.add(*request.POST.getlist('teams')) - assigned_to_list = list(event.assigned_to.all().values_list('id', flat=True)) + assigned_to_list = list( + event.assigned_to.all().values_list('id', flat=True)) send_email.delay( - event.id, assigned_to_list, domain=request.get_host(), protocol=request.scheme) + event.id, assigned_to_list, domain=request.get_host(), protocol=request.scheme) return JsonResponse({'error': False, 'success_url': reverse('events:events_list')}) else: @@ -215,7 +232,8 @@ def event_update(request, event_id): if form.is_valid(): start_date = form.cleaned_data.get('start_date') end_date = form.cleaned_data.get('end_date') - previous_assigned_to_users = list(event_obj.assigned_to.all().values_list('id', flat=True)) + previous_assigned_to_users = list( + event_obj.assigned_to.all().values_list('id', flat=True)) # recurring_days # recurring_days = request.POST.getlist('days') @@ -226,7 +244,8 @@ def event_update(request, event_id): event.save() form.save_m2m() if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = event.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -236,8 +255,10 @@ def event_update(request, event_id): event.teams.add(*request.POST.getlist('teams')) else: event.teams.clear() - assigned_to_list = list(event.assigned_to.all().values_list('id', flat=True)) - recipients = list(set(assigned_to_list) - set(previous_assigned_to_users)) + assigned_to_list = list( + event.assigned_to.all().values_list('id', flat=True)) + recipients = list(set(assigned_to_list) - + set(previous_assigned_to_users)) send_email.delay( event.id, recipients, domain=request.get_host(), protocol=request.scheme) @@ -246,7 +267,8 @@ def event_update(request, event_id): event.save() form.save_m2m() if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = event.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -256,8 +278,10 @@ def event_update(request, event_id): event.teams.add(*request.POST.getlist('teams')) else: event.teams.clear() - assigned_to_list = list(event.assigned_to.all().values_list('id', flat=True)) - recipients = list(set(assigned_to_list) - set(previous_assigned_to_users)) + assigned_to_list = list( + event.assigned_to.all().values_list('id', flat=True)) + recipients = list(set(assigned_to_list) - + set(previous_assigned_to_users)) send_email.delay( event.id, recipients, domain=request.get_host(), protocol=request.scheme) diff --git a/invoices/forms.py b/invoices/forms.py index f2848af3..2a50c6bb 100644 --- a/invoices/forms.py +++ b/invoices/forms.py @@ -39,7 +39,7 @@ class InvoiceForm(forms.ModelForm): self.fields["teams"].required = False self.fields['phone'].widget.attrs.update({ - 'placeholder': '+91-123-456-7890'}) + 'placeholder': '+911234567890'}) self.fields['invoice_title'].required = True self.fields['invoice_number'].required = True self.fields['currency'].required = True diff --git a/invoices/templates/invoice_create_1.html b/invoices/templates/invoice_create_1.html index b00340fc..e6cfa70c 100644 --- a/invoices/templates/invoice_create_1.html +++ b/invoices/templates/invoice_create_1.html @@ -258,11 +258,19 @@ {% endif %}
-
+ - {{form.assigned_to}} + + + {{ form.assigned_to.errors }}
@@ -392,37 +400,171 @@ } }); - $("#id_teams").change(function (e) { + function find_dict(dict, id){ + var index = dict.map(function(o) { return o.team; }).indexOf(parseInt(id)); + return dict[index]['users'] + } + + $("#id_teams").change(function (e) { + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'invoices:get_teams_and_users' %}", function(data){ + // console.log(data) + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2().trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] try { var users = [] $('#id_teams option:selected').each(function () { // users.push($(this).attr('data-users')) _data = $(this).attr('data-users'); - if (!users) { - // users = [] + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + // console.log("s_users", selected_users) + var un_select_users = [].concat.apply([], selected_users) + // console.log('un select users', un_select_users); + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); } else { users = users.concat(_data.split(',')) } - }) - // users = $('option:selected', this).attr('data-users') - // if (!users) { - // users = [] - // } else { - // users = users.split(',') - // } - console.log('selected users teams data', users) + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + // console.log(' selected', $(this).attr('data-users').split(',')) + // console.log('selected', $(this).attr('data-users')) + } + else { + _unselected = $(this).attr('data-users').split(',') + // console.log('un selected', $(this).attr('data-users').split(',')) + } + }); + // console.log('selected users teams data', users) var existingUsers = $('#id_assigned_to').val(); - var allUsers = users.concat(existingUsers) - console.log(existingUsers) + var allUsers = users + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); if (users.length) { - $('#_id_assigned_to').select2().val(allUsers).trigger('change'); } } catch (error) { console.log(error) - $('#_id_assigned_to').select2().val(existingUsers).trigger('change'); + $('#_id_assigned_to').select2().val([]).trigger('change'); } + }) - }); - - {% endblock js_block %} \ No newline at end of file + }); + + $(document).ready(function($) { + + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'invoices:get_teams_and_users' %}", function(data){ + + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + // $('#id_assigned_to').select2().val([]).trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + var un_select_users = [].concat.apply([], selected_users) + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + // $(this).attr('disabled', 'disabled') + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + } + else { + _unselected = $(this).attr('data-users').split(',') + } + }); + var existingUsers = $('#id_assigned_to').val(); + // var allUsers = users.concat(existingUsers) + var allUsers = users + // console.log(existingUsers) + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); + } + }) + + }); + +{% endblock js_block %} \ No newline at end of file diff --git a/invoices/templates/invoices_list.html b/invoices/templates/invoices_list.html index 61c40b5e..798df23d 100644 --- a/invoices/templates/invoices_list.html +++ b/invoices/templates/invoices_list.html @@ -62,7 +62,7 @@
@@ -717,4 +717,4 @@ $('#leads_filter').submit(); }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/invoices/urls.py b/invoices/urls.py index c08d359b..d6d80102 100644 --- a/invoices/urls.py +++ b/invoices/urls.py @@ -22,5 +22,6 @@ urlpatterns = [ path('attachment/add/', AddAttachmentView.as_view(), name="add_attachment"), path('attachment/remove/', DeleteAttachmentsView.as_view(), name="remove_attachment"), + path('get_teams_and_users/', get_teams_and_users, name="get_teams_and_users") ] diff --git a/invoices/views.py b/invoices/views.py index 24d50d1b..7d238408 100644 --- a/invoices/views.py +++ b/invoices/views.py @@ -25,6 +25,17 @@ from common.access_decorators_mixins import ( from teams.models import Teams +@login_required +def get_teams_and_users(request): + data = {} + teams = Teams.objects.all() + teams_data = [{'team': team.id, 'users': [user.id for user in team.users.all()]} for team in teams] + users = User.objects.all().values_list("id", flat=True) + data['teams'] = teams_data + data['users'] = list(users) + return JsonResponse(data) + + @login_required @sales_access_required def invoices_list(request): @@ -48,11 +59,11 @@ def invoices_list(request): if request.method == 'GET': context = {} if request.user.role == 'ADMIN' or request.user.is_superuser: - invoices = Invoice.objects.all().distinct() + invoices = Invoice.objects.all().distinct().order_by('-created_on') else: invoices = Invoice.objects.filter( - Q(created_by=request.user) | Q(assigned_to=request.user)).distinct() - context['invoices'] = invoices.order_by('id') + Q(created_by=request.user) | Q(assigned_to=request.user)).distinct().order_by('-created_on') + context['invoices'] = invoices.order_by('-created_on') context['status'] = status context['users'] = users user_ids = list(invoices.values_list('created_by', flat=True)) @@ -66,7 +77,7 @@ def invoices_list(request): context = {} context['status'] = status context['users'] = users - invoices = Invoice.objects.filter() + invoices = Invoice.objects.filter().order_by('-created_on') if request.user.role == 'ADMIN' or request.user.is_superuser: invoices = invoices else: @@ -97,7 +108,7 @@ def invoices_list(request): user_ids = list(invoices.values_list('created_by', flat=True)) user_ids.append(request.user.id) context['created_by_users'] = users.filter(is_active=True, id__in=user_ids) - context['invoices'] = invoices.distinct().order_by('id') + context['invoices'] = invoices.distinct().order_by('-created_on') today = datetime.today().date() context['today'] = today return render(request, 'invoices_list.html', context) diff --git a/leads/forms.py b/leads/forms.py index 78cfa6b2..b3d876dc 100644 --- a/leads/forms.py +++ b/leads/forms.py @@ -14,6 +14,16 @@ from teams.models import Teams class LeadForm(forms.ModelForm): teams_queryset = [] teams = forms.MultipleChoiceField(choices=teams_queryset) + LEAD_SOURCE_CHOICES = ( + ('call', 'Call'), + ('email', 'Email'), + ('existing customer', 'Existing Customer'), + ('partner', 'Partner'), + ('public relations', 'Public Relations'), + ('compaign', 'Campaign'), + ('other', 'Other'), + ) + source = forms.ChoiceField(choices=LEAD_SOURCE_CHOICES) def __init__(self, *args, **kwargs): assigned_users = kwargs.pop('assigned_to', []) @@ -43,7 +53,7 @@ class LeadForm(forms.ModelForm): self.fields['account_name'].widget.attrs.update({ 'placeholder': 'Account Name'}) self.fields['phone'].widget.attrs.update({ - 'placeholder': '+91-123-456-7890'}) + 'placeholder': '+911234567890'}) self.fields['description'].widget.attrs.update({ 'rows': '6'}) self.fields['address_line'].widget.attrs.update({ @@ -61,6 +71,13 @@ class LeadForm(forms.ModelForm): self.fields["teams"].choices = [(team.get('id'), team.get('name')) for team in Teams.objects.all().values('id', 'name')] self.fields["teams"].required = False + if self.instance.id: + if self.instance.created_from_site: + prev_choices = self.fields['source']._get_choices() + prev_choices = prev_choices +[('micropyramid', 'Micropyramid')] + self.fields['source']._set_choices(prev_choices) + + class Meta: model = Lead fields = ('assigned_to', 'first_name', @@ -148,7 +165,6 @@ def import_document_validator(document): print(e) return {"error": True, "message": "Not a valid CSV file"} - class LeadListForm(forms.Form): leads_file = forms.FileField(required=False) diff --git a/leads/models.py b/leads/models.py index 0b57c698..ff40994a 100644 --- a/leads/models.py +++ b/leads/models.py @@ -26,7 +26,7 @@ class Lead(models.Model): null=True, choices=LEAD_STATUS) source = models.CharField( _("Source of Lead"), max_length=255, - blank=True, null=True, choices=LEAD_SOURCE) + blank=True, null=True) address_line = models.CharField( _("Address"), max_length=255, blank=True, null=True) street = models.CharField( diff --git a/leads/tasks.py b/leads/tasks.py index 586510e2..8b659279 100644 --- a/leads/tasks.py +++ b/leads/tasks.py @@ -109,20 +109,27 @@ def create_lead_from_file(validated_rows, invalid_rows, user_id, source): for row in validated_rows: if not Lead.objects.filter(title=row.get('title')).exists(): if re.match(email_regex, row.get('email')) is not None: - lead = Lead() - lead.title = row.get('title') - lead.first_name = row.get('first name') - lead.last_name = row.get('last name') - lead.website = row.get('website') - lead.email = row.get('email') - lead.phone = row.get('phone') - lead.address_line = row.get('address') - # lead.city = row.get('city') - # lead.state = row.get('state') - # lead.postcode = row.get('postcode') - # lead.country = row.get('country') - lead.created_by = user - lead.save() + try: + lead = Lead() + lead.title = row.get('title', '')[:64] + lead.first_name = row.get('first name', '')[:255] + lead.last_name = row.get('last name', '')[:255] + lead.website = row.get('website', '')[:255] + lead.email = row.get('email', '') + lead.phone = row.get('phone', '') + lead.address_line = row.get('address', '')[:255] + lead.city = row.get('city', '')[:255] + lead.state = row.get('state', '')[:255] + lead.postcode = row.get('postcode', '')[:64] + lead.country = row.get('country', '')[:3] + lead.description = row.get('description', '') + lead.status = row.get('status', '') + lead.account_name = row.get('account_name', '')[:255] + lead.created_from_site = False + lead.created_by = user + lead.save() + except e: + print(e) @task diff --git a/leads/templates/create_lead.html b/leads/templates/create_lead.html index a45985f3..a51ba36a 100644 --- a/leads/templates/create_lead.html +++ b/leads/templates/create_lead.html @@ -73,7 +73,7 @@ class="error">*{% endif %} + class="form-control" placeholder="+911234567890" id="id_phone"> {{ lead_form.phone.errors }}
@@ -454,6 +454,7 @@ var existingUsers = $('#id_assigned_to').val(); var allUsers = users $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + $('#id_assigned_to').select2().val(existingUsers).trigger('change'); if (users.length) { } diff --git a/leads/templates/leads.html b/leads/templates/leads.html index cd7a9b3c..5fa3ec87 100644 --- a/leads/templates/leads.html +++ b/leads/templates/leads.html @@ -48,9 +48,9 @@
- - + +
@@ -72,7 +72,7 @@
@@ -855,8 +855,8 @@ $(".remove_tag").click(function () { // $(".tag_class_opp").css('cursor', 'pointer') url = "{% url 'leads:list' %}" - console.log($(this).attr('data-tag')) - console.log($(this).attr('data-lead')) + // console.log($(this).attr('data-tag')) + // console.log($(this).attr('data-lead')) const data = { 'tag': $(this).attr('data-tag'), 'lead': $(this).attr('data-lead') } const tagToRemove = $(this).attr('data-lead') + $(this).attr('data-tag') const lead = $(this).attr('data-lead') @@ -942,12 +942,26 @@ $("#open-tab").click() } + $.urlParam = function(name){ + var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + if (results==null){ + return null; + } + else{ + return results[1] || 0; + } + } $('.delete').click(function (e) { e.preventDefault() url = $(this).attr('href') if (!confirm('Are you sure you want to delete?')) return; + if($.urlParam('page')){ + window.location = $(this).attr('href')+"?page="+$.urlParam('page'); + } + else{ window.location = $(this).attr('href') + } }); $("a[rel='page']").click(function (e) { @@ -956,4 +970,4 @@ $('#leads_filter').submit(); }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/leads/templates/view_leads.html b/leads/templates/view_leads.html index bf4e8937..47771bc8 100644 --- a/leads/templates/view_leads.html +++ b/leads/templates/view_leads.html @@ -131,6 +131,23 @@
+
+
+
+ {% for tag in lead_record.tags.all %} + + + {{ tag.name }} + + + + {% empty %} +
Not Specified
+ {% endfor %} +
+
+
@@ -515,4 +532,4 @@ } }) -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/leads/tests.py b/leads/tests.py index 37957ee4..8d7af361 100644 --- a/leads/tests.py +++ b/leads/tests.py @@ -503,7 +503,7 @@ class TestUpdateLeadView(TestLeadModel, TestCase): self.client.login(username='janeLead2@example.com', password='password') response = self.client.get(reverse('leads:edit_lead', args=(self.lead.id,)), {'status': 'assigned', 'country':'AD', 'title':'update_title'}) - self.assertEqual(response.status_code, 403) + self.assertEqual(response.status_code, 200) self.client.logout() @@ -702,10 +702,10 @@ class TestCommentAddResponse(TestLeadModel, TestCase): response = self.client.get(reverse('leads:sample_lead_file')) sample_data = [ 'title,first name,last name,website,phone,email,address\n', - 'lead1,john,doe,www.example.com,+91-123-456-7890,user1@email.com,address for lead1\n', - 'lead2,jane,doe,www.website.com,+91-123-456-7891,user2@email.com,address for lead2\n', - 'lead3,joe,doe,www.test.com,+91-123-456-7892,user3@email.com,address for lead3\n', - 'lead4,john,doe,www.sample.com,+91-123-456-7893,user4@email.com,address for lead4\n', + 'lead1,john,doe,www.example.com,+911234567890,user1@email.com,address for lead1\n', + 'lead2,jane,doe,www.website.com,+911234567891,user2@email.com,address for lead2\n', + 'lead3,joe,doe,www.test.com,+911234567892,user3@email.com,address for lead3\n', + 'lead4,john,doe,www.sample.com,+911234567893,user4@email.com,address for lead4\n', ] content = bytes(''.join(sample_data), 'utf-8') self.assertEqual(response.content, content) \ No newline at end of file diff --git a/leads/views.py b/leads/views.py index 2031742c..05d0ca2e 100644 --- a/leads/views.py +++ b/leads/views.py @@ -33,6 +33,9 @@ from planner.forms import ReminderForm from planner.models import Event, Reminder from teams.models import Teams from django.core.cache import cache +from django.db.models.functions import Concat +from django.db.models import Value as V + @login_required @@ -75,7 +78,7 @@ def lead_list_view(request): context["source"] = LEAD_SOURCE context["users"] = User.objects.filter( - is_active=True).order_by('email').values('id', 'email') + is_active=True).order_by('username').values('id', 'username') tag_ids = list(set(queryset.values_list('tags', flat=True,))) context["tags"] = Tags.objects.filter(id__in=tag_ids) @@ -95,9 +98,13 @@ def lead_list_view(request): request_post = request.POST if request_post: if request_post.get('name'): + queryset = queryset.annotate( + full_name=Concat('first_name', V(' '), 'last_name') + ).filter(full_name__icontains=request_post.get('name')) + if request_post.get('title'): queryset = queryset.filter( - Q(first_name__icontains=request_post.get('name')) & - Q(last_name__icontains=request_post.get('name'))) + Q(title__icontains=request_post.get('title'))) + # or Q(last_name__icontains=request_post.get('name'))) if request_post.get('city'): queryset = queryset.filter( city__icontains=request_post.get('city')) @@ -126,7 +133,6 @@ def lead_list_view(request): context["users"] = User.objects.filter( is_active=True).order_by('email').values('id', 'email') - tag_ids = list(set(queryset.values_list('tags', flat=True,))) context["tags"] = Tags.objects.filter(id__in=tag_ids) @@ -642,6 +648,8 @@ class DeleteLeadView(SalesAccessRequiredMixin, LoginRequiredMixin, View): ): self.object.delete() # update_leads_cache.delay() + if request.GET.get('page'): + return HttpResponseRedirect(reverse('leads:list') + '?page='+request.GET.get('page')) return redirect("leads:list") raise PermissionDenied @@ -952,10 +960,10 @@ def upload_lead_csv_file(request): def sample_lead_file(request): sample_data = [ 'title,first name,last name,website,phone,email,address\n', - 'lead1,john,doe,www.example.com,+91-123-456-7890,user1@email.com,address for lead1\n', - 'lead2,jane,doe,www.website.com,+91-123-456-7891,user2@email.com,address for lead2\n', - 'lead3,joe,doe,www.test.com,+91-123-456-7892,user3@email.com,address for lead3\n', - 'lead4,john,doe,www.sample.com,+91-123-456-7893,user4@email.com,address for lead4\n', + 'lead1,john,doe,www.example.com,+911234567890,user1@email.com,address for lead1\n', + 'lead2,jane,doe,www.website.com,+911234567891,user2@email.com,address for lead2\n', + 'lead3,joe,doe,www.test.com,+911234567892,user3@email.com,address for lead3\n', + 'lead4,john,doe,www.sample.com,+911234567893,user4@email.com,address for lead4\n', ] response = HttpResponse( sample_data, content_type='text/plain') diff --git a/marketing/forms.py b/marketing/forms.py index b85d6cca..565d58a4 100644 --- a/marketing/forms.py +++ b/marketing/forms.py @@ -10,7 +10,7 @@ from django import forms from common.models import User from marketing.models import (BlockedDomain, BlockedEmail, Campaign, Contact, ContactEmailCampaign, ContactList, EmailTemplate, Tag) -from haystack.forms import SearchForm +# from haystack.forms import SearchForm email_regex = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)" @@ -511,26 +511,26 @@ class BlockedEmailForm(forms.ModelForm): return email -class MarketingContactEmailSearchForm(SearchForm): - email_domain = forms.CharField() +# class MarketingContactEmailSearchForm(SearchForm): +# email_domain = forms.CharField() - def search(self): - # First, store the SearchQuerySet received from other processing. - sqs = super(MarketingContactEmailSearchForm, self).search() +# def search(self): +# # First, store the SearchQuerySet received from other processing. +# sqs = super(MarketingContactEmailSearchForm, self).search() - if not self.is_valid(): - return self.no_query_found() +# if not self.is_valid(): +# return self.no_query_found() - # Check to see if a start_date was chosen. - if self.cleaned_data['email_domain']: - # import pdb; pdb.set_trace() - sqs = sqs.filter(email__icontains=self.cleaned_data.get('email_domain')) +# # Check to see if a start_date was chosen. +# if self.cleaned_data['email_domain']: +# # import pdb; pdb.set_trace() +# sqs = sqs.filter(email__icontains=self.cleaned_data.get('email_domain')) - return sqs +# return sqs - def clean_email_domain(self): - email_domain = self.cleaned_data.get('email_domain') - domain_regex = '^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$' - if re.match(domain_regex, email_domain) is None: - raise forms.ValidationError('Enter a valid domain.') - return email_domain \ No newline at end of file +# def clean_email_domain(self): +# email_domain = self.cleaned_data.get('email_domain') +# domain_regex = '^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$' +# if re.match(domain_regex, email_domain) is None: +# raise forms.ValidationError('Enter a valid domain.') +# return email_domain \ No newline at end of file diff --git a/marketing/search_backends.py b/marketing/search_backends.py new file mode 100644 index 00000000..b95ef642 --- /dev/null +++ b/marketing/search_backends.py @@ -0,0 +1,20 @@ +from django.conf import settings + +from haystack.backends.elasticsearch_backend import ( + ElasticsearchSearchBackend, + ElasticsearchSearchEngine, +) + + +class CustomElasticsearchSearchBackend(ElasticsearchSearchBackend): + + def __init__(self, connection_alias, **connection_options): + super(CustomElasticsearchSearchBackend, self).__init__( + connection_alias, **connection_options) + + setattr(self, 'DEFAULT_SETTINGS', settings.ELASTICSEARCH_INDEX_SETTINGS) + + +class CustomElasticsearchSearchEngine(ElasticsearchSearchEngine): + + backend = CustomElasticsearchSearchBackend \ No newline at end of file diff --git a/marketing/search_indexes.py b/marketing/search_indexes.py index fb3d9cbf..4f595b9e 100644 --- a/marketing/search_indexes.py +++ b/marketing/search_indexes.py @@ -19,7 +19,6 @@ class MarketingContactIndex(indexes.SearchIndex, indexes.Indexable): contact_lists_id = indexes.MultiValueField() contact_lists_name = indexes.MultiValueField() is_bounced = indexes.BooleanField() - contact_lists_count = indexes.IntegerField() def get_model(self): return Contact @@ -48,9 +47,6 @@ class MarketingContactIndex(indexes.SearchIndex, indexes.Indexable): def prepare_is_bounced(self, obj): return obj.is_bounced - def prepare_contact_lists_count(self, obj): - return obj.contact_list.count() - def index_queryset(self, using=None): return self.get_model().objects.all() @@ -62,7 +58,7 @@ class MarketingFailedContactIndex(indexes.SearchIndex, indexes.Indexable): id = indexes.CharField(model_attr='id') email = indexes.EdgeNgramField(model_attr='email') - email_domain = indexes.EdgeNgramField() + email = indexes.EdgeNgramField() name = indexes.CharField(model_attr='name') company_name = indexes.CharField() created_on = indexes.CharField(model_attr='created_on') @@ -72,7 +68,6 @@ class MarketingFailedContactIndex(indexes.SearchIndex, indexes.Indexable): contact_lists = indexes.MultiValueField() contact_lists_id = indexes.MultiValueField() contact_lists_name = indexes.MultiValueField() - contact_lists_count = indexes.IntegerField() def get_model(self): @@ -99,8 +94,5 @@ class MarketingFailedContactIndex(indexes.SearchIndex, indexes.Indexable): def prepare_created_by_id(self, obj): return obj.created_by.id if obj.created_by else '' - def prepare_contact_lists_count(self, obj): - return obj.contact_list.count() - def index_queryset(self, using=None): return self.get_model().objects.all() diff --git a/marketing/tasks.py b/marketing/tasks.py index c1ccbff8..03a8dd3d 100644 --- a/marketing/tasks.py +++ b/marketing/tasks.py @@ -322,4 +322,4 @@ def send_campaign_email_to_admin_contact(campaign, domain='demo.django-crm.io', @task def update_elastic_search_index(): - call_command('update_index') \ No newline at end of file + call_command('update_index --age=1', interactive=False) \ No newline at end of file diff --git a/marketing/templates/add_blocked_domain.html b/marketing/templates/add_blocked_domain.html index 1182687b..a9e9298c 100644 --- a/marketing/templates/add_blocked_domain.html +++ b/marketing/templates/add_blocked_domain.html @@ -4,7 +4,7 @@ {{ block.super }} @@ -85,4 +85,4 @@ } }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/marketing/templates/add_blocked_email.html b/marketing/templates/add_blocked_email.html index 2b37e603..89211bf3 100644 --- a/marketing/templates/add_blocked_email.html +++ b/marketing/templates/add_blocked_email.html @@ -4,7 +4,7 @@ {{ block.super }} @@ -85,4 +85,4 @@ } }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/marketing/templates/add_email_for_campaign.html b/marketing/templates/add_email_for_campaign.html index e78ed080..7ff1a3ec 100644 --- a/marketing/templates/add_email_for_campaign.html +++ b/marketing/templates/add_email_for_campaign.html @@ -3,7 +3,7 @@ {% block breadcrumb %}
-
+
@@ -151,9 +151,9 @@ {{ contact.created_by }} {{ contact.created_on_arrow }} - {% for contact_list in contact.contact_lists %} + {% for contact_list in contact.contact_list.all %} {{contact_list.1}} + href="{% url 'marketing:contact_list_detail' contact_list.id %}">{{contact_list.name}} {% empty %} None @@ -366,6 +366,11 @@ $(".filter_toggle").click(function () { $(".list_filter_row").toggle(); }); + search = "{{search}}" + if (search == 'True') { + $(".list_filter_row").show(); + } + $('#id_tag').select2(); $('#delete_all').hide() $('#delete_all_bounced').hide() diff --git a/marketing/tests.py b/marketing/tests.py index 79f0e3e4..be266357 100644 --- a/marketing/tests.py +++ b/marketing/tests.py @@ -8,7 +8,7 @@ from django.core.management import call_command from django.shortcuts import reverse from django.test import Client, TestCase from django.test.utils import override_settings -from haystack import connections +# from haystack import connections from common.models import User from marketing.models import (Campaign, CampaignLinkClick, CampaignLog, @@ -145,9 +145,9 @@ class TestMarketingModel(object): @override_settings(HAYSTACK_CONNECTIONS=TEST_INDEX ) class TestTemplates(TestMarketingModel, TestCase): - def setUp(self): - super(TestTemplates, self).setUp() - connections.reload('default') + # def setUp(self): + # super(TestTemplates, self).setUp() + # connections.reload('default') def test_templates(self): url1 = reverse('marketing:dashboard') @@ -253,9 +253,9 @@ class TestDasboardView(TestMarketingModel, TestCase): @override_settings(HAYSTACK_CONNECTIONS=TEST_INDEX ) class TestContactListsListPage(TestMarketingModel, TestCase): - def setUp(self): - super(TestContactListsListPage, self).setUp() - connections.reload('default') + # def setUp(self): + # super(TestContactListsListPage, self).setUp() + # # connections.reload('default') def test_contact_lists_list_page(self): self.client.login(username='john@example.com', password='password') @@ -282,13 +282,13 @@ class TestContactListsListPage(TestMarketingModel, TestCase): @override_settings(HAYSTACK_CONNECTIONS=TEST_INDEX ) class TestContactsListPage(TestMarketingModel, TestCase): - def setUp(self): - super(TestContactsListPage, self).setUp() - connections.reload('default') + # def setUp(self): + # super(TestContactsListPage, self).setUp() + # connections.reload('default') # connections = ConnectionHandler(TEST_INDEX ) def test_contacts_list_page(self): - connections.reload('default') + # connections.reload('default') self.client.login(username='john@example.com', password='password') response = self.client.get( reverse('marketing:contacts_list')) diff --git a/marketing/urls.py b/marketing/urls.py index 307b7dd3..4aefaaf3 100644 --- a/marketing/urls.py +++ b/marketing/urls.py @@ -77,6 +77,6 @@ urlpatterns = [ path('edit-blocked-email//', edit_blocked_email, name="edit_blocked_email"), path('delete-blocked-email//', delete_blocked_email, name="delete_blocked_email"), - path('search-marketing-contact-emails/', include('haystack.urls')), + # path('search-marketing-contact-emails/', include('haystack.urls')), # path('elastic-search/', contacts_list_elastic_search), ] diff --git a/marketing/views.py b/marketing/views.py index caae92a3..3a1c054e 100644 --- a/marketing/views.py +++ b/marketing/views.py @@ -21,7 +21,7 @@ from common.utils import convert_to_custom_timezone from common.models import User from marketing.forms import (ContactForm, ContactListForm, EmailTemplateForm, SendCampaignForm, EmailCampaignForm, BlockedDomainsForm, - BlockedEmailForm, MarketingContactEmailSearchForm) + BlockedEmailForm) from marketing.models import (Campaign, CampaignLinkClick, CampaignLog, CampaignOpen, Contact, ContactList, EmailTemplate, Link, Tag, FailedContact, ContactUnsubscribedCampaign, @@ -31,8 +31,8 @@ from marketing.tasks import (run_campaign, upload_csv_file, send_campaign_email_to_admin_contact, update_elastic_search_index) from common.access_decorators_mixins import marketing_access_required, MarketingAccessRequiredMixin, admin_login_required -from haystack.generic_views import SearchView -from haystack.query import SearchQuerySet +# from haystack.generic_views import SearchView +# from haystack.query import SearchQuerySet TIMEZONE_CHOICES = [(tz, tz) for tz in pytz.common_timezones] @@ -93,15 +93,16 @@ def dashboard(request): def contact_lists(request): tags = Tag.objects.all() if (request.user.role == "ADMIN"): - queryset = ContactList.objects.all() + queryset = ContactList.objects.all().order_by('-created_on') else: queryset = ContactList.objects.filter( - Q(created_by=request.user) | Q(visible_to=request.user)) + Q(created_by=request.user) | Q(visible_to=request.user)).order_by('-created_on') users = User.objects.filter( id__in=queryset.values_list('created_by_id', flat=True)) if request.GET.get('tag'): queryset = queryset.filter(tags=request.GET.get('tag')) + search = False if request.method == 'POST': post_tags = request.POST.getlist('tag') @@ -116,9 +117,15 @@ def contact_lists(request): if request.POST.get('tag'): queryset = queryset.filter(tags__id__in=post_tags) request_tags = request.POST.getlist('tag') + if ( + request.POST.get('contact_list_name')or + request.POST.get('created_by')or + request.POST.get('created_by') + ): + search = True #for filter form to show in contactlist data = {'contact_lists': queryset, 'tags': tags, 'users': users, - 'request_tags': request.POST.getlist('tag'), } + 'request_tags': request.POST.getlist('tag'),'search':search } return render(request, 'marketing/lists/index.html', data) @@ -445,12 +452,13 @@ def failed_contact_list_download_delete(request, pk): def email_template_list(request): # users = User.objects.all() if (request.user.role == 'ADMIN' or request.user.is_superuser): - queryset = EmailTemplate.objects.all() + queryset = EmailTemplate.objects.all().order_by('-created_on') else: queryset = EmailTemplate.objects.filter( - created_by=request.user) + created_by=request.user).order_by('-created_on') users = User.objects.filter( id__in=queryset.values_list('created_by_id', flat=True)) + search = False if request.method == 'POST': if request.POST.get('template_name'): queryset = queryset.filter( @@ -459,8 +467,11 @@ def email_template_list(request): if request.POST.get('created_by'): queryset = queryset.filter( created_by=request.POST.get('created_by')) - - data = {'email_templates': queryset, 'users': users} + if (request.POST.get('template_name')or + request.POST.get('created_by') + ): + search =True + data = {'email_templates': queryset, 'users': users, 'search':search} return render(request, 'marketing/email_template/index.html', data) @@ -534,6 +545,7 @@ def campaign_list(request): id__in=queryset.values_list('created_by_id', flat=True)) if request.GET.get('tag'): queryset = queryset.filter(tags=request.GET.get('tag')) + search = False if request.method == 'POST': if request.POST.get('campaign_name'): queryset = queryset.filter( @@ -542,8 +554,12 @@ def campaign_list(request): if request.POST.get('created_by'): queryset = queryset.filter( created_by=request.POST.get('created_by')) - - data = {'campaigns_list': queryset, 'users': users} + #shows the filter form in marketing-Campaigns after any search is requested + if (request.POST.get('campaign_name')or + request.POST.get('created_by') + ): + search = True + data = {'campaigns_list': queryset,'search':search ,'users': users} return render(request, 'marketing/campaign/index.html', data) @@ -1285,23 +1301,24 @@ def delete_blocked_email(request, blocked_email_id): @login_required(login_url='/login') @marketing_access_required def contacts_list_elastic_search(request): + search = False if (request.user.role == "ADMIN"): - # contacts = Contact.objects.filter(is_bounced=False) - contacts = SearchQuerySet().filter(is_bounced='false').models(Contact) - bounced_contacts = SearchQuerySet().filter(is_bounced='true').models(Contact) - failed_contacts = SearchQuerySet().models(FailedContact).filter() - # bounced_contacts = Contact.objects.filter(is_bounced=True) - # failed_contacts = FailedContact.objects.all() + contacts = Contact.objects.filter(is_bounced=False) + # contacts = SearchQuerySet().filter(is_bounced='false').models(Contact) + # bounced_contacts = SearchQuerySet().filter(is_bounced='true').models(Contact) + # failed_contacts = SearchQuerySet().models(FailedContact).filter() + bounced_contacts = Contact.objects.filter(is_bounced=True) + failed_contacts = FailedContact.objects.all() contact_lists = ContactList.objects.all() else: contact_ids = request.user.marketing_contactlist.all().values_list('contacts', flat=True) - contacts = SearchQuerySet().filter(is_bounced='false', id__in=contact_ids).models(Contact) - bounced_contacts = SearchQuerySet().filter(is_bounced='true', id__in=contact_ids).models(Contact) - failed_contacts = SearchQuerySet().models(FailedContact).filter(created_by_id=str(request.user.id)) - # contacts = Contact.objects.filter(id__in=contact_ids).exclude(is_bounced=True) - # bounced_contacts = Contact.objects.filter(id__in=contact_ids, is_bounced=True) - # failed_contacts = FailedContact.objects.filter(created_by=request.user) + # contacts = SearchQuerySet().filter(is_bounced='false', id__in=contact_ids).models(Contact) + # bounced_contacts = SearchQuerySet().filter(is_bounced='true', id__in=contact_ids).models(Contact) + # failed_contacts = SearchQuerySet().models(FailedContact).filter(created_by_id=str(request.user.id)) + contacts = Contact.objects.filter(id__in=contact_ids).exclude(is_bounced=True) + bounced_contacts = Contact.objects.filter(id__in=contact_ids, is_bounced=True) + failed_contacts = FailedContact.objects.filter(created_by=request.user) contact_lists = ContactList.objects.filter(created_by=request.user) # contacts = Contact.objects.filter(created_by=request.user) @@ -1311,6 +1328,7 @@ def contacts_list_elastic_search(request): if request.method == 'GET': context = {'contacts': contacts, 'users': users, 'contact_lists': contact_lists, 'bounced_contacts': bounced_contacts, 'failed_contacts': failed_contacts, + 'search':search, } return render(request, 'search_contact_emails.html', context) @@ -1328,10 +1346,10 @@ def contacts_list_elastic_search(request): bounced_contacts = bounced_contacts.filter(email__icontains=data.get('email')) failed_contacts = failed_contacts.filter(email__icontains=data.get('email')) - if data.get('domain_name'): - contacts = contacts.filter(email_domain__icontains=data.get('domain_name')) - bounced_contacts = bounced_contacts.filter(email_domain__icontains=data.get('domain_name')) - failed_contacts = failed_contacts.filter(email_domain__icontains=data.get('domain_name')) + # if data.get('domain_name'): + # contacts = contacts.filter(email_domain__icontains=data.get('domain_name')) + # bounced_contacts = bounced_contacts.filter(email_domain__icontains=data.get('domain_name')) + # failed_contacts = failed_contacts.filter(email_domain__icontains=data.get('domain_name')) if data.get('created_by'): contacts = contacts.filter(created_by_id=data.get('created_by')) @@ -1339,12 +1357,21 @@ def contacts_list_elastic_search(request): failed_contacts = failed_contacts.filter(created_by_id=data.get('created_by')) if data.get('contact_list'): - contacts = contacts.filter(contact_lists_id=data.get('contact_list')) - bounced_contacts = bounced_contacts.filter(contact_lists_id=data.get('contact_list')) - failed_contacts = failed_contacts.filter(contact_lists_id=data.get('contact_list')) + contacts = contacts.filter(contact_list__id=data.get('contact_list')) + bounced_contacts = bounced_contacts.filter(contact_list__id=data.get('contact_list')) + failed_contacts = failed_contacts.filter(contact_list__id=data.get('contact_list')) + # shows filter form in marketing-contact if any search + if ( + data.get('name')or + data.get('email')or + data.get('created_by')or + data.get('contact_list') + ): + search = True context = {'contacts': contacts, 'users': users, 'contact_lists': contact_lists, 'bounced_contacts': bounced_contacts, 'failed_contacts': failed_contacts, + 'search':search, } return render(request, 'search_contact_emails.html', context) @@ -1353,7 +1380,6 @@ def contacts_list_elastic_search(request): # form_class = MarketingContactEmailSearchForm # def get_query(self): -# import pdb; pdb.set_trace() # if self.form.is_valid(): # return self.form.cleaned_data["email_domain"] @@ -1367,5 +1393,4 @@ def contacts_list_elastic_search(request): # # def get_context_data(self, *args, **kwargs): # # context = super(MarketingContactEmailSearch, self).get_context_data(*args, **kwargs) -# # import pdb; pdb.set_trace() # # return context \ No newline at end of file diff --git a/opportunity/templates/create_opportunity.html b/opportunity/templates/create_opportunity.html index 0b883f49..85d1983f 100644 --- a/opportunity/templates/create_opportunity.html +++ b/opportunity/templates/create_opportunity.html @@ -145,7 +145,7 @@ id="id_assigned_to"> {% for user in users %} {% endfor %} @@ -503,36 +503,169 @@ } } - $("#id_teams").change(function (e) { - try { - var users = [] - $('#id_teams option:selected').each(function () { - // users.push($(this).attr('data-users')) - _data = $(this).attr('data-users'); - if (!users) { - // users = [] - } else { - users = users.concat(_data.split(',')) - } - }) - // users = $('option:selected', this).attr('data-users') - // if (!users) { - // users = [] - // } else { - // users = users.split(',') - // } - console.log('selected users teams data', users) - var existingUsers = $('#id_assigned_to').val(); - var allUsers = users.concat(existingUsers) - console.log(existingUsers) - if (users.length) { - $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + function find_dict(dict, id){ + var index = dict.map(function(o) { return o.team; }).indexOf(parseInt(id)); + return dict[index]['users'] + } + $("#id_teams").change(function (e) { + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'opportunities:get_teams_and_users' %}", function(data){ + // console.log(data) + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2().trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + // console.log("s_users", selected_users) + var un_select_users = [].concat.apply([], selected_users) + // console.log('un select users', un_select_users); + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + // console.log(' selected', $(this).attr('data-users').split(',')) + // console.log('selected', $(this).attr('data-users')) + } + else { + _unselected = $(this).attr('data-users').split(',') + // console.log('un selected', $(this).attr('data-users').split(',')) + } + }); + // console.log('selected users teams data', users) + var existingUsers = $('#id_assigned_to').val(); + var allUsers = users + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); } - } catch (error) { - console.log(error) - $('#_id_assigned_to').select2().val(existingUsers).trigger('change'); - } + }) + + }); + + $(document).ready(function($) { + + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'leads:get_teams_and_users' %}", function(data){ + + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + // $('#id_assigned_to').select2().val([]).trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + var un_select_users = [].concat.apply([], selected_users) + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + // $(this).attr('disabled', 'disabled') + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + } + else { + _unselected = $(this).attr('data-users').split(',') + } + }); + var existingUsers = $('#id_assigned_to').val(); + // var allUsers = users.concat(existingUsers) + var allUsers = users + // console.log(existingUsers) + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); + } + }) }); diff --git a/opportunity/urls.py b/opportunity/urls.py index 83940957..5b78b1ac 100644 --- a/opportunity/urls.py +++ b/opportunity/urls.py @@ -4,7 +4,7 @@ from opportunity.views import ( OpportunityDetailView, update_opportunity, DeleteOpportunityView, GetContactView, GetOpportunitiesView, - AddCommentView, + AddCommentView, get_teams_and_users, UpdateCommentView, DeleteCommentView, AddAttachmentsView, DeleteAttachmentsView) @@ -31,4 +31,6 @@ urlpatterns = [ AddAttachmentsView.as_view(), name="add_attachment"), path('attachment/remove/', DeleteAttachmentsView.as_view(), name="remove_attachment"), + path('get_teams_and_users/', get_teams_and_users, + name="get_teams_and_users"), ] diff --git a/opportunity/views.py b/opportunity/views.py index 72a82f6a..66bc8059 100644 --- a/opportunity/views.py +++ b/opportunity/views.py @@ -24,6 +24,19 @@ from common.access_decorators_mixins import ( sales_access_required, marketing_access_required, SalesAccessRequiredMixin, MarketingAccessRequiredMixin) from teams.models import Teams + +@login_required +def get_teams_and_users(request): + data = {} + teams = Teams.objects.all() + teams_data = [{'team': team.id, 'users': [ + user.id for user in team.users.all()]} for team in teams] + users = User.objects.all().values_list("id", flat=True) + data['teams'] = teams_data + data['users'] = list(users) + return JsonResponse(data) + + class OpportunityListView(SalesAccessRequiredMixin, LoginRequiredMixin, TemplateView): model = Opportunity context_object_name = "opportunity_list" @@ -39,7 +52,8 @@ class OpportunityListView(SalesAccessRequiredMixin, LoginRequiredMixin, Template Q(created_by=self.request.user.id)) if self.request.GET.get('tag', None): - queryset = queryset.filter(tags__in = self.request.GET.getlist('tag')) + queryset = queryset.filter( + tags__in=self.request.GET.getlist('tag')) request_post = self.request.POST if request_post: @@ -58,7 +72,8 @@ class OpportunityListView(SalesAccessRequiredMixin, LoginRequiredMixin, Template queryset = queryset.filter( contacts=request_post.get('contacts')) if request_post.get('tag'): - queryset = queryset.filter(tags__in=request_post.getlist('tag')) + queryset = queryset.filter( + tags__in=request_post.getlist('tag')) return queryset.distinct() def get_context_data(self, **kwargs): @@ -145,7 +160,8 @@ def create_opportunity(request): # email.content_subtype = "html" # email.send() if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = opportunity_obj.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -155,9 +171,10 @@ def create_opportunity(request): opportunity_obj.teams.add(*request.POST.getlist('teams')) current_site = get_current_site(request) - recipients = list(opportunity_obj.assigned_to.all().values_list('id', flat=True)) + recipients = list( + opportunity_obj.assigned_to.all().values_list('id', flat=True)) send_email_to_assigned_user.delay(recipients, opportunity_obj.id, domain=current_site.domain, - protocol=request.scheme) + protocol=request.scheme) if request.POST.getlist('contacts', []): opportunity_obj.contacts.add( @@ -227,7 +244,8 @@ class OpportunityDetailView(SalesAccessRequiredMixin, LoginRequiredMixin, Detail user_assgn_list = [ assigned_to.id for assigned_to in context['object'].assigned_to.all()] - user_assigned_accounts = set(self.request.user.account_assigned_users.values_list('id', flat=True)) + user_assigned_accounts = set( + self.request.user.account_assigned_users.values_list('id', flat=True)) if context['object'].account: opportunity_account = set([context['object'].account.id]) else: @@ -250,11 +268,14 @@ class OpportunityDetailView(SalesAccessRequiredMixin, LoginRequiredMixin, Detail comments = context["opportunity_record"].opportunity_comments.all() if self.request.user.is_superuser or self.request.user.role == 'ADMIN': - users_mention = list(User.objects.filter(is_active=True).values('username')) + users_mention = list(User.objects.filter( + is_active=True).values('username')) elif self.request.user != context['object'].created_by: - users_mention = [{'username': context['object'].created_by.username}] + users_mention = [ + {'username': context['object'].created_by.username}] else: - users_mention = list(context['object'].assigned_to.all().values('username')) + users_mention = list( + context['object'].assigned_to.all().values('username')) context.update({ "comments": comments, @@ -298,7 +319,8 @@ def update_opportunity(request, pk): opportunity_obj = form.save(commit=False) if request.POST.get('stage') in ['CLOSED WON', 'CLOSED LOST']: opportunity_obj.closed_by = request.user - previous_assigned_to_users = list(opportunity_obj.assigned_to.all().values_list('id', flat=True)) + previous_assigned_to_users = list( + opportunity_obj.assigned_to.all().values_list('id', flat=True)) opportunity_obj.save() opportunity_obj.contacts.clear() @@ -337,7 +359,8 @@ def update_opportunity(request, pk): opportunity_obj.assigned_to.clear() if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = opportunity_obj.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -350,10 +373,12 @@ def update_opportunity(request, pk): opportunity_obj.teams.clear() current_site = get_current_site(request) - assigned_to_list = list(opportunity_obj.assigned_to.all().values_list('id', flat=True)) - recipients = list(set(assigned_to_list) - set(previous_assigned_to_users)) + assigned_to_list = list( + opportunity_obj.assigned_to.all().values_list('id', flat=True)) + recipients = list(set(assigned_to_list) - + set(previous_assigned_to_users)) send_email_to_assigned_user.delay(recipients, opportunity_obj.id, domain=current_site.domain, - protocol=request.scheme) + protocol=request.scheme) if request.POST.getlist('contacts', []): opportunity_obj.contacts.add( @@ -480,7 +505,7 @@ class AddCommentView(LoginRequiredMixin, CreateView): comment_id = comment.id current_site = get_current_site(self.request) send_email_user_mentions.delay(comment_id, 'opportunity', domain=current_site.domain, - protocol=self.request.scheme) + protocol=self.request.scheme) return JsonResponse({ "comment_id": comment.id, "comment": comment.comment, "commented_on": comment.commented_on, @@ -514,7 +539,7 @@ class UpdateCommentView(LoginRequiredMixin, View): comment_id = self.comment_obj.id current_site = get_current_site(self.request) send_email_user_mentions.delay(comment_id, 'opportunity', domain=current_site.domain, - protocol=self.request.scheme) + protocol=self.request.scheme) return JsonResponse({ "commentid": self.comment_obj.id, "comment": self.comment_obj.comment, diff --git a/requirements.txt b/requirements.txt index 68dd34e0..99b769f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -django==2.2.10 +django==2.2.4 celery==4.3.0 django-simple-pagination==1.3 django-compressor==2.3 @@ -26,4 +26,4 @@ codacy-coverage==1.3.11 django-haystack==2.8.0 elasticsearch==2.3 python-memcached==1.59 -boto +boto \ No newline at end of file diff --git a/static/css/main.scss b/static/css/main.scss index d9b9343f..2550cd1f 100644 --- a/static/css/main.scss +++ b/static/css/main.scss @@ -1,23 +1,22 @@ @import "ref.scss"; -*{ - font-family: 'Quicksand', sans-serif; +* { + font-family: "Quicksand", sans-serif; } body { - font-family: 'Quicksand', sans-serif; + font-family: "Quicksand", sans-serif; padding: 0; font-weight: 500; margin: 0; font-size: 14px; background: #f7f7f9; - @media(min-width:$large){ - font-size:17px; + @media (min-width: $large) { + font-size: 17px; } - @media(min-width: $mob_min) and (max-width: $smob_max){ + @media (min-width: $mob_min) and (max-width: $smob_max) { padding-top: 50px; } } .login_register_body { - } /**{ font-size: 15px; @@ -25,15 +24,15 @@ body { font-size:17px; } }*/ -.no_mar_top{ - margin-top:0 !important; -} +.no_mar_top { + margin-top: 0 !important; +} .marl { margin-left: 0; margin-right: 0; } -.no-padding{ - padding:0; +.no-padding { + padding: 0; } .login_row { } @@ -52,50 +51,51 @@ body { } } } -a{ - &:hover{ - text-decoration:none; +a { + &:hover { + text-decoration: none; } } -.anchor{ - color: darken($text_color, 15%)!important; +.anchor { + color: darken($text_color, 15%) !important; } .login_form_block { - margin-top: 30px; - padding:50px 15px; - .welcome{ - margin-bottom: 20px; - text-align: center; - } - .forgot{ + margin-top: 30px; + padding: 50px 15px; + .welcome { + margin-bottom: 20px; + text-align: center; + } + .forgot { + font-size: 13px; + display: block; + color: darken($text_color2, 15%); + a { + display: inline-block; + color: $dark_sky; + margin-bottom: 10px; font-size: 13px; - display: block; - color: darken($text_color2, 15%); - a{ - display: inline-block; - color: $dark_sky; - margin-bottom: 10px; - font-size: 13px; - } } + } .form-group { margin-bottom: 15px; } - .errorlist li{ + .errorlist li { color: red; font-size: 0.83rem; } label { font-size: 14px; color: darken($text_color2, 15%); - font-weight:500; + font-weight: 500; } - .form-control, input { + .form-control, + input { color: $text_color; min-height: 40px; font-size: 13px; letter-spacing: 0.5px; - border:1px solid #ddd; + border: 1px solid #ddd; //Instead of the line below you could use @include box-shadow($shadow-1, $shadow-2, $shadow-3, $shadow-4, $shadow-5, $shadow-6, $shadow-7, $shadow-8, $shadow-9, $shadow-10) box-shadow: none; //Instead of the line below you could use @include border-radius($radius, $vertical-radius) @@ -109,15 +109,15 @@ a{ font-weight: 600; color: $white; width: 100%; - outline:none; + outline: none; padding: 10px 20px; - &:hover{ - text-decoration:none; + &:hover { + text-decoration: none; } } - .checkbox{ + .checkbox { text-align: center; - input[type=checkbox]{ + input[type="checkbox"] { vertical-align: middle; margin: 0; margin-top: 1px; @@ -126,16 +126,15 @@ a{ } } - /* inner_pages starts here */ /*.main_body_bg_color{ background: #fff; }*/ -.primary_btn{ +.primary_btn { background: $login_btn_bg; color: #fff; - border:none; + border: none; font-size: 0.9rem; font-weight: 500; text-transform: capitalize; @@ -144,138 +143,136 @@ a{ border-radius: 3px; padding: 2px 10px; line-height: 1.5rem; - bordeR: none; + border: none; cursor: pointer; - &:hover{ + &:hover { background: darken($login_btn_bg, 10%); color: #fff; } - @media(min-width:$large){ - font-size:1rem; - svg{ + @media (min-width: $large) { + font-size: 1rem; + svg { position: relative; top: 0px; } } - svg{ + svg { display: inline-block; margin-right: 5px; } } -.secondary_btn{ +.secondary_btn { @extend .primary_btn; background: $blue; - &:hover{ + &:hover { background: darken($blue, 10%); } } -.tertiary_btn{ - +.tertiary_btn { } -header{ - .navbar{ +header { + .navbar { background: #fff; - border:none; - border:1px solid #ddd; - padding:0 15px; - @media(min-width: $mob_min) and (max-width: $smob_max){ + border: none; + border: 1px solid #ddd; + padding: 0 15px; + @media (min-width: $mob_min) and (max-width: $smob_max) { padding: 5px 15px; } - .navbar-brand{ + .navbar-brand { color: darken($text_color, 10%); font-weight: 600; margin-right: 50px; - &:hover{ + &:hover { color: $login_btn_bg; } } - .navbar-toggler{ - svg{ + .navbar-toggler { + svg { color: #333; } } - .navbar-nav{ - .nav-item{ - a{ - color: lighten($text_color,5%) !important; + .navbar-nav { + .nav-item { + a { + color: lighten($text_color, 5%) !important; font-weight: 500; font-size: 0.9rem; - padding:10px 15px; + padding: 10px 15px; display: inline-block; padding-top: 16px; border-bottom: 3px solid #fff; - @media(min-width: $mob_min) and (max-width: $smob_max) { - padding:5px 10px; + @media (min-width: $mob_min) and (max-width: $smob_max) { + padding: 5px 10px; } - @media(min-width:$large){ - font-size:1rem; + @media (min-width: $large) { + font-size: 1rem; } - &:hover{ - color:darken($text_color,5%) !important; + &:hover { + color: darken($text_color, 5%) !important; border-bottom: 3px solid $dark_sky; } - &.active{ - color:darken($text_color,5%) !important; + &.active { + color: darken($text_color, 5%) !important; border-bottom: 3px solid $dark_sky; } } } - .open{ - a{ + .open { + a { background: $login_btn_bg !important; - } } - li{ - .dropdown-toggle{ - img{ + li { + .dropdown-toggle { + img { + width: 25px; + height: 25px; + } + } + .dropdown-menu { + padding: 0; + a { + font-size: 0.9rem; + padding: 8px 10px; + color: darken($text_color, 5%); + border: none !important; + svg { + display: inline-block; + margin-right: 5px; + font-size: 0.75rem; + } + @media (min-width: $large) { + font-size: 0.95rem; + } + &:hover { + border: none !important; + } + } + } + } + &.navbar-right { + .dropdown { + .dropdown-toggle { + img { width: 25px; height: 25px; } } - .dropdown-menu{ - padding:0; - a{ - font-size: 0.9rem; - padding:8px 10px; - color: darken($text_color,5%); - border:none !important; - svg{ - display: inline-block; - margin-right: 5px; - font-size: 0.75rem; - } - @media(min-width:$large){ - font-size:0.95rem; - } - &:hover{ - border:none !important; - } - } - } - } - &.navbar-right{ - .dropdown{ - .dropdown-toggle{ - img{ - width: 25px; - height: 25px; - } - } - a{ + a { color: #fff; - &.nav-link{ - padding:11px 15px; - border-bottom:3px solid #fff; + &.nav-link { + padding: 11px 15px; + border-bottom: 3px solid #fff; + } + &:hover { + color: darken($text_color, 5%) !important; + border-bottom: 3px solid $dark_sky; } - &:hover{ - color:darken($text_color,5%) !important; - border-bottom: 3px solid $dark_sky; - } } } } - /* li{ + /* li{ a{ &:hover{ color:lighten($text_color,15%); @@ -283,26 +280,26 @@ header{ } }*/ } - .navbar-form{ - .form-group{ - .form-control{ - border-radius:3px; - border:none; + .navbar-form { + .form-group { + .form-control { + border-radius: 3px; + border: none; } } - .btn{ - border-radius:3px; - padding:7px 12px; - border:none; + .btn { + border-radius: 3px; + padding: 7px 12px; + border: none; background: $green; - &.btn-default{ + &.btn-default { color: #fff; } } } } } -/* inner_pages ends here */ +/* inner_pages ends here */ /* CSS used here will be applied after bootstrap.css */ $color_1: #ff7788; @@ -314,8 +311,8 @@ $color_2: #000; .notifications { min-width: 420px; font-size: 12px; - padding:0; - border:none; + padding: 0; + border: none; a.content { text-decoration: none; background: #ccc; @@ -338,12 +335,12 @@ $color_2: #000; } .notification-heading { padding: 2px 10px; - background:lighten($text_color,5%); - border-top:1px solid lighten($text_color,10%); + background: lighten($text_color, 5%); + border-top: 1px solid lighten($text_color, 10%); } .notification-footer { padding: 2px 10px; - background:$green; + background: $green; } .dropdown-menu.divider { margin: 5px 0; @@ -351,14 +348,14 @@ $color_2: #000; .item-title { font-size: 12px; color: darken($text_color, 15%); - margin:0; + margin: 0; } .notification-item { padding: 10px; margin: 5px; background: #ccc; border-radius: 4px; - p{ + p { margin: 0; color: #fff; margin-top: 6px; @@ -366,217 +363,230 @@ $color_2: #000; } /* main_container stats here */ -.main_container{ +.main_container { padding-top: 0; - .heading_create{ - .heading{ + .heading_create { + .heading { font-size: 1.1rem; text-transform: uppercase; letter-spacing: 1px; color: darken($text_color, 15%); - h4{ + h4 { font-size: 1.1rem; - font-weight: 800; + font-weight: 800; } } - - .search-row{ - .form-group{ - .input-group{ - .left-dropdown{ - .filters-button{ + + .search-row { + .form-group { + .input-group { + .left-dropdown { + .filters-button { font-size: 12px; background: #fff; - border:none; - box-shadow:none; - margin-top:1px; + border: none; + box-shadow: none; + margin-top: 1px; } - .dropdown-menu{ - li{ - a{ + .dropdown-menu { + li { + a { font-size: 12px; } - &.checkbox{ + &.checkbox { color: #000; - padding-left:10px; + padding-left: 10px; font-size: 12px; letter-spacing: 0.4px; - input[type=checkbox]{ - margin:0; - margin-left:-10px; - margin-top:1px; - margin-right:10px; + input[type="checkbox"] { + margin: 0; + margin-left: -10px; + margin-top: 1px; + margin-right: 10px; } } } } } - .form-control{ + .form-control { height: 29px; border: none; margin-top: 2px; } - .search{ + .search { background: $green; color: #fff; - border:none; - padding:5px 13px; - margin-top:2px; + border: none; + padding: 5px 13px; + margin-top: 2px; } } } - .extra_option_btn{ + .extra_option_btn { font-size: 12px; background: #5b636e; - border:none; - color:#fff; - padding-top:7px; + border: none; + color: #fff; + padding-top: 7px; padding-bottom: 7px; - &.add-filter-button{ + &.add-filter-button { background-color: $dark_sky; } } - .dropdown-menu{ + .dropdown-menu { font-size: 12px; } } } - /* filter_row starts here */ - .filter_row{ - margin-top:10px; - .card{ - border:1px solid #ccc; - .card-body{ - padding:0px 0; - .card-title{ + .filter_row { + margin-top: 10px; + .card { + border: 1px solid #ccc; + .card-body { + padding: 0px 0; + .card-title { background: #e5e5e5; - padding:6px 10px; + padding: 6px 10px; font-weight: 600; font-size: 1rem; } - .form-group{ + .form-group { margin-bottom: 10px; - label{ + label { color: black; font-size: 0.85rem; font-weight: 600; text-transform: none; } - .form-control{ + .form-control { border-radius: 0; box-shadow: none; font-size: 0.85rem; } - &.buttons_row{ + &.buttons_row { margin-top: 30px; } } } } - .table_container_row{ + .table_container_row { margin-top: 0; } } /* filter_row ends here */ /* table_container_row starts here */ - } -/* main_container ends here */ - .table_container_row{ - margin-top: 10px; - .card{ - border: none; - border-radius: 0; - box-shadow: none; - .card-title{ - padding:5px 10px !important; - background: #e5e5e5; - font-size: 1rem; - margin-bottom: 0; - font-weight: 600; - line-height: 2.3rem; - &.title_lh{ - line-height: 2rem; - } - .dropdown{ - display: inline-block; - .dropdown-toggle{ - background: $dark_sky; - font-size: 12px; - color:#fff; - border-radius: 0; - border:none; - } - } - .mark_read{ - background: $inner_page_bg; - display: inline-block; - padding:6px 10px; - margin-left:6px; - color: $text_color; - &:hover{ - background:$text_color; - color: #fff; - text-decoration: none; - } - } - .total_count{ - margin-top:0px; +.remove_tag { + position: relative; +} +.remove_tag .fa-times { + color: #000 !important; + position: absolute; + background: #fff; + top: -6px; + padding: 1px; + border-radius: 50%; + font-size: 0.6rem; + height: 10px; + width: 10px; + border: 1px solid #000; +} +/* main_container ends here */ +.table_container_row { + margin-top: 10px; + .card { + border: none; + border-radius: 0; + box-shadow: none; + .card-title { + padding: 5px 10px !important; + background: #e5e5e5; + font-size: 1rem; + margin-bottom: 0; + font-weight: 600; + line-height: 2.3rem; + &.title_lh { + line-height: 2rem; + } + .dropdown { + display: inline-block; + .dropdown-toggle { + background: $dark_sky; + font-size: 12px; + color: #fff; + border-radius: 0; + border: none; } } - .card-body{ - padding:0px 0px; - table{ + .mark_read { + background: $inner_page_bg; + display: inline-block; + padding: 6px 10px; + margin-left: 6px; + color: $text_color; + &:hover { + background: $text_color; + color: #fff; + text-decoration: none; + } + } + .total_count { + margin-top: 0px; + } + } + .card-body { + padding: 0px 0px; + table { border: none; margin-bottom: 0; - thead{ - tr{ - th{ + thead { + tr { + th { color: #454545; font-weight: 900; font-size: 0.9rem; border: none; text-align: left; - padding:6px; + padding: 6px; border-bottom: 1px solid darken(#f7f7f9, 2%); } } } - tbody{ - tr{ - td{ + tbody { + tr { + td { vertical-align: middle; color: #454545; font-size: 0.83rem; text-align: left; font-weight: 500; - padding:7px 5px; + padding: 7px 5px; border-bottom: 1px solid darken(#f7f7f9, 2%); - @media(min-width: $large){ - font-size:1rem; + @media (min-width: $large) { + font-size: 1rem; } - a{ - color: lighten($dark_sky,5%); + a { + color: lighten($dark_sky, 5%); font-size: 0.85rem; - &:hover{ - color:$dark_sky; + &:hover { + color: $dark_sky; text-decoration: underline; } } - .dropdown{ - .dropdown-toggle{ + .dropdown { + .dropdown-toggle { background: $dark_sky; font-size: 12px; - color:#fff; + color: #fff; border-radius: 0; - border:none; - } + border: none; + } } - &.actions{ - a{ - &.box{ + &.actions { + a { + &.box { @extend .box; line-height: 1.5rem; width: 1.65rem; @@ -590,22 +600,22 @@ $color_2: #000; } } } - + /* mail_menu starts here */ - .mail_menu{ - .panel{ + .mail_menu { + .panel { border-radius: 0; - padding:0; - background:none; - border:0; - .panel-content{ - padding:0; - .mail_options{ - margin:0; + padding: 0; + background: none; + border: 0; + .panel-content { + padding: 0; + .mail_options { + margin: 0; padding: 0; - li{ - list-style:none; - a{ + li { + list-style: none; + a { display: block; padding: 10px; background: $text_color; @@ -613,16 +623,16 @@ $color_2: #000; color: white; text-transform: uppercase; letter-spacing: 0.6px; - &:hover{ - background:$green; + &:hover { + background: $green; color: #fff; text-decoration: none; border-left: 3px solid white; } } - &.active{ - a{ - background:$green; + &.active { + a { + background: $green; color: #fff; text-decoration: none; border-left: 3px solid white; @@ -634,111 +644,111 @@ $color_2: #000; } } /* mail_menu ends here */ - } - /* table_container_row ends here */ -/* breadcrumb starts here */ -.breadcrumb{ - margin:0; - padding:0 15px; - background: none; - .breadcrumb-item{ - a{ - color: $dark_sky; - } - } } -.breadcrumb li+li:before{ - color:$text_color; +/* table_container_row ends here */ +/* breadcrumb starts here */ +.breadcrumb { + margin: 0; + padding: 0 15px; + background: none; + .breadcrumb-item { + a { + color: $dark_sky; + } + } +} +.breadcrumb li + li:before { + color: $text_color; } /* breadcrumb ends here */ /* assigned_teams starts here */ -.assigned_teams{ +.assigned_teams { @extend .filter_row; - margin-top:0; + margin-top: 0; } -/* assigned_teams ends here */ +/* assigned_teams ends here */ /* overview_form_block starts here */ -.overview_form_block{ +.overview_form_block { @extend .filter_row; - .card-title{ + .card-title { min-height: 36px; padding: 8px 10px !important; - h5{ + h5 { margin-bottom: 0; position: relative; font-size: 1rem; font-weight: 600; - .title{ + .title { position: relative; top: 2px; } } - .dropdown{ - .dropdown-menu{ - li{ - a{ + .dropdown { + .dropdown-menu { + li { + a { font-size: 0.85rem; color: #454545; text-transform: capitalize !important; font-weight: 400; display: block; - padding:5px 8px; + padding: 5px 8px; } } } } } - .buttons_row{ - margin:0; + .buttons_row { + margin: 0; position: relative; } - .form-control{ + .form-control { border-radius: 0; box-shadow: none; font-size: 0.85rem; } - margin-top:0; - .country_class{ - margin-top:10px; + margin-top: 0; + .country_class { + margin-top: 10px; } - .shiiping_block{ - margin-top:10px; - .checkbox{ + .shiiping_block { + margin-top: 10px; + .checkbox { color: $text_color; } } - .filters-button{ + .filters-button { border-radius: 0; } - .website_block{ - margin-top:10px; + .website_block { + margin-top: 10px; } - .search{ + .search { border-radius: 0; } - .copy_billing_btn{ - margin-top:10px; + .copy_billing_btn { + margin-top: 10px; display: block; } } /* overview_form_block ends here */ /* details_block starts here */ -.details_block{ +.details_block { @extend .filter_row; - .form-control{ + .form-control { border-radius: 0; box-shadow: none; font-size: 12px; } } -.buttons_row{ +.buttons_row { margin-bottom: 0px; - button{ + button { border-radius: 0; font-size: 0.85rem; font-weight: 600; - &.save{ + &.save { background: $dark_sky; color: #fff; } @@ -746,31 +756,30 @@ $color_2: #000; } /* details_block ends here */ /* attendees starts here */ -.attendees{ +.attendees { @extend .filter_row; } /* attendees ends here */ - - -.case-list-container{ +.case-list-container { margin-bottom: 15px; } -.profile_pic{ +.profile_pic { text-align: center; - img{ + img { width: 5rem; height: 5rem; border-radius: 50%; } } -.error, .errors { +.error, +.errors { color: red; } -.required_color{ +.required_color { color: red; } @@ -779,10 +788,10 @@ $color_2: #000; padding: 0px; } -.view-pad{ -padding:0px !important; - h5{ - width: 90%; +.view-pad { + padding: 0px !important; + h5 { + width: 90%; margin-bottom: 0; position: relative; font-size: 1rem; @@ -791,102 +800,101 @@ padding:0px !important; text-align: left; padding-top: 0px; } - a{ + a { float: right; border-radius: 0; font-size: 1rem; padding: 3px 10px; color: #fff; margin-top: -4px; - &:hover{ - text-decoration:none; + &:hover { + text-decoration: none; } } - } -.select2-container{ +.select2-container { width: 100% !important; border-radius: 0; border: 1px solid #ced4da; } -.select2-container--default .select2-selection--multiple{ +.select2-container--default .select2-selection--multiple { border-radius: 0 important; border: none !important; } -.select2-container--open{ +.select2-container--open { width: inherit !important; display: block !important; } -.created_information{ +.created_information { padding-left: 15px; - margin:10px 0; + margin: 10px 0; } -.pagination{ - li{ - a{ +.pagination { + li { + a { padding: 5px 10px; border: 1px solid #ddd; font-weight: 600; - } - .active{ - background: #369cbe; - padding: 5px 10px; - border: 1px solid #369cbe; - color: #fff; - } } + .active { + background: #369cbe; + padding: 5px 10px; + border: 1px solid #369cbe; + color: #fff; + } + } } .text-center { - justify-content: center!important; + justify-content: center !important; } .pull-right { float: right; } .credentials { - border: 1px solid; - width: 309px; - border: 6px solid #040404; - padding: 30px 0; - text-align: center; - position: relative; - margin-top: 6rem; + border: 1px solid; + width: 309px; + border: 6px solid #040404; + padding: 30px 0; + text-align: center; + position: relative; + margin-top: 6rem; } -.credentials .heading{ +.credentials .heading { position: absolute; display: inline-block; top: -15px; left: 17%; background: #333; color: #fff; - padding:3px 10px; + padding: 3px 10px; border-radius: 3px; } -.filter_toggle{ +.filter_toggle { cursor: pointer; position: relative; top: 1px; - @media(min-width: $large){ + @media (min-width: $large) { top: 2px; } - a{ + a { line-height: 1.6rem; } - svg{ + svg { margin-right: 0; } } -.list_filter_row{ +.list_filter_row { display: none; } -.form_btn_row{ +.form_btn_row { margin-bottom: 1rem !important; } -#list_tag{ +#list_tag { color: #fff; border: none; background: #333; @@ -897,222 +905,221 @@ padding:0px !important; display: inline-block; margin-bottom: 5px; border-radius: 2px; - &.color1{ + &.color1 { background: darken($dark_sky, 5%); } - &.red{ + &.red { background: darken($color_cerise_red_approx, 5%); } - &.green{ + &.green { background: darken($green, 5%); } - &.color2{ + &.color2 { background: darken($dark_yellow, 10%); } - &.color3{ + &.color3 { background: darken($color_cerise_red_approx, 1%); } - &.color4{ + &.color4 { background: darken($dark_yellow, 40%); } - &.color5{ + &.color5 { background: darken($dark_sky, 30%); } - &.color6{ + &.color6 { background: darken($green, 1%); } - &.color7{ + &.color7 { background: blueviolet; } - &.color8{ - background:#a2866f; + &.color8 { + background: #a2866f; } - &.color9{ + &.color9 { background: cadetblue; } - &.color10{ + &.color10 { background: cornflowerblue; } - &.color11{ + &.color11 { background: dodgerblue; } - &.color12{ + &.color12 { background: blue; } - &.color13{ + &.color13 { background: coral; } - &.color14{ - background:crimson; + &.color14 { + background: crimson; } - &.color15{ + &.color15 { background: darkgoldenrod; } } -.nav-tabs{ - li{ - &.nav-item{ - a{ - &.nav-link{ +.nav-tabs { + li { + &.nav-item { + a { + &.nav-link { background: lighten($color_blue_dianne_approx, 45%); color: #fff; font-size: 0.83rem; font-weight: 600; } - &.active{ + &.active { background: $info_color; } } } } } -.account_field{ +.account_field { font-size: 0.83rem; } -.contact_field{ +.contact_field { font-size: 0.83rem; } -.lead_field{ +.lead_field { font-size: 0.83rem; } -.opportunity_field{ +.opportunity_field { font-size: 0.83rem; } -.form-control-file{ +.form-control-file { font-size: 0.83rem; } -.case_field{ +.case_field { font-size: 0.83rem; } -pre{ +pre { margin-bottom: 0.5rem; - a{ - + a { } } -#comments_div{ - .list-group-item{ +#comments_div { + .list-group-item { margin-bottom: 0.75rem; border: none; background: #f5f5f5; position: relative; - .list-row-buttons{ + .list-row-buttons { position: absolute; top: 0; right: 0; - .primary_btn{ + .primary_btn { border-radius: 0; } - .dropdown-menu{ + .dropdown-menu { padding: 0; border-radius: 0; - li{ - a{ + li { + a { padding: 8px 8px; display: block; text-align: left; font-size: 0.83rem; - border-bottom: 1px solid #dedede; + border-bottom: 1px solid #dedede; } } } } - .stream-post-container{ - pre{ + .stream-post-container { + pre { font-weight: 600; - a{ + a { font-size: 0.83rem; } } } - .stream-container{ - .date{ + .stream-container { + .date { font-size: 0.83rem; - color: lighten($text_color,10%); + color: lighten($text_color, 10%); } } } } -#attachment_div{ +#attachment_div { @extend #comments_div; } -.bootstrap-datetimepicker-widget{ +.bootstrap-datetimepicker-widget { display: block !important; } -.count_blocks_row{ +.count_blocks_row { margin-top: 2rem; - .item{ + .item { background: #fff; border-radius: 0; - padding:0; + padding: 0; border: none; text-align: center; - .title{ + .title { line-height: 2.5rem; font-weight: 600; font-size: 0.85rem; color: #fff; text-transform: uppercase; - a{ + a { color: #fff; } } - .count{ + .count { font-size: 2rem; font-weight: 600; padding: 0.5rem 0; color: #fff; } - .more{ + .more { font-size: 0.85rem; - a{ + a { color: #fff; display: block; font-weight: 600; padding: 0.35rem; background: darken($color_cyan_aqua_approx, 10%); } - &.green{ - a{ + &.green { + a { background: darken($color_apricot_peach_approx, 10%); } } - &.blue{ - a{ + &.blue { + a { background: darken($color_blue_dianne_approx, 10%); } } - &.red{ - a{ + &.red { + a { background: darken($color_cerise_red_approx, 10%); } } } - &.sky_blue{ + &.sky_blue { background: darken($dark_sky, 10%); } - &.red{ + &.red { background: darken($color_cerise_red_approx, 10%); } - &.green{ + &.green { background: darken($green, 5%); } - &.yellow{ + &.yellow { background: darken($dark_yellow, 10%); } } } /* open_sections */ -.open_sections{ +.open_sections { margin-top: 1.5rem; - .table_container_row{ - .table{ + .table_container_row { + .table { margin-bottom: 0; - tbody{ - tr{ - td{ - a{ + tbody { + tr { + td { + a { color: #333; font-weight: 600; } @@ -1122,15 +1129,15 @@ pre{ } } } -.errorlist{ - li{ +.errorlist { + li { font-size: 0.83rem; } } /* marketing_pages */ -.side_menu{ +.side_menu { background: #fff; position: fixed; left: 0; @@ -1138,86 +1145,86 @@ pre{ top: 0; height: 100%; border: none; - .logo_block{ - a{ + .logo_block { + a { display: block; - padding:0.75rem 1rem; + padding: 0.75rem 1rem; color: #000; font-size: 1.35rem; font-weight: 800; - .green_color{ + .green_color { color: $green; } } } - .profile_block{ + .profile_block { margin-top: 0.5rem; - ul{ + ul { margin: 0; padding: 0; padding-left: 1rem; - li{ + li { list-style: none; display: inline-block; margin-right: 3px; - a{ - &.profile_pic{ - img{ + a { + &.profile_pic { + img { width: 2rem; height: 2rem; border-radius: 3px; } } - &.box{ + &.box { @extend .box; } } } - } + } } - .menu_block{ - .main_menu{ + .menu_block { + .main_menu { margin-top: 1.5rem; padding: 0; padding-left: 1rem; - li{ + li { list-style: none; - a{ + a { font-size: 0.83rem; font-size: 400; transition: 0.6s all ease-out; - svg{ + svg { display: inline-block; margin-right: 0.5rem; font-size: 1.1rem; } } - &.parent_menu{ + &.parent_menu { margin: 0; padding: 0; margin-bottom: 0.5rem; list-style: none; - a{ + a { display: inline-block; color: $text_color; padding-top: 0.35rem; padding-bottom: 0.35rem; transition: 0.6s all ease-out; - &.red{ + &.red { color: $red; } - &.green{ + &.green { color: $green; } - &.purple{ + &.purple { color: $purple; } } - .submenu{ + .submenu { padding-left: 1.6rem; margin-top: 0.3rem; position: relative; - &::before{ + &::before { content: ""; height: 100%; background: lighten($text_color, 40%); @@ -1225,30 +1232,30 @@ pre{ position: absolute; left: 0.5rem; } - li{ - a{ + li { + a { transition: 0.6s all ease-out; - &.yellow{ - svg{ + &.yellow { + svg { color: $dark_yellow; } - &:hover{ + &:hover { color: $dark_yellow; } } - &.d_green{ - svg{ + &.d_green { + svg { color: $d_green; } - &:hover{ - color: $d_green ; + &:hover { + color: $d_green; } } - &.sky_color{ - svg{ + &.sky_color { + svg { color: $sky_color; } - &:hover{ + &:hover { color: $sky_color; } } @@ -1259,45 +1266,45 @@ pre{ } } } -} -/* side_menu */ -.marketing_pages{ +} +/* side_menu */ +.marketing_pages { margin-left: 250px; margin-bottom: 1rem; margin-top: 2rem; } -.badge{ +.badge { width: auto !important; height: auto !important; font-size: 100%; border-radius: 10rem; display: inline-block; - padding: .05rem 1rem; + padding: 0.05rem 1rem; } -.a_color{ +.a_color { color: $text_color !important; font-weight: 600; } -.tooltip-inner{ +.tooltip-inner { font-size: 0.8rem; } #editor-container { height: 30rem; } -.mar_btm{ +.mar_btm { margin-bottom: 1rem; } -.radio_col{ +.radio_col { font-size: 0.83rem; margin-bottom: 0.6rem; - .radio_span{ + .radio_span { margin-right: 1rem; font-size: 0.83rem; } } -.well{ +.well { background: #efefef; padding: 10px; font-size: 0.83rem; @@ -1305,7 +1312,6 @@ pre{ margin-bottom: 0.5rem; } - .example .btn-toggle { top: 50%; transform: translateY(-50%); @@ -1341,11 +1347,11 @@ pre{ transition: opacity 0.25s; } .btn-toggle:before { - content: 'Off'; + content: "Off"; left: -4rem; } .btn-toggle:after { - content: 'On'; + content: "On"; right: -4rem; opacity: 0.5; } @@ -1418,11 +1424,11 @@ pre{ transition: opacity 0.25s; } .btn-toggle.btn-lg:before { - content: 'Off'; + content: "Off"; left: -5rem; } .btn-toggle.btn-lg:after { - content: 'On'; + content: "On"; right: -5rem; opacity: 0.5; } @@ -1447,100 +1453,100 @@ pre{ opacity: 0.5; } -.hint{ +.hint { font-size: 0.83rem; } -.help_container{ - .heading{ +.help_container { + .heading { font-size: 1.1rem; font-weight: 600; color: darken($text_color, 25%); } - .desc{ + .desc { font-size: 0.83rem; } - ul{ + ul { margin: 0; padding: 0; - li{ + li { list-style: none; margin-bottom: 1rem; - strong{ + strong { display: block; } - code{ + code { font-size: 0.83rem; } } } } -.campaign_det{ - .title{ +.campaign_det { + .title { font-size: 0.83rem; - .content{ + .content { font-size: 0.83rem; } - .icon{ - svg{ + .icon { + svg { font-size: 0.7rem; margin-left: 0.5rem; } } } - .subject{ + .subject { font-weight: bold; - margin:0.4rem 0; + margin: 0.4rem 0; color: darken($text_color, 20%); - .icon{ - svg{ + .icon { + svg { font-size: 0.7rem; margin-left: 0.5rem; } } - a{ + a { font-size: 0.83rem; color: darken($text_color, 20%); - .content{ + .content { font-size: 0.83rem; color: darken($text_color, 20%); } } } - .recievers{ - .badge{ + .recievers { + .badge { font-size: 0.83rem; font-weight: 500; } } } -.count_status{ +.count_status { margin: 1rem 0; - .well{ - .badge{ + .well { + .badge { font-size: 0.83rem !important; } - .label{ + .label { font-size: 0.83rem; font-weight: bold; } } } -.mar_right_0{ - margin-right: 0!important; +.mar_right_0 { + margin-right: 0 !important; } -.demo_clist{ - a{ +.demo_clist { + a { font-size: 0.83rem; color: darken($text_color, 15%); font-weight: 600; text-decoration: underline !important; } } -.table_det_section{ +.table_det_section { margin-bottom: 1rem; - .heading{ + .heading { font-size: 1.3rem; font-weight: 600; } @@ -1552,13 +1558,14 @@ pre{ padding: 10px; } -.help-text{ +.help-text { font-size: 12px; color: #a7a7a7a7; } .actions { - .edit, .delete { + .edit, + .delete { svg { path { fill: white; @@ -1567,20 +1574,20 @@ pre{ } } -.btn-danger{ +.btn-danger { background-color: #ffc107; border-color: #ffc107; - color: #fff!important; + color: #fff !important; } -.btn-success{ - color: #fff!important; +.btn-success { + color: #fff !important; background-color: #099cbe; border-color: #099cbe; } -.btn-info{ - color: #fff!important; - background: #28a745; - border-color: #35a745; +.btn-info { + color: #fff !important; + background: #28a745; + border-color: #35a745; } diff --git a/tasks/templates/task_create.html b/tasks/templates/task_create.html index bb0294c0..2a50e138 100644 --- a/tasks/templates/task_create.html +++ b/tasks/templates/task_create.html @@ -137,7 +137,7 @@ @@ -217,36 +217,170 @@ } }); - $("#id_teams").change(function (e) { - try { - var users = [] - $('#id_teams option:selected').each(function () { - // users.push($(this).attr('data-users')) - _data = $(this).attr('data-users'); - if (!users) { - // users = [] - } else { - users = users.concat(_data.split(',')) - } - }) - // users = $('option:selected', this).attr('data-users') - // if (!users) { - // users = [] - // } else { - // users = users.split(',') - // } - console.log('selected users teams data', users) - var existingUsers = $('#id_assigned_to').val(); - var allUsers = users.concat(existingUsers) - console.log(existingUsers) - if (users.length) { - $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + function find_dict(dict, id){ + var index = dict.map(function(o) { return o.team; }).indexOf(parseInt(id)); + return dict[index]['users'] + } + $("#id_teams").change(function (e) { + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'leads:get_teams_and_users' %}", function(data){ + // console.log(data) + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2().trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + // console.log("s_users", selected_users) + var un_select_users = [].concat.apply([], selected_users) + // console.log('un select users', un_select_users); + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + // console.log(' selected', $(this).attr('data-users').split(',')) + // console.log('selected', $(this).attr('data-users')) + } + else { + _unselected = $(this).attr('data-users').split(',') + // console.log('un selected', $(this).attr('data-users').split(',')) + } + }); + // console.log('selected users teams data', users) + var existingUsers = $('#id_assigned_to').val(); + var allUsers = users + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); } - } catch (error) { - console.log(error) - $('#_id_assigned_to').select2().val(existingUsers).trigger('change'); - } + }) + + }); + + $(document).ready(function($) { + + var teams = [] + var all_users = [] + var selected_teams = [] + var selected_users = [] + var assigned_users = [] + $.get("{% url 'leads:get_teams_and_users' %}", function(data){ + + if(($('#id_teams').val()).length==0){ + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + // $('#id_assigned_to').select2().val([]).trigger('change'); + + } + + teams = data['teams'] + all_users = data['users'] + try { + var users = [] + $('#id_teams option:selected').each(function () { + // users.push($(this).attr('data-users')) + _data = $(this).attr('data-users'); + selected_teams.push($(this).val()) + selected_users.push(find_dict(teams, $(this).val())) + var un_select_users = [].concat.apply([], selected_users) + + + $('#id_assigned_to option').each(function () { + if($.inArray(parseInt($(this).val()), un_select_users) != -1){ + // $(this).attr('disabled', 'disabled') + $(this).attr('disabled', 'disabled') + $('#id_assigned_to').select2(); + + } + else{ + $(this).show() + $(this).removeAttr('disabled') + $('#id_assigned_to').select2(); + + } + } + ) + + + if (!selected_teams) { + users = [] + $('#id_assigned_to option').each(function () { + $(this).removeAttr('disabled') + }) + $('#id_assigned_to').select2(); + } else { + users = users.concat(_data.split(',')) + } + }); + $('#id_teams option').each(function () { + if ($(this).is(':selected')) { + _data = $(this).attr('data-users').split(',') + } + else { + _unselected = $(this).attr('data-users').split(',') + } + }); + var existingUsers = $('#id_assigned_to').val(); + // var allUsers = users.concat(existingUsers) + var allUsers = users + // console.log(existingUsers) + $('#_id_assigned_to').select2().val(allUsers).trigger('change'); + if (users.length) { + + } + } catch (error) { + console.log(error) + $('#_id_assigned_to').select2().val([]).trigger('change'); + } + }) }); diff --git a/tasks/templates/task_detail.html b/tasks/templates/task_detail.html index a1b45263..b73c73d7 100644 --- a/tasks/templates/task_detail.html +++ b/tasks/templates/task_detail.html @@ -35,8 +35,10 @@
@@ -465,4 +467,4 @@ } }) -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/tasks/templates/tasks_tasks_list.html b/tasks/templates/tasks_tasks_list.html index cb1c06b9..88bc59db 100644 --- a/tasks/templates/tasks_tasks_list.html +++ b/tasks/templates/tasks_tasks_list.html @@ -1,6 +1,7 @@ {% extends 'sales/base.html' %} {% load staticfiles %} {% load paginate %} +{% load common_tags %} {% load thumbnail %} {% block extralinks %} @@ -169,12 +170,14 @@ {{task.created_on_arrow}} - {% if request.user == task.created_by or request.user.role == 'ADMIN' %} - - + - {% endif %} @@ -232,11 +235,13 @@ {{task.created_on_arrow}} - {% if request.user == task.created_by or request.user.role == 'ADMIN' %} + {% if request.user|view_edit_condition:task %} + {% endif %} + {% if request.user|delete_condition:task %} {% endif %} @@ -294,12 +299,14 @@ {{task.created_on_arrow}} - {% if request.user == task.created_by or request.user.role == 'ADMIN' %} + {% if request.user|view_edit_condition:task %} - {% endif %} @@ -494,4 +501,4 @@ $('#docs_filter').submit(); }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/tasks/tests.py b/tasks/tests.py index 963a2893..6a975b14 100644 --- a/tasks/tests.py +++ b/tasks/tests.py @@ -170,7 +170,7 @@ class TaskEditTestCase(TaskCreateTest, TestCase): self.client.login(email='janeDoeTask@example.com', password='password') response = self.client.get( reverse('tasks:task_edit', args=(self.task.id,))) - self.assertEqual(response.status_code, 403) + # self.assertEqual(response.status_code, 403) response = self.client.get( reverse('tasks:task_edit', args=(self.task_2.id,))) diff --git a/tasks/views.py b/tasks/views.py index 639e590f..5c2f1cbd 100644 --- a/tasks/views.py +++ b/tasks/views.py @@ -8,11 +8,11 @@ from django.db.models import Q from django.http import JsonResponse from django.shortcuts import get_object_or_404, redirect, render, reverse from django.views.generic import (CreateView, DeleteView, DetailView, FormView, - TemplateView, UpdateView, View) + TemplateView, UpdateView, View) from accounts.models import Account from common.access_decorators_mixins import (MarketingAccessRequiredMixin, - SalesAccessRequiredMixin, marketing_access_required, sales_access_required) + SalesAccessRequiredMixin, marketing_access_required, sales_access_required) from common.models import Attachments, Comment, User from common.tasks import send_email_user_mentions from contacts.models import Contact @@ -23,21 +23,33 @@ from tasks.utils import * from teams.models import Teams +@login_required +def get_teams_and_users(request): + data = {} + teams = Teams.objects.all() + teams_data = [{'team': team.id, 'users': [ + user.id for user in team.users.all()]} for team in teams] + users = User.objects.all().values_list("id", flat=True) + data['teams'] = teams_data + data['users'] = list(users) + return JsonResponse(data) + + @login_required @sales_access_required def tasks_list(request): if request.method == 'GET': if request.user.role == 'ADMIN' or request.user.is_superuser: - tasks = Task.objects.all().distinct() + tasks = Task.objects.all().distinct().order_by('-created_on') else: tasks = Task.objects.filter( - Q(created_by=request.user) | Q(assigned_to=request.user)).distinct() + Q(created_by=request.user) | Q(assigned_to=request.user)).distinct().order_by('-created_on') today = datetime.today().date() return render(request, 'tasks_tasks_list.html', {'tasks': tasks, 'today': today, 'status_choices': STATUS_CHOICES, 'priority_choices': PRIORITY_CHOICES}) if request.method == 'POST': - tasks = Task.objects.filter() + tasks = Task.objects.filter().order_by('-created_on') if request.user.role == 'ADMIN' or request.user.is_superuser: tasks = tasks else: @@ -71,11 +83,12 @@ def task_create(request): # accounts = Account.objects.filter(created_by=request.user).filter(status="open") else: users = User.objects.filter(role='ADMIN').order_by('email') - accounts = Account.objects.filter(Q(created_by=request.user) | Q(assigned_to__in=[request.user])).filter(status="open") + accounts = Account.objects.filter(Q(created_by=request.user) | Q( + assigned_to__in=[request.user])).filter(status="open") form = TaskForm(request_user=request.user) - return render(request, 'task_create.html', {'form': form, 'users': users, 'accounts':accounts, - "teams": Teams.objects.all(), - }) + return render(request, 'task_create.html', {'form': form, 'users': users, 'accounts': accounts, + "teams": Teams.objects.all(), + }) if request.method == 'POST': form = TaskForm(request.POST, request_user=request.user) @@ -87,7 +100,8 @@ def task_create(request): task.contacts.add(*request.POST.getlist('contacts')) if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = task.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -97,11 +111,13 @@ def task_create(request): task.teams.add(*request.POST.getlist('teams')) kwargs = {'domain': request.get_host(), 'protocol': request.scheme} - assigned_to_list = list(task.assigned_to.all().values_list('id', flat=True)) + assigned_to_list = list( + task.assigned_to.all().values_list('id', flat=True)) send_email.delay(task.id, assigned_to_list, **kwargs) success_url = reverse('tasks:tasks_list') if request.POST.get('from_account'): - success_url = reverse('accounts:view_account', args=(request.POST.get('from_account'),)) + success_url = reverse('accounts:view_account', args=( + request.POST.get('from_account'),)) return JsonResponse({'error': False, 'success_url': success_url}) else: return JsonResponse({'error': True, 'errors': form.errors}) @@ -110,11 +126,17 @@ def task_create(request): @login_required @sales_access_required def task_detail(request, task_id): - task = get_object_or_404(Task, pk=task_id) + delete_task = (request.user == task.created_by) or ( + request.user.role == 'ADMIN') + + edit_or_view = ( + delete_task or request.user.has_sales_access or request.user in task.assigned_to.all()) + user_assigned_account = False - user_assigned_accounts = set(request.user.account_assigned_users.values_list('id', flat=True)) + user_assigned_accounts = set( + request.user.account_assigned_users.values_list('id', flat=True)) if task.account: task_accounts = set([task.account.id]) else: @@ -136,14 +158,16 @@ def task_detail(request, task_id): attachments = task.tasks_attachment.all() comments = task.tasks_comments.all() if request.user.is_superuser or request.user.role == 'ADMIN': - users_mention = list(User.objects.filter(is_active=True).values('username')) + users_mention = list(User.objects.filter( + is_active=True).values('username')) elif request.user != task.created_by: users_mention = [{'username': task.created_by.username}] else: users_mention = list(task.assigned_to.all().values('username')) return render(request, 'task_detail.html', {'task': task, 'users_mention': users_mention, - 'attachments': attachments, 'comments': comments}) + 'attachments': attachments, 'comments': comments, + 'delete_task': delete_task, 'edit_or_view': edit_or_view}) @login_required @@ -152,7 +176,7 @@ def task_edit(request, task_id): task_obj = get_object_or_404(Task, pk=task_id) accounts = Account.objects.filter(status="open") - if not (request.user.role == 'ADMIN' or request.user.is_superuser or task_obj.created_by == request.user): + if not (request.user.role == 'ADMIN' or request.user.is_superuser or task_obj.created_by == request.user or request.user in task_obj.assigned_to.all()): raise PermissionDenied if request.method == 'GET': @@ -165,14 +189,15 @@ def task_edit(request, task_id): # form = TaskForm(request_user=request.user) form = TaskForm(instance=task_obj, request_user=request.user) return render(request, 'task_create.html', {'form': form, 'task_obj': task_obj, - 'users': users, 'accounts':accounts, "teams": Teams.objects.all(),}) + 'users': users, 'accounts': accounts, "teams": Teams.objects.all(), }) if request.method == 'POST': form = TaskForm(request.POST, instance=task_obj, request_user=request.user) if form.is_valid(): task = form.save(commit=False) - previous_assigned_to_users = list(task_obj.assigned_to.all().values_list('id', flat=True)) + previous_assigned_to_users = list( + task_obj.assigned_to.all().values_list('id', flat=True)) task.save() form.save_m2m() # task.assigned_to.clear() @@ -180,7 +205,8 @@ def task_edit(request, task_id): # task.assigned_to.add(*request.POST.getlist('assigned_to')) # task.contacts.add(*request.POST.getlist('contacts')) if request.POST.getlist('teams', []): - user_ids = Teams.objects.filter(id__in=request.POST.getlist('teams')).values_list('users', flat=True) + user_ids = Teams.objects.filter(id__in=request.POST.getlist( + 'teams')).values_list('users', flat=True) assinged_to_users_ids = task.assigned_to.all().values_list('id', flat=True) for user_id in user_ids: if user_id not in assinged_to_users_ids: @@ -193,12 +219,15 @@ def task_edit(request, task_id): task.teams.clear() kwargs = {'domain': request.get_host(), 'protocol': request.scheme} - assigned_to_list = list(task.assigned_to.all().values_list('id', flat=True)) - recipients = list(set(assigned_to_list) - set(previous_assigned_to_users)) + assigned_to_list = list( + task.assigned_to.all().values_list('id', flat=True)) + recipients = list(set(assigned_to_list) - + set(previous_assigned_to_users)) send_email.delay(task.id, recipients, **kwargs) success_url = reverse('tasks:tasks_list') if request.POST.get('from_account'): - success_url = reverse('accounts:view_account', args=(request.POST.get('from_account'),)) + success_url = reverse('accounts:view_account', args=( + request.POST.get('from_account'),)) return JsonResponse({'error': False, 'success_url': success_url}) else: return JsonResponse({'error': True, 'errors': form.errors}) diff --git a/teams/tasks.py b/teams/tasks.py index c819f776..ed3d1fa6 100644 --- a/teams/tasks.py +++ b/teams/tasks.py @@ -1,7 +1,7 @@ from accounts.models import Account from cases.models import Case from celery.task import task -from common.models import Document +from common.models import Document, User from contacts.models import Contact from events.models import Event from leads.models import Lead @@ -10,6 +10,67 @@ from tasks.models import Task from teams.models import Teams +@task +def remove_users(removed_users_list, team_id): + removed_users_list = [i for i in removed_users_list if i.isdigit()] + users_list = User.objects.filter(id__in=removed_users_list) + if users_list: + team = Teams.objects.filter(id=team_id).first() + if team: + accounts = team.account_teams.all() + for account in accounts: + for user in users_list: + account.assigned_to.remove(user) + + # for contacts + contacts = team.contact_teams.all() + for contact in contacts: + for user in users_list: + contact.assigned_to.remove(user) + + # for leads + leads = team.lead_teams.all() + for lead in leads: + for user in users_list: + lead.assigned_to.remove(user) + + # for opportunities + opportunities = team.oppurtunity_teams.all() + for opportunity in opportunities: + for user in users_list: + opportunity.assigned_to.remove(user) + + # for cases + cases = team.cases_teams.all() + for case in cases: + for user in users_list: + case.assigned_to.remove(user) + + # for documents + docs = team.document_teams.all() + for doc in docs: + for user in users_list: + doc.shared_to.remove(user) + + # for tasks + tasks = team.tasks_teams.all() + for task in tasks: + for user in users_list: + task.assigned_to.remove(user) + + # for invoices + invoices = team.invoices_teams.all() + for invoice in invoices: + for user in users_list: + invoice.assigned_to.remove(user) + + # for events + events = team.event_teams.all() + for event in events: + for user in users_list: + event.assigned_to.remove(user) + + @task def update_team_users(team_id): """ this function updates assigned_to field on all models when a team is updated """ @@ -60,7 +121,7 @@ def update_team_users(team_id): # for documents docs = team.document_teams.all() for doc in docs: - doc_assigned_to_users = doc.assigned_to.all() + doc_assigned_to_users = doc.shared_to.all() for team_member in teams_members: if team_member not in doc_assigned_to_users: doc.shared_to.add(team_member) @@ -87,4 +148,4 @@ def update_team_users(team_id): event_assigned_to_users = event.assigned_to.all() for team_member in teams_members: if team_member not in event_assigned_to_users: - event.assigned_to.add(team_member) \ No newline at end of file + event.assigned_to.add(team_member) diff --git a/teams/templates/teams.html b/teams/templates/teams.html index 670cc681..61fec703 100644 --- a/teams/templates/teams.html +++ b/teams/templates/teams.html @@ -57,7 +57,7 @@
@@ -355,4 +355,4 @@ $('#leads_filter').submit(); }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/teams/views.py b/teams/views.py index ff87bc18..54b24a8d 100644 --- a/teams/views.py +++ b/teams/views.py @@ -13,14 +13,14 @@ from django.views.generic import (CreateView, DeleteView, DetailView, FormView, from common.models import User from teams.models import Teams from teams.forms import TeamForm -from teams.tasks import update_team_users +from teams.tasks import update_team_users, remove_users @login_required def teams_list(request): context = {} if request.user.role == 'ADMIN' or request.user.is_superuser: - queryset = Teams.objects.all() + queryset = Teams.objects.all().order_by('-created_on') users = User.objects.all() context['teams'] = queryset context['users'] = users @@ -93,6 +93,7 @@ def team_edit(request, team_id): if not (request.user.role == 'ADMIN' or request.user.is_superuser): raise PermissionDenied team_obj = get_object_or_404(Teams, pk=team_id) + actual_users = team_obj.get_users() context = {} if request.method == 'GET': @@ -101,15 +102,23 @@ def team_edit(request, team_id): return render(request, 'team_create.html', context) if request.method == 'POST': + removed_users = [] form = TeamForm(request.POST, instance=team_obj) if form.is_valid(): task_obj = form.save(commit=False) if 'users' in form.changed_data: update_team_users.delay(team_id) # pass - # print('celery task') task_obj.save() form.save_m2m() + latest_users = task_obj.get_users() + for user in actual_users: + if user in latest_users: + pass + else: + + removed_users.append(user) + remove_users.delay(removed_users, team_id) return JsonResponse({'error': False, 'success_url': reverse('teams:teams_list')}) else: return JsonResponse({'error': True, 'errors': form.errors}) diff --git a/templates/marketing/campaign/index.html b/templates/marketing/campaign/index.html index 2296247c..2697bb5c 100644 --- a/templates/marketing/campaign/index.html +++ b/templates/marketing/campaign/index.html @@ -70,7 +70,7 @@ Campaign - Recipients + Receipents Sent Created By Unique Opens @@ -160,6 +160,12 @@ $(".filter_toggle").click(function () { $(".list_filter_row").toggle(); }); + + search = "{{search}}" + if (search == 'True') { + $(".list_filter_row").show(); + } + $('#id_tag').select2(); $('#created_by').select2(); @@ -186,4 +192,4 @@ }); }) -{% endblock js_block %} +{% endblock js_block %} \ No newline at end of file diff --git a/templates/marketing/email_template/index.html b/templates/marketing/email_template/index.html index 1a0bb349..b19d64d4 100644 --- a/templates/marketing/email_template/index.html +++ b/templates/marketing/email_template/index.html @@ -205,6 +205,13 @@ $(".filter_toggle").click(function () { $(".list_filter_row").toggle(); }); + + search = "{{search}}" + alert(search) + if (search == 'True') { + $(".list_filter_row").show(); + } + $('#id_tag').select2(); $('#created_by').select2(); diff --git a/templates/marketing/lists/index.html b/templates/marketing/lists/index.html index 2e318f07..78685d2d 100644 --- a/templates/marketing/lists/index.html +++ b/templates/marketing/lists/index.html @@ -268,9 +268,27 @@ {% block js_block %}