Example #1
0
def listproducts(request):
    if request.method == 'GET':

        temp_list = ProductSubmit.objects.filter(
            submitter=request.user.username)
        if request.GET.get('search'):
            temp_list = temp_list.filter(
                product__name__contains=request.GET.get('search'))
        temp_list = list(reversed(temp_list))
        product_list = [[0 for x in range(3)] for y in range(len(temp_list))]
        for i in range(0, len(temp_list)):
            product_list[i][0] = i + 1
            product_list[i][1] = temp_list[i]
            product_list[i][2] = persian.from_gregorian(
                temp_list[i].date.year, temp_list[i].date.month,
                temp_list[i].date.day)

        page = request.GET.get('page')

        paginator = Paginator(product_list, 2)
        try:
            list_with_dates = paginator.get_page(page)
        except PageNotAnInteger:
            list_with_dates = paginator.get_page(1)
        except EmptyPage:
            list_with_dates = paginator.get_page(paginator.num_pages)

        return render(request, 'reporting/listproducts.html',
                      {'products': product_list})
Example #2
0
def getPersianCalendarDateName( n ):
    if not isinstance( n, RPNDateTime ):
        raise ValueError( 'time type required for this operator' )

    date = persian.from_gregorian( n.year, n.month, n.day )

    return persianDays[ n.weekday( ) ] + ', ' + persianMonths[ date[ 1 ] - 1 ] + \
           ' ' + str( date[ 2 ] ) + ', ' + str( date[ 0 ] )
Example #3
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     comment = context[self.context_object_name]
     date = persian.from_gregorian(comment.date.year, comment.date.month,
                                   comment.date.day)
     comment.date_str = (str(date[0]) + '/' + str(date[1]) + '/' +
                         str(date[2])).translate(num_tab)
     return context
Example #4
0
 def test_returntype(self):
     self.assertSequenceType(coptic.from_gregorian(2020, 6, 4), int)
     self.assertSequenceType(hebrew.from_gregorian(2020, 6, 4), int)
     self.assertSequenceType(islamic.from_gregorian(2020, 6, 4), int)
     self.assertSequenceType(indian_civil.from_gregorian(2020, 6, 4), int)
     self.assertSequenceType(iso.from_gregorian(2020, 6, 4), int)
     self.assertSequenceType(julian.from_gregorian(2020, 6, 4), int)
     self.assertSequenceType(persian.from_gregorian(2020, 6, 4), int)
    def get_queryset(self):
        params = self.request.GET
        products = ProductSubmit.objects.all()
        kwargs = {}

        product = params.get('product', '')
        if product:
            kwargs['product__name'] = product

        submitter = params.get('submitter', '')
        if submitter:
            kwargs['submitter__first_name__contains'] = submitter
            kwargs['submitter__last_name__contains'] = submitter

        province = params.get('province', '')
        if province:
            kwargs['province'] = province

        price_min = params.get('price_min', '')
        if price_min and re.fullmatch(num_reg, price_min):
            kwargs['price__gte'] = int(price_min.translate(num_tab[1]))

        price_max = params.get('price_max', '')
        if price_max and re.fullmatch(num_reg, price_max):
            kwargs['price__lte'] = int(price_max.translate(num_tab[1]))

        start_date = params.get('start_date', '')
        if start_date and re.fullmatch(date_reg, start_date):
            year, month, day = start_date.translate(num_tab[1]).split('/')
            kwargs['date__gte'] = date(
                *persian.to_gregorian(int(year), int(month), int(day)))

        end_date = params.get('end_date', '')
        if end_date and re.fullmatch(date_reg, end_date):
            year, month, day = start_date.translate(num_tab[1]).split('/')
            kwargs['date__lte'] = date(
                *persian.to_gregorian(int(year), int(month), int(day)))

        quantity_min = params.get('quantity_min', '')
        if quantity_min and re.fullmatch(num_reg, quantity_min):
            kwargs['quantity__gte'] = int(quantity_min)

        quantity_max = params.get('quantity_max', '')
        if quantity_max and re.fullmatch(num_reg, quantity_max):
            kwargs['quantity__lte'] = int(quantity_max)

        if kwargs:
            products = products.filter(**kwargs)

        for product in products:
            date = persian.from_gregorian(product.date.year,
                                          product.date.month, product.date.day)
            product.date_str = (str(date[0]) + '/' + str(date[1]) + '/' +
                                str(date[2])).translate(num_tab[0])
            product.quantity_str = str(product.quantity).translate(num_tab[0])
            product.price_str = str(product.price).translate(num_tab[0])

        return products
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        product = context['product']
        date = persian.from_gregorian(product.date.year, product.date.month,
                                      product.date.day)
        product.date_str = (str(date[0]) + '/' + str(date[1]) + '/' +
                            str(date[2])).translate(num_tab)
        product.quantity_str = str(product.quantity).translate(num_tab)
        product.price_str = str(product.price).translate(num_tab)

        return context
