def get_user_expiry(name, password, lang, _ip): user = Users.objects.filter(name__iexact=name, ).first() user_ip, create = BlockIP.objects.get_or_create(ip=_ip) if user and check_password(password, user.password): user_ip.faild_try = 0 user_ip.block = False user_ip.save() if lang == "fa": oreder = date2jalali(user.order_date).strftime('%Y-%m-%d') expire = date2jalali(user.order_expire).strftime('%Y-%m-%d') else: oreder = datetime.strftime(user.order_date, '%Y-%m-%d') expire = datetime.strftime(user.order_expire, '%Y-%m-%d') result = { 'name': user.name, 'order': oreder, 'expire': expire, } return result user_ip.faild_try += 1 user_ip.save() if user_ip.faild_try > 5: user_ip.block = True user_ip.save() return False
def month(value): date = jalali_date.date2jalali(value) month = None if date.month == 1: month = 'فروردین' elif date.month == 2: month = 'اردیبهشت' elif date.month == 3: month = 'خرداد' elif date.month == 4: month = 'تیر' elif date.month == 5: month = 'مرداد' elif date.month == 6: month = 'شهریور' elif date.month == 7: month = 'مهر' elif date.month == 8: month = 'آبان' elif date.month == 9: month = 'آذر' elif date.month == 10: month = 'دی' elif date.month == 11: month = 'بهمن' elif date.month == 12: month = 'اسفند' return month
def to_jalali(g_date, strftime=None): if g_date is None: return '-' elif isinstance(g_date, datetime): return datetime2jalali(g_date).strftime( strftime if strftime else '%y/%m/%d _ %H:%M:%S') elif isinstance(g_date, date): return date2jalali(g_date).strftime( strftime if strftime else '%y/%m/%d') return '-'
def to_jalali(g_date, strftime=None): if g_date is None: return '-' elif isinstance(g_date, datetime): strftime = strftime if strftime else DEFAULTS['Strftime']['datetime'] return datetime2jalali(g_date).strftime(strftime) elif isinstance(g_date, date): strftime = strftime if strftime else DEFAULTS['Strftime']['date'] return date2jalali(g_date).strftime(strftime) return '-'
def supply_list_view(request): if request.method == 'POST' and request.POST['supply_id'] and request.POST[ 'supply_price']: id = request.POST['supply_id'] supply = SupplyOrder.objects.get(id=id) supply.price = request.POST['supply_price'] supply.save() Activity.objects.create( type='خرید', title='خرید محصول ' + supply.name + 'به مقدار ' + supply.amount, description='در تاریخ ' + date2jalali(getNow().date()).strftime('%y/%m/%d'), moneyTrade=supply.price) supplies = SupplyOrder.objects.all() return render(request, 'supply_list.html', {'supplies': supplies})
def jalali_admin_safe_readonly(readonly_field, strftime=None): """ :param readonly_field: django.contrib.admin.helpers.AdminReadOnlyField :param strftime: format output :return: str """ instance = readonly_field.form.instance field_name = readonly_field.field['field'] if not hasattr(instance, field_name): return readonly_field field = getattr(instance, field_name) if isinstance(field, datetime): strftime = strftime if strftime else DEFAULTS['Strftime']['datetime'] return ObjectContents(datetime2jalali(field).strftime(strftime)) elif isinstance(field, date): strftime = strftime if strftime else DEFAULTS['Strftime']['date'] return ObjectContents(date2jalali(field).strftime(strftime)) elif field is None: return ObjectContents('-') return readonly_field
def handle_jobtime(request): if request.method != 'POST': return JsonResponse({}) # handle nothing employee = request.user response = {} if employee.workBegan is None: employee.workBegan = getNow() employee.save() response['work'] = 1 else: Activity.objects.create( type='گزارش کارمند', title=' ساعت کاری آقا/خانم ' + employee.first_name + ' ' + employee.last_name, description='در تاریخ ' + date2jalali(getNow().date()).strftime('%y/%m/%d') + 'آقا/خانم ' + employee.first_name + ' ' + employee.last_name + 'از ساعت ' + employee.workBegan.strftime('%H:%M') + ' تا ساعت ' + getNow().strftime('%H:%M') + ' مشغول به کار بودند.', moneyTrade=0) employee.workBegan = None employee.save() response['work'] = 0 return JsonResponse(response)
def year(value): date = jalali_date.date2jalali(value) year = date.year return year
def shamsi(value): try: date = jalali_date.date2jalali(value) return str(date.year) + '/' + str(date.month) + '/' + str(date.day) except: return 'ثبت نشده'
def jalali_date(self, obj): return date2jalali(obj.date).strftime('%y/%m/%d')
def day(value): date = jalali_date.date2jalali(value) day = date.day return day
def convert_date_to_jalali(obj): return date2jalali(obj.date)
def shamsi(value): date = jalali_date.date2jalali(value) return date
def since(self): from jalali_date import date2jalali return date2jalali(self.date_joined).strftime('13%y-%m-%d')
def jrequestDate(self, obj): if obj.requestDate: return str(date2jalali(obj.requestDate)).replace('-', '/') else: return '-'
def review_directory_path(obj, filename): return 'AdReview/ad_{0}/{1}__{2}'.format( obj.id, date2jalali(datetime.today()).strftime('%y_%m_%d'), filename)