diff --git a/accounts/templates/view_account.html b/accounts/templates/view_account.html index dbb875e3..c265ec00 100644 --- a/accounts/templates/view_account.html +++ b/accounts/templates/view_account.html @@ -236,6 +236,7 @@
+ {% if contacts|length > 0 %} @@ -245,6 +246,7 @@ + {% endif %} {% for contact in contacts %} @@ -262,6 +264,9 @@
S.NoActions
+ {% ifequal contacts|length 0 %} +
No Contact Records Found
+ {% endifequal %}
@@ -748,6 +753,7 @@
+ {% if opportunity_list|length > 0 %} @@ -757,6 +763,7 @@ + {% endif %} {% for opportunity in opportunity_list %} @@ -774,6 +781,9 @@
S.NoActions
+ `{% ifequal contacts|length 0 %} +
No Opportunity Records Found
+ {% endifequal %}
@@ -1306,6 +1316,7 @@
+ {% if cases|length > 0 %} @@ -1315,6 +1326,7 @@ + {% endif %} {% for case in cases %} @@ -1333,6 +1345,9 @@
S.NoActions
+ {% ifequal cases|length 0 %} +
No Case Records Found
+ {% endifequal %}
diff --git a/cases/templates/cases.html b/cases/templates/cases.html index c69cfddd..80c8d698 100644 --- a/cases/templates/cases.html +++ b/cases/templates/cases.html @@ -96,6 +96,7 @@ {% if cases|length > 0 %} + diff --git a/common/forms.py b/common/forms.py index 2ad64199..791e0eac 100644 --- a/common/forms.py +++ b/common/forms.py @@ -55,7 +55,7 @@ class UserForm(forms.ModelForm): class Meta: model = User - fields = ['email', 'first_name', 'last_name', 'username', 'role'] + fields = ['email', 'first_name', 'last_name', 'username', 'role', 'profile_pic'] def __init__(self, *args, **kwargs): super(UserForm, self).__init__(*args, **kwargs) diff --git a/common/migrations/0004_user_profile_pic.py b/common/migrations/0004_user_profile_pic.py new file mode 100644 index 00000000..0d56b18d --- /dev/null +++ b/common/migrations/0004_user_profile_pic.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.1 on 2018-10-09 06:44 + +import common.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0003_user_role'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='profile_pic', + field=models.FileField(blank=True, max_length=1000, null=True, upload_to=common.models.img_url), + ), + ] diff --git a/common/models.py b/common/models.py index 873c957e..a8052d89 100644 --- a/common/models.py +++ b/common/models.py @@ -3,9 +3,16 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager from common.utils import COUNTRIES, ROLES +import time + + +def img_url(self, filename): + hash_ = int(time.time()) + return "%s/%s/%s" % ("profile_pics", hash_, filename) class User(AbstractBaseUser, PermissionsMixin): + file_prepend = "users/profile_pics" username = models.CharField(max_length=100, unique=True) first_name = models.CharField(max_length=150, blank=True) last_name = models.CharField(max_length=150, blank=True) @@ -15,6 +22,8 @@ class User(AbstractBaseUser, PermissionsMixin): is_staff = models.BooleanField(default=False) date_joined = models.DateTimeField(('date joined'), auto_now_add=True) role = models.CharField(max_length=50, choices=ROLES) + profile_pic = models.FileField(max_length=1000, upload_to=img_url, null=True, blank=True) + USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['username', ] diff --git a/common/templates/create.html b/common/templates/create.html index aeb01c0a..c0e3b80c 100644 --- a/common/templates/create.html +++ b/common/templates/create.html @@ -25,21 +25,21 @@ - {{ errors.first_name }} + {{ errors.first_name }}
- {{ errors.last_name }} + {{ errors.last_name }}
- {{ errors.username }} + {{ errors.username }}
@@ -47,7 +47,7 @@
- {{ errors.email }} + {{ errors.email }}
@@ -63,7 +63,7 @@ {% endif %} - {{ user_form.role.errors }} + {{ user_form.role.errors }}
{% if not user_obj %} @@ -72,9 +72,17 @@ - {{ errors.password }} + {{ errors.password }} {% endif %} +
+
+ + +
+ {% if user_obj %}{{user_obj.profile_pic }}{% endif %} + {{ errors.profile_pic }} +
@@ -87,3 +95,26 @@
{% endblock content %} +{% block js_block %} + + +{% endblock js_block %} \ No newline at end of file diff --git a/common/templates/list.html b/common/templates/list.html index b63b9ccc..a8ced844 100644 --- a/common/templates/list.html +++ b/common/templates/list.html @@ -72,6 +72,7 @@
S.No Name
{% if users|length > 0 %} + @@ -105,7 +106,7 @@
S.No First Name - {% if request.user.id != user.id and user.email != "admin@micropyramid.com" %} + {% if user.email != admin_email or request.user.email == admin_email %} Edit {% endif %} diff --git a/common/urls.py b/common/urls.py index ed46d661..afd1f935 100644 --- a/common/urls.py +++ b/common/urls.py @@ -4,6 +4,8 @@ from django.urls import path, re_path from common.views import ( HomeView, LoginView, ForgotPasswordView, LogoutView, ChangePasswordView, ProfileView, UsersListView, CreateUserView, UpdateUserView, UserDetailView, UserDeleteView) +from django.conf.urls.static import static +from django.conf import settings app_name = 'common' @@ -32,4 +34,4 @@ urlpatterns = [ path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/common/views.py b/common/views.py index 62297711..0da9a7b5 100644 --- a/common/views.py +++ b/common/views.py @@ -1,12 +1,14 @@ from django.contrib.auth import logout, authenticate, login from django.contrib.auth.hashers import check_password from django.contrib.auth.mixins import LoginRequiredMixin, AccessMixin -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, JsonResponse from django.shortcuts import render, redirect, get_object_or_404 from django.views.generic import ( CreateView, UpdateView, DetailView, TemplateView, View, DeleteView) from common.models import User from common.forms import UserForm, LoginForm, ChangePasswordForm +from django.urls import reverse_lazy +from django.conf import settings def handler404(request, exception): @@ -132,6 +134,7 @@ class UsersListView(AdminRequiredMixin, TemplateView): 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 def post(self, request, *args, **kwargs): @@ -149,11 +152,17 @@ class CreateUserView(AdminRequiredMixin, CreateView): if form.cleaned_data.get("password"): user.set_password(form.cleaned_data.get("password")) user.save() - return redirect("common:users_list") + if self.request.is_ajax(): + data = {'success_url': reverse_lazy('common:users_list'), 'error': False} + return JsonResponse(data) + return super(CreateUserView, self).form_valid(form) + def form_invalid(self, form): - return self.render_to_response( - self.get_context_data(form=form, errors=form.errors)) + response = super(CreateUserView, self).form_invalid(form) + if self.request.is_ajax(): + return JsonResponse({'error': True, 'errors': form.errors}) + return response def get_context_data(self, **kwargs): context = super(CreateUserView, self).get_context_data(**kwargs) @@ -190,12 +199,20 @@ class UpdateUserView(LoginRequiredMixin, UpdateView): user.is_superuser = False user.save() if self.request.user.role == "ADMIN" or self.request.user.is_superuser: - return redirect("common:users_list") - return redirect("common:profile") + if self.request.is_ajax(): + data = {'success_url': reverse_lazy('common:users_list'), 'error': False} + return JsonResponse(data) + if self.request.is_ajax(): + data = {'success_url': reverse_lazy('common:profile'), 'error': False} + return JsonResponse(data) + return super(UpdateUserView, self).form_valid(form) + def form_invalid(self, form): - return self.render_to_response( - self.get_context_data(form=form, errors=form.errors)) + response = super(UpdateUserView, self).form_invalid(form) + if self.request.is_ajax(): + return JsonResponse({'error': True, 'errors': form.errors}) + return response def get_context_data(self, **kwargs): context = super(UpdateUserView, self).get_context_data(**kwargs) diff --git a/contacts/templates/contacts.html b/contacts/templates/contacts.html index 9da90473..e64fac40 100644 --- a/contacts/templates/contacts.html +++ b/contacts/templates/contacts.html @@ -78,6 +78,7 @@
+ {% if contact_obj_list|length > 0 %} diff --git a/crm/settings.py b/crm/settings.py index f1f52ca7..0d9b9f5f 100644 --- a/crm/settings.py +++ b/crm/settings.py @@ -34,6 +34,7 @@ INSTALLED_APPS = [ 'leads', 'opportunity', 'planner', + 'sorl.thumbnail', ] @@ -182,3 +183,5 @@ SG_USER = os.getenv('SG_USER', '') SG_PWD = os.getenv('SG_PWD', '') MANDRILL_API_KEY = os.getenv('MANDRILL_API_KEY', '') + +ADMIN_EMAIL = "admin@micropyramid.com" diff --git a/leads/templates/view_leads.html b/leads/templates/view_leads.html index 5cc9e716..15dcbb61 100644 --- a/leads/templates/view_leads.html +++ b/leads/templates/view_leads.html @@ -186,7 +186,8 @@
S.no
{% if opportunity_list|length > 0 %} + diff --git a/opportunity/templates/view_opportunity.html b/opportunity/templates/view_opportunity.html index 49f6ccc1..5e23541d 100644 --- a/opportunity/templates/view_opportunity.html +++ b/opportunity/templates/view_opportunity.html @@ -168,7 +168,8 @@
S.No Name