def listpurchases(request):

    temp_list = Order.objects.filter(buyer=request.user.username)
    if request.GET.get('search'):
        temp_list = temp_list.filter(
            product__product__name__contains=request.GET.get('search'))
    temp_list = list(reversed(temp_list))
    purchase_list = [[0 for x in range(3)] for y in range(len(temp_list))]
    for i in range(0, len(temp_list)):
        purchase_list[i][0] = i + 1
        purchase_list[i][1] = temp_list[i]
        tarikh = persian.from_gregorian(temp_list[i].date.year,
                                        temp_list[i].date.month,
                                        temp_list[i].date.day)
        purchase_list[i][2] = tarikh

    page = request.GET.get('page')

    paginator = Paginator(purchase_list, 2)
    try:
        purchases = paginator.get_page(page)
    except PageNotAnInteger:
        purchases = paginator.get_page(1)
    except EmptyPage:
        purchases = paginator.get_page(paginator.num_pages)

    if request.method == 'POST':
        print(dict(request.POST))
        keys = [key for key in request.POST.keys()]
        order_id = int(keys[1])

        sel_order = Order.objects.get(pk=order_id)
        sel_order.buyer_receipt = True
        sel_order.date_received = datetime.date.today()
        sel_order.save()
        sel_order.driver.reserved = False
        sel_order.driver.save()
        # request.session.pop('driver_id', None)

    return render(request, 'reporting/listpurchases.html',
                  {'purchases': purchases})
Example #8
0
def getPersianCalendarDateNameOperator( n ):
    date = persian.from_gregorian( n.year, n.month, n.day )

    return persianDays[ n.weekday( ) ] + ', ' + persianMonths[ date[ 1 ] - 1 ] + \
           ' ' + str( date[ 2 ] ) + ', ' + str( date[ 0 ] )
Example #9
0
def getPersianCalendarDateOperator( n ):
    return list( persian.from_gregorian( n.year, n.month, n.day ) )
Example #10
0
def getPersianCalendarDate( n ):
    if not isinstance( n, RPNDateTime ):
        raise ValueError( 'time type required for this operator' )

    return list( persian.from_gregorian( n.year, n.month, n.day ) )
def submit_details(request, prodsub_id):
    subprod = get_object_or_404(ProductSubmit, pk=prodsub_id)
    prod_tarikh = subprod.date
    tarikh = persian.from_gregorian(prod_tarikh.year, prod_tarikh.month, prod_tarikh.day)
    return render(request, 'tradeproduct/submittedProduct_details.html', {'submittedProduct': (subprod, tarikh), 'activated': subprod.active})
Example #12
0
def ecliptlong(year, month, day, do_print=False):
   # See https://en.wikipedia.org/wiki/Position_of_the_Sun#Ecliptic_coordinates
   # Days since Jan 1, 2000:
    n = sum(list(gcal2jd(year,month,day)) + [0.5]) - 2451545.0
    L = 280.460 + 0.9856474 * n
    while L > 360.:
        L -= 360.
    while L < 0.:
        L += 360.

    L_rad = (L / 180.) * pi
    g = 357.528 + 0.9856003 * n
    while g > 360.:
        g -= 360.
    while g < 0.:
        g += 360.
    g_rad = (g / 180.) * pi

    lam = L + 1.915 * sin(g_rad) + 0.020 * sin(2*g_rad)

    while lam > 360.:
        lam -= 360.

    if (do_print):
        seasons = { 0:'SPRING',
                    1:'SUMMER',
                    2:'AUTUMN',
                    3:'WINTER' }

        astrosign = lam / 30.
        octant = lam / 45.
        season = seasons[int(octant//2) % 4]
        xquarter = seasons[((octant+1)%8)//2]
        print("For day = {:04}/{:02}/{:02}:".format(year, month,day))
        print("ecliptic longitude =", lam)
        print("astrological sign position =", astrosign)
        print("ecliptic octant =", octant)
        print("astronomical season =", season)
        print("cross-quarter season =", xquarter)
        try:
            from convertdate import persian
            pyear, pmonth, pday = persian.from_gregorian(year, month, day)
            print("Persian date = {} {}, {}".format(pday,
                                                    {1:'aries',
                                                     2:'taurus',
                                                     3:'gemini',
                                                     4:'cancer',
                                                     5:'leo',
                                                     6:'virgo',
                                                     7:'libra',
                                                     8:'scorpio',
                                                     9:'sagittarius',
                                                     10:'capricorn',
                                                     11:'aquarius',
                                                     12:'pisces'}[pmonth],
                                                    pyear))
        except:
            pass
        try:
            import ephem
            sun = ephem.Sun()
            ymdstr = "{:04}/{:02}/{:02}".format(year, month, day)
            sun.compute(ymdstr, ymdstr)
            eph_lam = float(ephem.Ecliptic(sun).lon) / pi * 180.
            eph_sign = eph_lam / 30.
            print("ephem ecliptic longitude =", eph_lam)
            print("ephem astrological sign position =", eph_sign)
            print("ephem previous solstice =",
                  ephem.previous_solstice(ymdstr))
            print("ephem previous equinox =",
                  ephem.previous_equinox(ymdstr))
            print("ephem next solstice =",
                  ephem.next_solstice(ymdstr))
            print("ephem next equinox =",
                  ephem.next_equinox(ymdstr))
        except:
            pass

    return lam