From fa156da43991fc07ede09530dfe56579b4ac181a Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Sat, 29 Sep 2018 15:55:38 +0530 Subject: [PATCH] code enhancements (#90) --- accounts/templates/view_account.html | 2 ++ accounts/views.py | 21 +++++++++---- common/templates/create.html | 14 +++++++-- common/templates/list.html | 6 +++- common/urls.py | 14 +++++---- common/views.py | 19 +++++++----- contacts/models.py | 3 ++ contacts/views.py | 44 ++++++++++++++++------------ crm/urls.py | 2 +- requirements.txt | 2 +- static/css/main.scss | 21 ++++++++++++- templates/base.html | 8 ++--- templates/change_password.html | 4 +-- templates/profile.html | 2 ++ 14 files changed, 113 insertions(+), 49 deletions(-) diff --git a/accounts/templates/view_account.html b/accounts/templates/view_account.html index 6f161fe2..194a927a 100644 --- a/accounts/templates/view_account.html +++ b/accounts/templates/view_account.html @@ -154,6 +154,7 @@
+ {% if comment_permission %}
@@ -164,6 +165,7 @@
+ {% endif %}
    {% for comment in comments %}
  • diff --git a/accounts/views.py b/accounts/views.py index c6128df3..260e2fc2 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,7 +1,10 @@ from django.contrib.auth.mixins import LoginRequiredMixin -from django.http import JsonResponse -from django.shortcuts import get_object_or_404, redirect -from django.views.generic import CreateView, UpdateView, DetailView, TemplateView, View, DeleteView +from django.contrib.auth.decorators import login_required +from django.http import HttpResponseRedirect, HttpResponse, JsonResponse +from django.shortcuts import render, get_object_or_404, redirect +from django.urls import reverse +from django.views.generic import ( + CreateView, UpdateView, DetailView, ListView, TemplateView, View, DeleteView) from accounts.models import Account from common.models import User, Address, Team, Comment @@ -129,6 +132,13 @@ class AccountDetailView(LoginRequiredMixin, DetailView): def get_context_data(self, **kwargs): context = super(AccountDetailView, self).get_context_data(**kwargs) account_record = context["account_record"] + if ( + self.request.user in account_record.assigned_to.all() or + self.request.user == account_record.created_by + ): + comment_permission = True + else: + comment_permission = False context.update({ "comments": account_record.accounts_comments.all(), "opportunity_list": Opportunity.objects.filter(account=account_record), @@ -143,6 +153,7 @@ class AccountDetailView(LoginRequiredMixin, DetailView): "case_types": CASE_TYPE, "case_priority": PRIORITY_CHOICE, "case_status": STATUS_CHOICE, + 'comment_permission': comment_permission, }) return context @@ -211,9 +222,9 @@ class AccountUpdateView(LoginRequiredMixin, UpdateView): else: if self.request.POST: context["billing_form"] = BillingAddressForm( - request.POST, instance=self.object.billing_address) + self.request.POST, instance=self.object.billing_address) context["shipping_form"] = ShippingAddressForm( - request.POST, instance=self.object.shipping_address, prefix='ship') + self.request.POST, instance=self.object.shipping_address, prefix='ship') else: context["billing_form"] = BillingAddressForm( instance=self.object.billing_address) diff --git a/common/templates/create.html b/common/templates/create.html index bfb2d36e..074453f8 100644 --- a/common/templates/create.html +++ b/common/templates/create.html @@ -16,7 +16,11 @@
    + {% if user_obj %} + EDIT USER + {% else %} CREATE USER + {% endif %}
    @@ -44,7 +48,7 @@
    - +
    {{ errors.email }} @@ -52,8 +56,12 @@
    - {% if request.user.role == 'ADMIN' %} - {{ user_form.role }} + {% if request.user.role == 'ADMIN' or request.user.is_superuser %} + {% else %}