Sindbad~EG File Manager

Current Path : /home/numerotech/sa.aios-scientificcommittee.org/aios_sa_app/core/library/
Upload File :
Current File : //home/numerotech/sa.aios-scientificcommittee.org/aios_sa_app/core/library/helper.py

from core import app
from flask import render_template_string
from flask import url_for
from datetime import datetime, date, time, timedelta
import datetime
import imp,sys
import random
import base64
import requests

#settime working as global variable but commented for easy identification of this variable using class name 
# global settime
# settime = 5

class Helper:
    Institution = ['ksos23']
    live_domain = "https://sc.aios-scientificcommittee.org/1/aios"
    cdn_url="https://cdn.jsdelivr.net/gh/NumeroTec/ntec_cdn@main/"
    def_cat_id = 161
    mark1 = 10
    mark2 = 10
    mark3 = 10
    test_mail = "mukeshkumar@numerotec.com"
    testmail = "mukeshkumar@numerotec.com"
    master_email_ids = ["mukeshkumar@numerotec.com","manjula@numerotec.com","priyavarthana@numerotec.com"]
    CC_Presentation_type_id = 23
    
    def isAjax(request):
        if request.headers.get("X-Requested-With") == "XMLHttpRequest":
            return True
        else:
            return False 

    def convert_jinja_template_v1(data1,data):
        # data1 = data1[0]
        temp = app.jinja_env.from_string(data1["template_data"]).render(data=data)
        return render_template_string(temp)

    def convert_jinja_template(data1,data):
        data1 = data1[0]
        temp = app.jinja_env.from_string(data1["template_data"]).render(data=data)
        return render_template_string(temp)

    def footer_text():
        return ""
    
    def random_color():
        light_colors = ["#EDD1E0","#F0DEDE","#F1EFF0","#F8ECD7","#F8D5C1","#96DFCE","#DDECEF","#F8D5DB","#EFF1D9","#F1EB86","#FBFAF5","#F7F4E5","#F8EECA","#F6E2CA","#E8DAD7","#87E0E0","#A0E7E5","#BAEDE6","#CEF2EE","#DBF9F9","#EADCED","#FFE7CD","#FFD2CD","#F8D4DE","#D2ECFB"]
        random.shuffle(light_colors)
    
        # Return the first element of the shuffled list
        return light_colors[0]

    def email_mask(email):
        if email:
            lo = email.find('@')
            if lo>0:
                mask_email =  email[0]+"*****"+email[lo-1:]
            return mask_email
        return email

    def mobile_mask(mobile):
        if mobile:
            lo = len(mobile)
            if lo>0:
                mask =  mobile[:2]+"******"+mobile[lo-2:]
                return mask
        return mobile

    def call_custom_controller(abs_type):
        module_name = abs_type+"Controller"
        fp, pathname, description = imp.find_module(module_name,["./core/controller"])
        module = imp.load_module(module_name, fp, pathname, description)
        myclass = getattr(module, module_name)
        return myclass

    def merge_tags(text,values):
        for k, v in values.items():
            text = text.replace('*|'+k+'|*', v)
        return text

    def convert_html_for_mail_screen(data):
        temp = app.jinja_env.from_string("{{mail_content|safe}}").render(**data)
        return render_template_string(temp,**data)
        
    def getcurrenttimestamp():
        ct = datetime.datetime.now()
        ts = ct.timestamp()
        return ts 
    
    def calculate_age(born):
        today = date.today()
        return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

    def get_role_data(absData):
        chiefins    = None
        coins       = []
        chiefauthor = None
        presauthor  = None
        coauthor    = []
        others      = []
        for item in absData['topics']:
            if item['role_id'] == 32:
                chiefins = item
            if item['role_id'] == 33:
                coins.append(item)
            if item['role_id'] == 34:
                chiefauthor = item
            if item['role_id'] == 35:
                presauthor = item
            if item['role_id'] == 36:
                coauthor.append(item)
            if item['role_id'] not in (32,33,34,35,36):
                others.append(item)

        return chiefins,coins,chiefauthor,presauthor,coauthor,others
    
    def get_level_badge_for_IC(level):
        
        if level=='Intermediate':
            data='<span title="Intermediate" class="badge badge-warning p-2"><i class="fa fa-solid fa-i"></i></span>'
        elif level=='Basic':
            data='<span title="Basic" class="badge badge-success p-2"><i class="fa-solid fa-b"></i></span>'
        else:
            data='<span title="Advance" class="badge badge-danger p-2"><i class="fa-solid fa-a"></i> </span>'

        return data
    
    def get_url_base64(url):
        return "data:image/jpg;base64," + base64.b64encode(requests.get(url).content).decode('ascii')	
        
app.jinja_env.globals.update(Helper=Helper) 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists