[UPDT] EMPLOYEE: Changed employee image from if condition to get_avatar method
This commit is contained in:
@@ -5,6 +5,8 @@ This module is used to register models for employee app
|
||||
|
||||
"""
|
||||
from datetime import date, datetime
|
||||
import os
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Permission
|
||||
from django.utils.translation import gettext_lazy as trans
|
||||
@@ -116,7 +118,12 @@ class Employee(models.Model):
|
||||
f"https://ui-avatars.com/api/?name={self.get_full_name()}&background=random"
|
||||
)
|
||||
if self.employee_profile:
|
||||
url = self.employee_profile.url
|
||||
image_url = self.employee_profile.url.split("/media/")[1]
|
||||
media_root = settings.MEDIA_ROOT
|
||||
image_path = os.path.join(media_root, image_url)
|
||||
|
||||
if os.path.exists(image_path):
|
||||
url = self.employee_profile.url
|
||||
return url
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
||||
@@ -38,19 +38,11 @@
|
||||
</div>
|
||||
<div class="oh-profile oh-profile--md">
|
||||
<div class="oh-profile__avatar mr-1">
|
||||
{% if candidate.profile %}
|
||||
<img
|
||||
src="{{candidate.profile.url}}"
|
||||
src="{{candidate.get_avatar}}"
|
||||
class="oh-profile__image"
|
||||
alt="{{candidate.name}}"
|
||||
/>
|
||||
{% else %}
|
||||
<img
|
||||
src="https://ui-avatars.com/api/?name={{candidate.name}}&background=random"
|
||||
class="oh-profile__image"
|
||||
alt="{{candidate.name}}"
|
||||
/>
|
||||
{% endif %}
|
||||
</div>
|
||||
<span class="oh-profile__name oh-text--dark"
|
||||
>{{candidate.name}}</span
|
||||
@@ -67,7 +59,7 @@
|
||||
style="color: inherit; text-decoration: none"
|
||||
class="oh-sticky-table__td"
|
||||
>
|
||||
{% comment %} {{candidate.joining_date}} {% endcomment %} <input
|
||||
<input
|
||||
type="date" class="oh-input joining-date"
|
||||
value={{candidate.joining_date|date:"Y-m-d"}} name="joining_date"
|
||||
data-candidate-id="{{candidate.id}}">
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
<img
|
||||
src="https://ui-avatars.com/api/?name={{cand}}&background=random"
|
||||
class="oh-profile__image"
|
||||
alt="{{cand}}"
|
||||
alt=""
|
||||
/>
|
||||
</div>
|
||||
<span class="oh-profile__name oh-text--dark">{{cand}}</span>
|
||||
|
||||
@@ -186,7 +186,7 @@
|
||||
<div class="oh-kanban__card-head">
|
||||
<div class="oh-profile oh-profile--md">
|
||||
<div class="oh-profile__avatar mr-1">
|
||||
<img src="https://ui-avatars.com/api/?name={{candidate.candidate_id.name}}&background=random" class="oh-profile__image" alt="Hella">
|
||||
<img src="{{candidate.candidate_id.get_avatar}}" class="oh-profile__image" alt="">
|
||||
</div>
|
||||
<span class="oh-profile__name oh-text--dark fw-bold" data-type="label">{{candidate.candidate_id.name}}</span>
|
||||
</div>
|
||||
|
||||
@@ -181,13 +181,8 @@
|
||||
/>
|
||||
</div>
|
||||
<div class="oh-profile__avatar mr-1">
|
||||
{% if candidate.candidate_id.profile %}
|
||||
<img src="{{candidate.candidate_id.profile.url}}"
|
||||
<img src="{{candidate.candidate_id.get_avatar}}"
|
||||
class="oh-profile__image" alt="" />
|
||||
{% else %}
|
||||
<img src="https://ui-avatars.com/api/?name={{candidate.candidate_id}}&background=random"
|
||||
class="oh-profile__image" alt="" />
|
||||
{% endif %}
|
||||
</div>
|
||||
<span class="oh-profile__name oh-text--dark">{{candidate.candidate_id}}</span>
|
||||
</div>
|
||||
|
||||
@@ -54,11 +54,7 @@
|
||||
<div class="oh-input-group w-100 d-flex justify-content-center">
|
||||
<div class="oh-profile-section__edit-photo me-4 mb-3" data-toggle="oh-modal-toggle"
|
||||
data-target="#uploadPhotoModal">
|
||||
{% if candidate.profile %}
|
||||
<img src="{{candidate.profile.url}}" class="oh-profile-section__avatar" alt="{{candidate.name}}"/>
|
||||
{% else %}
|
||||
<img src="https://ui-avatars.com/api/?name={{candidate}}&background=random" class="oh-profile-section__avatar" alt="{{candidate.name}}"/>
|
||||
{% endif %}
|
||||
<img src="{{candidate.get_avatar}}" class="oh-profile-section__avatar" alt="{{candidate.name}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<h2 class="oh-onboarding-card__greeting text-center">Welcome Aboard</h2>
|
||||
@@ -91,13 +87,8 @@
|
||||
<div class="oh-modal__dialog-body">
|
||||
<div class="oh-profile-section__image-container">
|
||||
<div class="oh-profile-section__modal-avatar">
|
||||
{% if candidate.profile %}
|
||||
<img src="{{candidate.profile.url}}"
|
||||
<img src="{{candidate.get_avatar}}"
|
||||
class="oh-profile-section__modal-image oh-upload-photo" alt="User Photo" />
|
||||
{% else %}
|
||||
<img src="https://ui-avatars.com/api/?name={{candidate}}&background=random"
|
||||
class="oh-profile-section__modal-image oh-upload-photo" alt="User Photo" />
|
||||
{% endif %}
|
||||
</div>
|
||||
<input type="file"
|
||||
class="oh-input oh-input--file oh-input--file-sm mt-4 oh-upload-input"
|
||||
|
||||
@@ -3,13 +3,8 @@
|
||||
<div class="oh-timeoff-modal__profile-content">
|
||||
<div class="oh-profile">
|
||||
<div class="oh-profile-section__edit-photo me-3" >
|
||||
{% if candidate.profile %}
|
||||
<img src="{{candidate.profile.url}}"
|
||||
<img src="{{candidate.get_avatar}}"
|
||||
class="oh-profile-section__modal-image" alt="" />
|
||||
{% else %}
|
||||
<img src="https://ui-avatars.com/api/?name={{candidate}}&background=random"
|
||||
class="oh-profile-section__modal-image" alt="" />
|
||||
{% endif %}
|
||||
</div>
|
||||
<div >
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import os
|
||||
import json
|
||||
from django import forms
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -284,7 +285,13 @@ class Candidate(models.Model):
|
||||
f"https://ui-avatars.com/api/?name={self.get_full_name()}&background=random"
|
||||
)
|
||||
if self.profile:
|
||||
url = self.profile.url
|
||||
image_url = self.profile.url.split("/media/")[1]
|
||||
media_root = settings.MEDIA_ROOT
|
||||
|
||||
image_path = os.path.join(media_root, image_url)
|
||||
if os.path.exists(image_path):
|
||||
url = self.profile.url
|
||||
|
||||
return url
|
||||
|
||||
def tracking(self):
|
||||
|
||||
Reference in New Issue
Block a user