diff --git a/accounts/forms.py b/accounts/forms.py index 49c2f015..a468537d 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -15,7 +15,10 @@ class AccountForm(forms.ModelForm): self.fields['assigned_to'].required = False self.fields['teams'].required = False for key, value in self.fields.items(): - value.widget.attrs['placeholder'] = value.label + if key == 'phone': + value.widget.attrs['placeholder'] = "+91-123-456-7890" + else: + value.widget.attrs['placeholder'] = value.label class Meta: model = Account diff --git a/accounts/templates/view_account.html b/accounts/templates/view_account.html index 239ca749..2f301637 100644 --- a/accounts/templates/view_account.html +++ b/accounts/templates/view_account.html @@ -2155,10 +2155,11 @@ $("#attachment_form").submit(function (e) { if (data.error) { $("#AttachmentError").html(data.error).show() } else { - d = new Date(data.created_by); $("#attachment_div").prepend( "
  • " + - "
    "+data.created_by+"
    "+d.toGMTString()+"
    " + + "
    " + + "
    "+data.attachment+"
    "+ + "
    "+data.created_by+"
    "+data.created_on+"
    " + "
  • " ) diff --git a/accounts/views.py b/accounts/views.py index cade59b8..3f440840 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -206,23 +206,33 @@ class AccountUpdateView(LoginRequiredMixin, UpdateView): account_object.billing_address = billing_address_object account_object.shipping_address = shipping_address_object account_object.save() + + assigned_to_ids = account_object.assigned_to.all().values_list('id', flat=True) + account_object.assigned_to.clear() account_object.teams.clear() + all_members_list = [] + if self.request.POST.getlist('assigned_to', []): account_object.assigned_to.add(*self.request.POST.getlist('assigned_to')) assigned_to_list = self.request.POST.getlist('assigned_to') current_site = get_current_site(self.request) - for assigned_to_user in assigned_to_list: - user = get_object_or_404(User, pk=assigned_to_user) - mail_subject = 'Assigned to account.' - message = render_to_string('assigned_to/account_assigned.html', { - 'user': user, - 'domain': current_site.domain, - 'protocol': self.request.scheme, - 'account': account_object - }) - email = EmailMessage(mail_subject, message, to=[user.email]) - email.send() + + assigned_form_users = form.cleaned_data.get('assigned_to').values_list('id', flat=True) + all_members_list = list(set(list(assigned_form_users)) - set(list(assigned_to_ids))) + + if len(all_members_list): + for assigned_to_user in assigned_to_list: + user = get_object_or_404(User, pk=assigned_to_user) + mail_subject = 'Assigned to account.' + message = render_to_string('assigned_to/account_assigned.html', { + 'user': user, + 'domain': current_site.domain, + 'protocol': self.request.scheme, + 'account': account_object + }) + email = EmailMessage(mail_subject, message, to=[user.email]) + email.send() if self.request.POST.getlist('teams', []): account_object.teams.add(*self.request.POST.getlist('teams')) return redirect("accounts:list") @@ -383,7 +393,8 @@ class AddAttachmentView(LoginRequiredMixin, CreateView): attachment.save() return JsonResponse({ "attachment_id": attachment.id, - "attachment": attachment.attachment, + "attachment": attachment.file_name, + "attachment_url": attachment.attachment.url, "created_on": attachment.created_on, "created_by": attachment.created_by.email }) diff --git a/cases/forms.py b/cases/forms.py index 243dae00..09c4b6ac 100644 --- a/cases/forms.py +++ b/cases/forms.py @@ -1,6 +1,6 @@ from django import forms from cases.models import Case -from common.models import Comment +from common.models import Comment, Attachments class CaseForm(forms.ModelForm): @@ -42,4 +42,13 @@ class CaseCommentForm(forms.ModelForm): class Meta: model = Comment - fields = ('comment', 'case', 'commented_by', ) \ No newline at end of file + + fields = ('comment', 'case', 'commented_by', ) + + +class CaseAttachmentForm(forms.ModelForm): + attachment = forms.FileField(max_length=1001, required=True) + + class Meta: + model = Attachments + fields = ('attachment', 'case') diff --git a/cases/templates/view_case.html b/cases/templates/view_case.html index 4106de82..3ffe4b61 100644 --- a/cases/templates/view_case.html +++ b/cases/templates/view_case.html @@ -16,7 +16,7 @@ @@ -98,6 +98,44 @@ + + +
    +
    +
    Attachments
    +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    + +
    +
      + {% for attachemnt in attachments %} +
    • +
      +
      + +
      +
      +
      {{ attachemnt.file_name }}
      +
      +
      {{ attachemnt.created_by }}
      +
      {{ attachemnt.created_on }}
      +
      +
    • + {% endfor %} +
    +
    +
    +
    @@ -342,5 +380,46 @@ }); }) }); + + +function remove_attachment(x) { + const con = confirm("Do you want to Delete it for Sure!?"); + if (con == true) { + $.post('{% url "cases:remove_attachment" %}', { + "attachment_id": x + }, function (data) { + if (data.error) { + alert(data.error) + } else { + // $("#attachment" + data.aid).remove() + window.location.reload(); + } + }) + } +} + +$("#attachment_form").submit(function (e) { + e.preventDefault() + const formData = new FormData($("#attachment_form")[0]); + $.ajax({ + url: "{% url 'cases:add_attachment' %}", + type: "POST", + data: formData, + cache: false, + contentType: false, + processData: false, + success: function (data) { + if (data.error) { + $("#AttachmentError").html(data.error).show() + } else { + alert(data.message) + $("#id_attachments").val("") + window.location.reload(); + } + } + }) +}) + + {% endblock js_block %} diff --git a/cases/urls.py b/cases/urls.py index 2765feb3..52fe2124 100644 --- a/cases/urls.py +++ b/cases/urls.py @@ -2,7 +2,7 @@ from django.urls import path from cases.views import ( CasesListView, CreateCaseView, CaseDetailView, UpdateCaseView, RemoveCaseView, CloseCaseView, SelectContactsView, GetCasesView, AddCommentView, - UpdateCommentView, DeleteCommentView) + UpdateCommentView, DeleteCommentView, AddAttachmentView, DeleteAttachmentsView) app_name = 'cases' @@ -20,4 +20,7 @@ urlpatterns = [ path('comment/add/', AddCommentView.as_view(), name="add_comment"), path('comment/edit/', UpdateCommentView.as_view(), name="edit_comment"), path('comment/remove/', DeleteCommentView.as_view(), name="remove_comment"), + + path('attachment/add/', AddAttachmentView.as_view(), name="add_attachment"), + path('attachment/remove/', DeleteAttachmentsView.as_view(), name="remove_attachment"), ] diff --git a/cases/views.py b/cases/views.py index ccb86cbf..74fbd8ee 100644 --- a/cases/views.py +++ b/cases/views.py @@ -8,8 +8,8 @@ from django.template.loader import render_to_string from django.views.generic import CreateView, UpdateView, DetailView, ListView, TemplateView, View from cases.models import Case -from cases.forms import CaseForm, CaseCommentForm -from common.models import Team, User, Comment +from cases.forms import CaseForm, CaseCommentForm, CaseAttachmentForm +from common.models import Team, User, Comment, Attachments from accounts.models import Account from contacts.models import Contact from common.utils import PRIORITY_CHOICE, STATUS_CHOICE, CASE_TYPE @@ -143,7 +143,8 @@ class CaseDetailView(LoginRequiredMixin, DetailView): def get_context_data(self, **kwargs): context = super(CaseDetailView, self).get_context_data(**kwargs) - context.update({"comments": context["case_record"].cases.all()}) + context.update({"comments": context["case_record"].cases.all(), + "attachments": context['case_record'].case_attachment.all()}) return context @@ -174,24 +175,30 @@ class UpdateCaseView(LoginRequiredMixin, UpdateView): def form_valid(self, form): case_obj = form.save() + + assigned_to_ids = case_obj.assigned_to.all().values_list('id', flat=True) case_obj.assigned_to.clear() case_obj.teams.clear() case_obj.contacts.clear() + all_members_list = [] if self.request.POST.getlist('assigned_to', []): case_obj.assigned_to.add(*self.request.POST.getlist('assigned_to')) assigned_to_list = self.request.POST.getlist('assigned_to') current_site = get_current_site(self.request) - for assigned_to_user in assigned_to_list: - user = get_object_or_404(User, pk=assigned_to_user) - mail_subject = 'Assigned to case.' - message = render_to_string('assigned_to/cases_assigned.html', { - 'user': user, - 'domain': current_site.domain, - 'protocol': self.request.scheme, - 'case': case_obj - }) - email = EmailMessage(mail_subject, message, to=[user.email]) - email.send() + assigned_form_users = form.cleaned_data.get('assigned_to').values_list('id', flat=True) + all_members_list = list(set(list(assigned_form_users)) - set(list(assigned_to_ids))) + if len(all_members_list): + for assigned_to_user in assigned_to_list: + user = get_object_or_404(User, pk=assigned_to_user) + mail_subject = 'Assigned to case.' + message = render_to_string('assigned_to/cases_assigned.html', { + 'user': user, + 'domain': current_site.domain, + 'protocol': self.request.scheme, + 'case': case_obj + }) + email = EmailMessage(mail_subject, message, to=[user.email]) + email.send() if self.request.POST.getlist('teams', []): case_obj.teams.add(*self.request.POST.getlist('teams')) if self.request.POST.getlist('contacts', []): @@ -349,3 +356,51 @@ class DeleteCommentView(LoginRequiredMixin, View): else: data = {'error': "You don't have permission to delete this comment."} return JsonResponse(data) + + +class AddAttachmentView(LoginRequiredMixin, CreateView): + model = Attachments + form_class = CaseAttachmentForm + http_method_names = ["post"] + + def post(self, request, *args, **kwargs): + self.object = None + self.case = get_object_or_404(Case, id=request.POST.get('caseid')) + if ( + request.user in self.case.assigned_to.all() or + request.user == self.case.created_by + ): + form = self.get_form() + if form.is_valid(): + return self.form_valid(form) + else: + return self.form_invalid(form) + else: + data = {'error': "You don't have permission to add attachment for this case."} + return JsonResponse(data) + + def form_valid(self, form): + attachment = form.save(commit=False) + attachment.created_by = self.request.user + attachment.file_name = attachment.attachment.name + attachment.case = self.case + attachment.save() + return JsonResponse({ + "message": "Attachment Saved" + }) + + def form_invalid(self, form): + return JsonResponse({"error": form['attachment'].errors}) + + +class DeleteAttachmentsView(LoginRequiredMixin, View): + + def post(self, request, *args, **kwargs): + self.object = get_object_or_404(Attachments, id=request.POST.get("attachment_id")) + if request.user == self.object.created_by: + self.object.delete() + data = {"acd": request.POST.get("attachment_id")} + return JsonResponse(data) + else: + data = {'error': "You don't have permission to delete this attachment."} + return JsonResponse(data) \ No newline at end of file diff --git a/common/migrations/0004_attachments_case.py b/common/migrations/0004_attachments_case.py new file mode 100644 index 00000000..af324ca0 --- /dev/null +++ b/common/migrations/0004_attachments_case.py @@ -0,0 +1,20 @@ +# Generated by Django 2.1.5 on 2019-01-29 08:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cases', '0002_auto_20190128_1237'), + ('common', '0003_document'), + ] + + operations = [ + migrations.AddField( + model_name='attachments', + name='case', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='case_attachment', to='cases.Case'), + ), + ] diff --git a/common/models.py b/common/models.py index 05e7b1ef..89ccf7c7 100644 --- a/common/models.py +++ b/common/models.py @@ -127,6 +127,7 @@ class Attachments(models.Model): account = models.ForeignKey('accounts.Account', null=True, blank=True, related_name='account_attachment', on_delete=models.CASCADE) contact = models.ForeignKey('contacts.Contact', on_delete=models.CASCADE, related_name='contact_attachment', blank=True, null=True) opportunity = models.ForeignKey('opportunity.Opportunity',blank=True,null=True,on_delete=models.CASCADE,related_name='opportunity_attachment') + case = models.ForeignKey('cases.Case',blank=True,null=True,on_delete=models.CASCADE,related_name='case_attachment') def document_path(self, filename): @@ -272,4 +273,4 @@ class Document(models.Model): def __str__(self): - return self.title \ No newline at end of file + return self.title diff --git a/common/templates/create.html b/common/templates/create.html index d4f0218c..196cef53 100644 --- a/common/templates/create.html +++ b/common/templates/create.html @@ -51,7 +51,7 @@
    {{ errors.email }} -
    +
    {% if request.user.role == 'ADMIN' or request.user.is_superuser %} diff --git a/common/templates/doc_list.html b/common/templates/doc_list.html index aa2084eb..ebf88df3 100644 --- a/common/templates/doc_list.html +++ b/common/templates/doc_list.html @@ -29,8 +29,8 @@
    - - + +

    @@ -56,7 +56,7 @@ S.No - Document Name + Document Title Created_by Actions @@ -111,4 +111,4 @@ $('#docs_filter').submit(); }); -{% endblock js_block %} \ No newline at end of file +{% endblock js_block %} diff --git a/common/views.py b/common/views.py index 108885c0..cc97ecf8 100644 --- a/common/views.py +++ b/common/views.py @@ -241,7 +241,7 @@ class PasswordResetView(PasswordResetView): -class DocumentCreateView(AdminRequiredMixin, CreateView): +class DocumentCreateView(LoginRequiredMixin, CreateView): model = Document form_class = DocumentForm template_name = "doc_create.html" @@ -274,7 +274,7 @@ class DocumentCreateView(AdminRequiredMixin, CreateView): -class DocumentListView(AdminRequiredMixin, TemplateView): +class DocumentListView(LoginRequiredMixin, TemplateView): model = Document context_object_name = "documents" template_name = "doc_list.html" @@ -298,7 +298,7 @@ class DocumentListView(AdminRequiredMixin, TemplateView): return self.render_to_response(context) -class DocumentDeleteView(AdminRequiredMixin, DeleteView): +class DocumentDeleteView(LoginRequiredMixin, DeleteView): model = Document def get(self, request, *args, **kwargs): @@ -336,7 +336,7 @@ class UpdateDocumentView(LoginRequiredMixin, UpdateView): return context -class DocumentDetailView(AdminRequiredMixin, DetailView): +class DocumentDetailView(LoginRequiredMixin, DetailView): model = Document template_name = "doc_detail.html" @@ -359,4 +359,4 @@ def download_document(request, pk): response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel") response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path) return response - raise Http404 \ No newline at end of file + raise Http404 diff --git a/contacts/forms.py b/contacts/forms.py index 38fdc201..df549dd8 100644 --- a/contacts/forms.py +++ b/contacts/forms.py @@ -17,8 +17,12 @@ class ContactForm(forms.ModelForm): self.fields['account'].queryset = contact_account self.fields['assigned_to'].required = False self.fields['teams'].required = False + for key, value in self.fields.items(): - value.widget.attrs['placeholder'] = value.label + if key == 'phone': + value.widget.attrs['placeholder'] = "+91-123-456-7890" + else: + value.widget.attrs['placeholder'] = value.label class Meta: model = Contact @@ -39,6 +43,7 @@ class ContactForm(forms.ModelForm): + class ContactCommentForm(forms.ModelForm): comment = forms.CharField(max_length=64, required=True) diff --git a/contacts/templates/view_contact.html b/contacts/templates/view_contact.html index 3a222e61..3fa4cbc8 100644 --- a/contacts/templates/view_contact.html +++ b/contacts/templates/view_contact.html @@ -311,10 +311,11 @@ $("#attachment_form").submit(function (e) { $("#AttachmentError").html(data.error).show() alert("Attachment Saved") } else { - d = new Date(data.created_by); $("#attachment_div").prepend( "
  • " + - "
    "+data.created_by+"
    "+d.toGMTString()+"
    " + + "
    " + + "
    "+data.attachment+"
    "+ + "
    "+data.created_by+"
    "+data.created_on+"
    " + "
  • " ) $("#id_attachments").val("") diff --git a/contacts/views.py b/contacts/views.py index 56d842e8..38fe6034 100644 --- a/contacts/views.py +++ b/contacts/views.py @@ -181,23 +181,31 @@ class UpdateContactView(LoginRequiredMixin, UpdateView): def form_valid(self, form): contact_obj = form.save(commit=False) + + assigned_to_ids = contact_obj.assigned_to.all().values_list('id', flat=True) + contact_obj.assigned_to.clear() contact_obj.teams.clear() + all_members_list = [] if self.request.POST.getlist('assigned_to', []): contact_obj.assigned_to.add(*self.request.POST.getlist('assigned_to')) assigned_to_list = self.request.POST.getlist('assigned_to') current_site = get_current_site(self.request) - for assigned_to_user in assigned_to_list: - user = get_object_or_404(User, pk=assigned_to_user) - mail_subject = 'Assigned to contact.' - message = render_to_string('assigned_to/contact_assigned.html', { - 'user': user, - 'domain': current_site.domain, - 'protocol': self.request.scheme, - 'contact': contact_obj - }) - email = EmailMessage(mail_subject, message, to=[user.email]) - email.send() + + assigned_form_users = form.cleaned_data.get('assigned_to').values_list('id', flat=True) + all_members_list = list(set(list(assigned_form_users)) - set(list(assigned_to_ids))) + if len(all_members_list): + for assigned_to_user in assigned_to_list: + user = get_object_or_404(User, pk=assigned_to_user) + mail_subject = 'Assigned to contact.' + message = render_to_string('assigned_to/contact_assigned.html', { + 'user': user, + 'domain': current_site.domain, + 'protocol': self.request.scheme, + 'contact': contact_obj + }) + email = EmailMessage(mail_subject, message, to=[user.email]) + email.send() if self.request.POST.getlist('teams', []): contact_obj.teams.add(*self.request.POST.getlist('teams')) if self.request.is_ajax(): @@ -371,7 +379,8 @@ class AddAttachmentsView(LoginRequiredMixin, CreateView): attachment.save() return JsonResponse({ "attachment_id": attachment.id, - "attachment": attachment.attachment, + "attachment": attachment.file_name, + "attachment_url": attachment.attachment.url, "created_on": attachment.created_on, "created_by": attachment.created_by.email }) diff --git a/leads/forms.py b/leads/forms.py index 9d826a3b..952e682b 100644 --- a/leads/forms.py +++ b/leads/forms.py @@ -17,13 +17,19 @@ class LeadForm(forms.ModelForm): self.fields['teams'].required = False self.fields['phone'].required = True for key, value in self.fields.items(): - value.widget.attrs['placeholder'] = value.label + if key == 'phone': + value.widget.attrs['placeholder'] = 'Enter phone number with country code' + else: + value.widget.attrs['placeholder'] = value.label + self.fields['first_name'].widget.attrs.update({ 'placeholder': 'First Name'}) self.fields['last_name'].widget.attrs.update({ 'placeholder': 'Last Name'}) self.fields['account_name'].widget.attrs.update({ 'placeholder': 'Account Name'}) + self.fields['phone'].widget.attrs.update({ + 'placeholder': '+91-123-456-7890'}) class Meta: model = Lead @@ -43,6 +49,7 @@ class LeadForm(forms.ModelForm): return client_phone + class LeadCommentForm(forms.ModelForm): comment = forms.CharField(max_length=64, required=True) diff --git a/leads/templates/view_leads.html b/leads/templates/view_leads.html index df92c018..988b95ea 100644 --- a/leads/templates/view_leads.html +++ b/leads/templates/view_leads.html @@ -346,10 +346,11 @@ $("#attachment_form").submit(function (e) { $("#AttachmentError").html(data.error).show() alert("Attachment Saved") } else { - d = new Date(data.created_by); $("#attachment_div").prepend( "
  • " + - "
    "+data.created_by+"
    "+d.toGMTString()+"
    " + + "
    " + + "
    "+data.attachment+"
    "+ + "
    "+data.created_by+"
    "+data.created_on+"
    " + "
  • " ); $("#id_attachments").val("") diff --git a/leads/views.py b/leads/views.py index 32dca866..b04319d5 100644 --- a/leads/views.py +++ b/leads/views.py @@ -230,26 +230,33 @@ class UpdateLeadView(LoginRequiredMixin, UpdateView): def form_valid(self, form, address_form): address_obj = address_form.save() lead_obj = form.save(commit=False) + assigned_to_ids = lead_obj.assigned_to.all().values_list('id', flat=True) lead_obj.address = address_obj lead_obj.save() lead_obj.assigned_to.clear() lead_obj.teams.clear() + all_members_list = [] if self.request.POST.getlist('assigned_to', []): lead_obj.assigned_to.add(*self.request.POST.getlist('assigned_to')) if self.request.POST.get('status') != "converted": assigned_to_list = self.request.POST.getlist('assigned_to') current_site = get_current_site(self.request) - for assigned_to_user in assigned_to_list: - user = get_object_or_404(User, pk=assigned_to_user) - mail_subject = 'Assigned to lead.' - message = render_to_string('assigned_to/leads_assigned.html', { - 'user': user, - 'domain': current_site.domain, - 'protocol': self.request.scheme, - 'lead': lead_obj - }) - email = EmailMessage(mail_subject, message, to=[user.email]) - email.send() + + assigned_form_users = form.cleaned_data.get('assigned_to').values_list('id', flat=True) + all_members_list = list(set(list(assigned_form_users)) - set(list(assigned_to_ids))) + + if len(all_members_list): + for assigned_to_user in assigned_to_list: + user = get_object_or_404(User, pk=assigned_to_user) + mail_subject = 'Assigned to lead.' + message = render_to_string('assigned_to/leads_assigned.html', { + 'user': user, + 'domain': current_site.domain, + 'protocol': self.request.scheme, + 'lead': lead_obj + }) + email = EmailMessage(mail_subject, message, to=[user.email]) + email.send() if self.request.POST.getlist('teams', []): lead_obj.teams.add(*self.request.POST.getlist('teams')) if self.request.POST.get('status') == "converted": @@ -479,7 +486,8 @@ class AddAttachmentsView(LoginRequiredMixin, CreateView): attachment.save() return JsonResponse({ "attachment_id": attachment.id, - "attachment": attachment.attachment, + "attachment": attachment.file_name, + "attachment_url": attachment.attachment.url, "created_on": attachment.created_on, "created_by": attachment.created_by.email }) diff --git a/opportunity/templates/view_opportunity.html b/opportunity/templates/view_opportunity.html index d3ef5994..b5203d19 100644 --- a/opportunity/templates/view_opportunity.html +++ b/opportunity/templates/view_opportunity.html @@ -363,10 +363,11 @@ $("#attachment_form").submit(function (e) { $("#AttachmentError").html(data.error).show() alert("Attachment Saved") } else { - d = new Date(data.created_by); $("#attachment_div").prepend( "
  • " + - "
    "+data.created_by+"
    "+d.toGMTString()+"
    " + + "
    " + + "
    "+data.attachment+"
    "+ + "
    "+data.created_by+"
    "+data.created_on+"
    " + "
  • " ) $("#id_attachments").val("") diff --git a/opportunity/views.py b/opportunity/views.py index 829e0fbf..abb7cc4d 100644 --- a/opportunity/views.py +++ b/opportunity/views.py @@ -178,24 +178,30 @@ class UpdateOpportunityView(LoginRequiredMixin, UpdateView): if self.request.POST.get('stage') in ['CLOSED WON', 'CLOSED LOST']: opportunity_obj.closed_by = self.request.user opportunity_obj.save() + assigned_to_ids = opportunity_obj.assigned_to.all().values_list('id', flat=True) opportunity_obj.assigned_to.clear() opportunity_obj.teams.clear() opportunity_obj.contacts.clear() + all_members_list = [] if self.request.POST.getlist('assigned_to', []): opportunity_obj.assigned_to.add(*self.request.POST.getlist('assigned_to')) assigned_to_list = self.request.POST.getlist('assigned_to') current_site = get_current_site(self.request) - for assigned_to_user in assigned_to_list: - user = get_object_or_404(User, pk=assigned_to_user) - mail_subject = 'Assigned to opportunity.' - message = render_to_string('assigned_to/opportunity_assigned.html', { - 'user': user, - 'domain': current_site.domain, - 'protocol': self.request.scheme, - 'opportunity': opportunity_obj - }) - email = EmailMessage(mail_subject, message, to=[user.email]) - email.send() + + assigned_form_users = form.cleaned_data.get('assigned_to').values_list('id', flat=True) + all_members_list = list(set(list(assigned_form_users)) - set(list(assigned_to_ids))) + if len(all_members_list): + for assigned_to_user in assigned_to_list: + user = get_object_or_404(User, pk=assigned_to_user) + mail_subject = 'Assigned to opportunity.' + message = render_to_string('assigned_to/opportunity_assigned.html', { + 'user': user, + 'domain': current_site.domain, + 'protocol': self.request.scheme, + 'opportunity': opportunity_obj + }) + email = EmailMessage(mail_subject, message, to=[user.email]) + email.send() if self.request.POST.getlist('teams', []): opportunity_obj.teams.add(*self.request.POST.getlist('teams')) if self.request.POST.getlist('contacts', []): @@ -372,7 +378,8 @@ class AddAttachmentsView(LoginRequiredMixin, CreateView): attachment.save() return JsonResponse({ "attachment_id": attachment.id, - "attachment": attachment.attachment, + "attachment": attachment.file_name, + "attachment_url": attachment.attachment.url, "created_on": attachment.created_on, "created_by": attachment.created_by.email }) diff --git a/requirements.txt b/requirements.txt index f9c67f1d..234d07a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,15 @@ Django==2.1.5 -django-simple-pagination==1.1.8 -pytz==2018.3 -psycopg2-binary==2.7.4 +django-simple-pagination==1.3 +pytz==2018.9 +psycopg2-binary==2.7.7 redis django-compressor==2.2 coverage -pytest==3.6.3 -pytest-cov==2.5.1 -pytest-django==3.1.2 -codacy-coverage==1.3.6 +pytest==4.1.1 +pytest-cov==2.6.1 +pytest-django==3.4.5 +codacy-coverage==1.3.11 sorl-thumbnail==12.5.0 -Pillow==5.3.0 -django-phonenumber-field==2.0.1 +Pillow==5.4.1 +phonenumbers==8.10.4 +django-phonenumber-field==2.2.0