a #e@sddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZGd d d ejZe e ed ddZe e ed ddZdS)N)User)models) gettext_lazy) post_save)receiver)Task)Sum)cache)settingsc@s~eZdZejeejdZejdde de ddZ ddZ d d Z d d Z d dZddZddZddZddZddZdS)Profile) on_deleteTzMaximum disk quota in megabytesZQuota)defaultblank help_text verbose_namecCs |jdkS)Nr )quotaselfr/webodm/app/models/profile.py has_quotaszProfile.has_quotacCs0tjj|jdjtddd}|dur,d}|S)N)Zproject__ownersize)totalrr)robjectsfilteruser aggregaterrqrrr used_quotas zProfile.used_quotacCs|s dS|}||jkSNF)rr rrrrrhas_exceeded_quotaszProfile.has_exceeded_quotacCs>d|jj}t|}|dur$|S|}t||d|S)N used_quota_i)ridr getr set)rkcachedvrrrused_quota_cached!s zProfile.used_quota_cachedcCs|s dS|}||jkSr!)rr*rrrrrhas_exceeded_quota_cached+sz!Profile.has_exceeded_quota_cachedcCstd|jjdS)Nr#r deleterr$rrrrclear_used_quota_cache2szProfile.clear_used_quota_cachecCstd|jjSNquota_deadline_)r r%rr$rrrrget_quota_deadline5szProfile.get_quota_deadlinec CsPd|jj}|dd}t|}t||tt|dtjdd|S)Nr0< ) rr$timer r&intmaxr QUOTA_EXCEEDED_GRACE_PERIOD)rhoursr'secondsr)rrrset_quota_deadline8s   &zProfile.set_quota_deadlinecCstd|jjdSr/r,rrrrclear_quota_deadline?szProfile.clear_quota_deadlineN)__name__ __module__ __qualname__r OneToOneFieldrCASCADEr FloatField_rrr r"r*r+r.r1r:r;rrrrr s r )sendercKs|rtjj|ddS)N)r)r rcreate)rCinstancecreatedkwargsrrrcreate_user_profileCsrHcKs|jdS)N)profilesave)rCrErGrrrsave_user_profileHsrK)r4django.contrib.auth.modelsr django.dbrdjango.utils.translationrrBZdjango.db.models.signalsrdjango.dispatchrZ app.modelsrdjango.db.modelsrdjango.core.cacher Zwebodmr Modelr rHrKrrrrs         6