From 18c810e956b96af9e7c7478e8dd38855dd774c93 Mon Sep 17 00:00:00 2001 From: Ashwin Date: Tue, 12 Feb 2019 04:36:35 +0530 Subject: [PATCH] started test case enhancements --- accounts/templates/accounts.html | 3 +- accounts/templates/create_account.html | 82 +++-- accounts/views.py | 18 +- common/forms.py | 18 +- common/templates/doc_create.html | 2 + common/templates/list.html | 68 +---- common/templates/user_detail.html | 10 +- common/views.py | 51 ++-- leads/forms.py | 1 - leads/migrations/0003_auto_20190211_1142.py | 18 ++ leads/models.py | 2 +- leads/templates/create_lead.html | 4 +- leads/templates/leads.html | 288 +++++++++++++----- leads/templates/view_leads.html | 55 ++-- leads/views.py | 29 +- templates/assigned_to/account_assigned.html | 12 +- templates/assigned_to/cases_assigned.html | 12 +- templates/assigned_to/contact_assigned.html | 12 +- templates/assigned_to/leads_assigned.html | 12 +- .../assigned_to/opportunity_assigned.html | 12 +- 20 files changed, 429 insertions(+), 280 deletions(-) create mode 100644 leads/migrations/0003_auto_20190211_1142.py diff --git a/accounts/templates/accounts.html b/accounts/templates/accounts.html index 6be0217b..ac0aa902 100644 --- a/accounts/templates/accounts.html +++ b/accounts/templates/accounts.html @@ -38,10 +38,9 @@ - {{ account_form.assigned_to.errors }}
diff --git a/accounts/templates/create_account.html b/accounts/templates/create_account.html index 383f49d1..77cf710d 100644 --- a/accounts/templates/create_account.html +++ b/accounts/templates/create_account.html @@ -57,6 +57,56 @@
+
+
+
+ + {{ billing_form.address_line }} + {{ billing_form.address_line.errors }} +
+ +
+
+
+ + {{ billing_form.street }} + {{ billing_form.street.errors }} +
+
+
+
+ + {{ billing_form.postcode }} + {{ billing_form.postcode.errors }} +
+
+
+
+ + {{ billing_form.city }} + {{ billing_form.city.errors }} +
+
+
+
+ + {{ billing_form.state }} + {{ billing_form.state.errors }} +
+
+
+
+ + {{ billing_form.country }} + {{ billing_form.country.errors }} +
+
+
+
+
+
Copy Address
+
+
@@ -70,38 +120,6 @@ {{ account_form.assigned_to.errors }}
-
-
- - {{ billing_form.address_line }} - {{ billing_form.address_line.errors }} -
- {{ billing_form.street }} - {{ billing_form.street.errors }} -
-
- {{ billing_form.city }} - {{ billing_form.city.errors }} -
-
- {{ billing_form.state }} - {{ billing_form.state.errors }} -
-
- {{ billing_form.postcode }} - {{ billing_form.postcode.errors }} -
-
- {{ billing_form.country }} - {{ billing_form.country.errors }} -
-
-
-
-
Copy Address
-
-
-
diff --git a/accounts/views.py b/accounts/views.py index edc44c0b..8e9d7b91 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -37,8 +37,8 @@ class AccountsListView(LoginRequiredMixin, TemplateView): queryset = queryset.filter(industry__icontains=request_post.get('industry')) if request_post.get('tag'): queryset = queryset.filter(tags__in=request_post.get('tag')) - if request_post.get('assigned_to'): - queryset = queryset.filter(assigned_to__id__in=request_post.get('assigned_to')) + if request_post.getlist('assigned_to'): + queryset = queryset.filter(assigned_to__id__in=request_post.getlist('assigned_to')) return queryset def get_context_data(self, **kwargs): @@ -51,6 +51,8 @@ class AccountsListView(LoginRequiredMixin, TemplateView): context['close_accounts'] = close_accounts context["industries"] = INDCHOICES context["per_page"] = self.request.POST.get('per_page') + context["assignedto_list"] = [ + int(i) for i in self.request.POST.getlist('assigned_to', []) if i] context['tags'] = Tags.objects.all() tab_status = 'Open' @@ -85,7 +87,7 @@ class CreateAccountView(LoginRequiredMixin, CreateView): def post(self, request, *args, **kwargs): self.object = None form = self.get_form() - billing_form = BillingAddressForm(request.POST) + billing_form = BillingAddressForm(request.POST, account=True) shipping_form = ShippingAddressForm(request.POST, prefix='ship') if form.is_valid() and billing_form.is_valid() and shipping_form.is_valid(): return self.form_valid(form, billing_form, shipping_form) @@ -152,10 +154,10 @@ class CreateAccountView(LoginRequiredMixin, CreateView): context["shipping_form"] = kwargs["shipping_form"] else: if self.request.POST: - context["billing_form"] = BillingAddressForm(self.request.POST) + context["billing_form"] = BillingAddressForm(self.request.POST, account=True) context["shipping_form"] = ShippingAddressForm(self.request.POST, prefix='ship') else: - context["billing_form"] = BillingAddressForm() + context["billing_form"] = BillingAddressForm(account=True) context["shipping_form"] = ShippingAddressForm(prefix='ship') context["assignedto_list"] = [ int(i) for i in self.request.POST.getlist('assigned_to', []) if i] @@ -226,7 +228,7 @@ class AccountUpdateView(LoginRequiredMixin, UpdateView): def post(self, request, *args, **kwargs): self.object = self.get_object() form = self.get_form() - billing_form = BillingAddressForm(request.POST, instance=self.object.billing_address) + billing_form = BillingAddressForm(request.POST, instance=self.object.billing_address, account=True) shipping_form = ShippingAddressForm( request.POST, instance=self.object.shipping_address, prefix='ship') if form.is_valid() and billing_form.is_valid() and shipping_form.is_valid(): @@ -304,12 +306,12 @@ class AccountUpdateView(LoginRequiredMixin, UpdateView): else: if self.request.POST: context["billing_form"] = BillingAddressForm( - self.request.POST, instance=self.object.billing_address) + self.request.POST, instance=self.object.billing_address, account=True) context["shipping_form"] = ShippingAddressForm( self.request.POST, instance=self.object.shipping_address, prefix='ship') else: context["billing_form"] = BillingAddressForm( - instance=self.object.billing_address) + instance=self.object.billing_address, account=True) context["shipping_form"] = ShippingAddressForm( instance=self.object.shipping_address, prefix='ship') context["assignedto_list"] = [ diff --git a/common/forms.py b/common/forms.py index 41b52a79..eafafd3b 100644 --- a/common/forms.py +++ b/common/forms.py @@ -11,6 +11,8 @@ class BillingAddressForm(forms.ModelForm): fields = ('address_line', 'street', 'city', 'state', 'postcode', 'country') def __init__(self, *args, **kwargs): + account_view = kwargs.pop('account', False) + super(BillingAddressForm, self).__init__(*args, **kwargs) for field in self.fields.values(): field.widget.attrs = {"class": "form-control"} @@ -26,6 +28,14 @@ class BillingAddressForm(forms.ModelForm): 'placeholder': 'Postcode'}) self.fields["country"].choices = [("", "--Country--"), ] + list(self.fields["country"].choices)[1:] + if account_view: + self.fields['address_line'].required = True + self.fields['street'].required = True + self.fields['city'].required = True + self.fields['state'].required = True + self.fields['postcode'].required = True + self.fields['country'].required = True + class ShippingAddressForm(forms.ModelForm): class Meta: @@ -107,12 +117,14 @@ class LoginForm(forms.ModelForm): password = self.cleaned_data.get("password") if email and password: - self.user = authenticate(email=email, password=password) + self.user = authenticate(username=email, password=password) if self.user: if not self.user.is_active: - raise forms.ValidationError("User is Inactive") + pass + # raise forms.ValidationError("User is Inactive") else: - raise forms.ValidationError("Invalid email and password") + pass + # raise forms.ValidationError("Invalid email and password") return self.cleaned_data diff --git a/common/templates/doc_create.html b/common/templates/doc_create.html index 65334077..33678e46 100644 --- a/common/templates/doc_create.html +++ b/common/templates/doc_create.html @@ -36,6 +36,7 @@ {{ errors.document_file }}

+ {% if doc_obj %}
@@ -43,6 +44,7 @@ {{ doc_form.status.errors }}
+ {% endif %}
diff --git a/common/templates/list.html b/common/templates/list.html index e2239564..84911822 100644 --- a/common/templates/list.html +++ b/common/templates/list.html @@ -10,53 +10,6 @@ Add New User
-
-
-
-
-
Filters
-
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - Clear -
-
-
-
-
-
-
-
-
@@ -66,7 +19,7 @@ Users - {% if show_pageitems %} {% show_pageitems %}{% else %} {{ users|length }}{% endif %} - +

+
@@ -168,6 +169,7 @@
+
@@ -282,7 +284,7 @@
- `{% ifequal contacts|length 0 %} + `{% ifequal opportunity_list|length 0 %}
No Opportunity Records Found
{% endifequal %}
@@ -368,8 +370,8 @@ d = new Date(data.commented_on); $("#comments_div").prepend("
  • "+ "
    "+ - ""+ diff --git a/common/views.py b/common/views.py index 18ca7190..eed461c3 100644 --- a/common/views.py +++ b/common/views.py @@ -94,24 +94,37 @@ class LoginView(TemplateView): def post(self, request, *args, **kwargs): form = LoginForm(request.POST, request=request) if form.is_valid(): - user = authenticate(username=request.POST.get('email'), password=request.POST.get('password')) + user = User.objects.filter(email=request.POST.get('email')).first() + # user = authenticate(username=request.POST.get('email'), password=request.POST.get('password')) if user is not None: if user.is_active: - login(request, user) - return HttpResponseRedirect('/') - + user = authenticate(username=request.POST.get('email'), + password=request.POST.get('password')) + if user is not None: + login(request, user) + return HttpResponseRedirect('/') + else: + return render(request, "login.html", { + "error": True, + "message": "Your username and password didn't match. Please try again." + }) + else: + return render(request, "login.html", { + "error": True, + "message": "Your Account is inactive. Please Contact Administrator" + }) + else: return render(request, "login.html", { "error": True, - "message": "Your Account is InActive. Please Contact Administrator" - }) + "message": "Your Account is not Found. Please Contact Administrator" + }) + + else: return render(request, "login.html", { "error": True, - "message": "Your Account is not Found. Please Contact Administrator" - }) - return render(request, "login.html", { - "error": True, - "message": "Your username and password didn't match. Please try again." - }) + "message": "Your username and password didn't match. Please try again." + }) + class ForgotPasswordView(TemplateView): @@ -133,25 +146,11 @@ class UsersListView(AdminRequiredMixin, TemplateView): def get_queryset(self): queryset = self.model.objects.all() - request_post = self.request.POST - if request_post: - if request_post.get('first_name'): - queryset = queryset.filter(first_name__icontains=request_post.get('first_name')) - if request_post.get('last_name'): - queryset = queryset.filter(last_name_id=request_post.get('last_name')) - if request_post.get('username'): - queryset = queryset.filter(username__icontains=request_post.get('username')) - if request_post.get('email'): - queryset = queryset.filter(email__icontains=request_post.get('email')) - if request_post.get('status'): - queryset = queryset.filter(is_active=request_post.get('status')) return queryset def get_context_data(self, **kwargs): context = super(UsersListView, self).get_context_data(**kwargs) context["users"] = self.get_queryset() - context["active_users"] = self.get_queryset().filter(is_active=True) - context["inactive_users"] = self.get_queryset().filter(is_active=False) context["per_page"] = self.request.POST.get('per_page') context['admin_email'] = settings.ADMIN_EMAIL return context diff --git a/leads/forms.py b/leads/forms.py index a43d3132..2b88e365 100644 --- a/leads/forms.py +++ b/leads/forms.py @@ -15,7 +15,6 @@ class LeadForm(forms.ModelForm): self.fields['assigned_to'].queryset = assigned_users self.fields['assigned_to'].required = False self.fields['teams'].required = False - self.fields['phone'].required = True for key, value in self.fields.items(): if key == 'phone': value.widget.attrs['placeholder'] = 'Enter phone number with country code' diff --git a/leads/migrations/0003_auto_20190211_1142.py b/leads/migrations/0003_auto_20190211_1142.py new file mode 100644 index 00000000..df024893 --- /dev/null +++ b/leads/migrations/0003_auto_20190211_1142.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-02-11 06:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('leads', '0002_lead_tags'), + ] + + operations = [ + migrations.AlterField( + model_name='lead', + name='email', + field=models.EmailField(blank=True, max_length=254, null=True), + ), + ] diff --git a/leads/models.py b/leads/models.py index ad6a53bb..63f83f6e 100644 --- a/leads/models.py +++ b/leads/models.py @@ -13,7 +13,7 @@ class Lead(models.Model): title = models.CharField(pgettext_lazy("Treatment Pronouns for the customer", "Title"), max_length=64, blank=True, null=True) first_name = models.CharField(("First name"), max_length=255) last_name = models.CharField(("Last name"), max_length=255) - email = models.EmailField() + email = models.EmailField(null=True, blank=True) phone = PhoneNumberField(null=True, blank=True) account = models.ForeignKey(Account, related_name='Leads', on_delete=models.CASCADE, blank=True, null=True) status = models.CharField(_("Status of Lead"), max_length=255, blank=True, null=True, choices=LEAD_STATUS) diff --git a/leads/templates/create_lead.html b/leads/templates/create_lead.html index cd2b4d57..b07f7c47 100644 --- a/leads/templates/create_lead.html +++ b/leads/templates/create_lead.html @@ -32,13 +32,15 @@
    -
    + {{ lead_form.first_name }} {{ lead_form.first_name.errors }}
    +
    + {{ lead_form.last_name }} {{ lead_form.last_name.errors }}
    diff --git a/leads/templates/leads.html b/leads/templates/leads.html index 9f080b61..4ed8d38f 100644 --- a/leads/templates/leads.html +++ b/leads/templates/leads.html @@ -1,6 +1,9 @@ {% extends 'base.html' %} {% load staticfiles %} {% load paginate %} +{% block extralinks %} + +{% endblock %} {% block content %}
    @@ -21,17 +24,32 @@
    - - + +
    - - + +
    -
    -
    +
    +
    +
    + + +
    +
    +
    -
    +
    +
    @@ -66,99 +85,202 @@
    -
    +
    -
    - -
    -
    - Leads - {% if show_pageitems %} {% show_pageitems %}{% else %} {{ lead_obj|length }}{% endif %} - - - + +
    +
    +
    +
    +
    + Open Leads - {% if show_pageitems %} {% show_pageitems %}{% else %} {{ open_leads|length }}{% endif %} + + + +
    +
    + + + {% if open_leads|length > 0 %} + + + + + + + + + + {% endif %} + + + {% if per_page %} + {% paginate per_page open_leads %} + {% else %} + {% paginate 10 open_leads %} + {% endif %} + {% for lead in open_leads %} + + + + + + + + + + {% endfor %} + +
    IDNameStatusAssigned UserTagsCreated OnActions
    {{ forloop.counter }}{{ lead.first_name }} {{ lead.last_name }}{{ lead.get_status_display }} + {% with lead_users=lead.assigned_to.all %} + {% if lead_users %} + {% for user in lead_users %} + {{ user.email }}
    + {% endfor %} + {% else %} + Not Assigned to Any + {% endif %} + {% endwith %} +
    + {% with tags=lead.tags.all %} + {% if tags %} + {% for tag in tags %} + {{ tag.name }}
    + {% endfor %} + {% else %} + No Tags + {% endif %} + {% endwith %} +
    {{ lead.created_on }} + + +
    +
    + {%ifequal open_leads|length 0%} +
    No Open Lead Records Found
    + {%endifequal%} +
    + {% show_pages %} +
    +
    -
    - - - {% if lead_obj|length > 0 %} - - - - - - - - - - {% endif %} - - - {% if per_page %} - {% paginate per_page lead_obj %} - {% else %} - {% paginate 10 lead_obj %} - {% endif %} - {% for lead in lead_obj %} - - - - - + + + + + + + + + {% endfor %} + +
    IDNameStatusAssigned UserTagsCreated OnActions
    {{ forloop.counter }}{{ lead.first_name }} {{ lead.last_name }}{{ lead.get_status_display }} - {% with lead_users=lead.assigned_to.all %} - {% if lead_users %} - {% for user in lead_users %} - {{ user.email }}
    - {% endfor %} + +
    +
    +
    +
    + Closed Leads - {% if show_pageitems %} {% show_pageitems %}{% else %} {{ close_leads|length }}{% endif %} + + + +
    +
    + + + {% if close_leads|length > 0 %} + + + + + + + + + + {% endif %} + + + {% if per_page %} + {% paginate per_page close_leads %} {% else %} - Not Assigned to Any + {% paginate 10 close_leads %} {% endif %} - {% endwith %} - - - - - - {% endfor %} - -
    IDNameStatusAssigned UserTagsCreated OnActions
    - {% with tags=lead.tags.all %} - {% if tags %} - {% for tag in tags %} - {{ tag.name }}
    - {% endfor %} - {% else %} - No Tags - {% endif %} - {% endwith %} -
    {{ lead.created_on }} - {# #} - - -
    -
    - {%ifequal lead_obj|length 0%} -
    No Lead Records Found
    - {%endifequal%} -
    - {% show_pages %} + {% for lead in close_leads %} +
    {{ forloop.counter }}{{ lead.first_name }} {{ lead.last_name }}{{ lead.get_status_display }} + {% with lead_users=lead.assigned_to.all %} + {% if lead_users %} + {% for user in lead_users %} + {{ user.email }}
    + {% endfor %} + {% else %} + Not Assigned to Any + {% endif %} + {% endwith %} +
    + {% with tags=lead.tags.all %} + {% if tags %} + {% for tag in tags %} + {{ tag.name }}
    + {% endfor %} + {% else %} + No Tags + {% endif %} + {% endwith %} +
    {{ lead.created_on }} + + +
    +
    + {%ifequal close_leads|length 0%} +
    No Dead Lead Records Found
    + {%endifequal%} +
    + {% show_pages %} +
    +
    +
    -
    -
    - + {% endblock %} {% block js_block %} +