コード例 #1
0
ファイル: views.py プロジェクト: JessAtBlocBoxCo/blocbox
def aftership(request):
    enduser = request.user
    if enduser.is_authenticated():
        watch_packages(specificuser_id=enduser.id)
        transactions_all = Transaction.objects.filter(enduser=enduser) #custom is the field for user email
        transactions_all_paid = transactions_all.filter(payment_processed=True)
        shipments_all_paid = transactions_all_paid.filter(favortype="package")
        shipments_all_paid_notarchived = shipments_all_paid.exclude(trans_archived=True)
        otherfavors_all_paid = transactions_all_paid.exclude(favortype="package")
        #Merge the shipments table dta with the aftership API data in lists called 'shipmetns_with_tracking'
   	    #Noet that with_trackign means it has tracking information appended - does not mean it is on aftership or has a trackin gnumber, that could be empty      
        for shipment in shipments_all_paid_notarchived:  
            tracking_no = str(shipment.tracking) #the str function removes the preceding u'
            shipment_tuple = {} 
            shipment_tuple['trans']=shipment #get all of the transaction variables
            shipment_tuple['aftership']={}  
            if shipment.on_aftership: 
                #populate the aftership_tracking sub-tuble                 
                courier_allfields = api.couriers.detect.post(tracking=dict(tracking_number=tracking_no))
                courier_list = courier_allfields.get(u'couriers')
                courier_list_first = courier_list[0]
                slug_to_detect_u = courier_list_first.get(u'slug')
                slug_to_detect = str(slug_to_detect_u)
                datadict = api.trackings.get(slug_to_detect, tracking_no)
                shipment_tuple['aftership'] = datadict.get(u'tracking') 
                #extract date-only form of expected delivery 
                expected_delivery = shipment_tuple['aftership']['expected_delivery']
                if expected_delivery:
                    shipment_tuple['aftership']['expected_delivery_notime']=expected_delivery.date()
                else:
                    shipment_tuple['aftership']['expected_delivery_notime']=None  
                checkpoints = shipment_tuple['aftership']['checkpoints']
                if checkpoints:
                    shipment_tuple['aftership']['checkpoints'] = checkpoints
                    shipment_tuple['aftership']['last_checkpoint'] = checkpoints[-1] #-nth to last.. so -1 is the last element     
                if shipment.trans_complete ==True:
                    shipments_with_tracking_complete.append(shipment_tuple)
                else:
                    shipments_with_tracking_notcomplete.append(shipment_tuple)
                    tag = shipment_tuple['aftership']['tag']
                    if tag == "Delivered":
                        shipments_with_tracking_notcomplete_delivered.append(shipment_tuple)
                    else:
                        shipments_with_tracking_notcomplete_notdelivered.append(shipment_tuple)
            else: #if not on aftership
                shipment_tuple['aftership']=None
                shipment_tuple['tracking']=None
                if shipment.trans_complete == False:
                    shipments_with_tracking_notcomplete_notrackingno.append(shipment_tuple)
            shipments_with_tracking_allpaid.append(shipment_tuple)
    else: #if not authenticated set these to None
        connections_all = None
        connections_count = None
        hostonly=None
        shipments_all_paid = None
        otherfavors_all_paid = None	  
    return render(request, 'testing/aftership.html', {'enduser': enduser,
        #shipments lists
        'shipments_with_tracking_allpaid': shipments_with_tracking_allpaid, 'shipments_with_tracking_complete': shipments_with_tracking_complete, 
        'shipments_with_tracking_notcomplete': shipments_with_tracking_notcomplete, 
        'shipments_with_tracking_notcomplete_delivered': shipments_with_tracking_notcomplete_delivered, 'shipments_with_tracking_notcomplete_notdelivered': shipments_with_tracking_notcomplete_notdelivered,
        'shipments_with_tracking_notcomplete_notrackingno': shipments_with_tracking_notcomplete_notrackingno,
        #other favors lists
        'otherfavors_all_paid': otherfavors_all_paid, 
    })
コード例 #2
0
def aftership(request):
    enduser = request.user
    if enduser.is_authenticated():
        watch_packages(specificuser_id=enduser.id)
        transactions_all = Transaction.objects.filter(
            enduser=enduser)  #custom is the field for user email
        transactions_all_paid = transactions_all.filter(payment_processed=True)
        shipments_all_paid = transactions_all_paid.filter(favortype="package")
        shipments_all_paid_notarchived = shipments_all_paid.exclude(
            trans_archived=True)
        otherfavors_all_paid = transactions_all_paid.exclude(
            favortype="package")
        #Merge the shipments table dta with the aftership API data in lists called 'shipmetns_with_tracking'
        #Noet that with_trackign means it has tracking information appended - does not mean it is on aftership or has a trackin gnumber, that could be empty
        for shipment in shipments_all_paid_notarchived:
            tracking_no = str(
                shipment.tracking)  #the str function removes the preceding u'
            shipment_tuple = {}
            shipment_tuple[
                'trans'] = shipment  #get all of the transaction variables
            shipment_tuple['aftership'] = {}
            if shipment.on_aftership:
                #populate the aftership_tracking sub-tuble
                courier_allfields = api.couriers.detect.post(tracking=dict(
                    tracking_number=tracking_no))
                courier_list = courier_allfields.get(u'couriers')
                courier_list_first = courier_list[0]
                slug_to_detect_u = courier_list_first.get(u'slug')
                slug_to_detect = str(slug_to_detect_u)
                datadict = api.trackings.get(slug_to_detect, tracking_no)
                shipment_tuple['aftership'] = datadict.get(u'tracking')
                #extract date-only form of expected delivery
                expected_delivery = shipment_tuple['aftership'][
                    'expected_delivery']
                if expected_delivery:
                    shipment_tuple['aftership'][
                        'expected_delivery_notime'] = expected_delivery.date()
                else:
                    shipment_tuple['aftership'][
                        'expected_delivery_notime'] = None
                checkpoints = shipment_tuple['aftership']['checkpoints']
                if checkpoints:
                    shipment_tuple['aftership']['checkpoints'] = checkpoints
                    shipment_tuple['aftership'][
                        'last_checkpoint'] = checkpoints[
                            -1]  #-nth to last.. so -1 is the last element
                if shipment.trans_complete == True:
                    shipments_with_tracking_complete.append(shipment_tuple)
                else:
                    shipments_with_tracking_notcomplete.append(shipment_tuple)
                    tag = shipment_tuple['aftership']['tag']
                    if tag == "Delivered":
                        shipments_with_tracking_notcomplete_delivered.append(
                            shipment_tuple)
                    else:
                        shipments_with_tracking_notcomplete_notdelivered.append(
                            shipment_tuple)
            else:  #if not on aftership
                shipment_tuple['aftership'] = None
                shipment_tuple['tracking'] = None
                if shipment.trans_complete == False:
                    shipments_with_tracking_notcomplete_notrackingno.append(
                        shipment_tuple)
            shipments_with_tracking_allpaid.append(shipment_tuple)
    else:  #if not authenticated set these to None
        connections_all = None
        connections_count = None
        hostonly = None
        shipments_all_paid = None
        otherfavors_all_paid = None
    return render(
        request,
        'testing/aftership.html',
        {
            'enduser': enduser,
            #shipments lists
            'shipments_with_tracking_allpaid': shipments_with_tracking_allpaid,
            'shipments_with_tracking_complete':
            shipments_with_tracking_complete,
            'shipments_with_tracking_notcomplete':
            shipments_with_tracking_notcomplete,
            'shipments_with_tracking_notcomplete_delivered':
            shipments_with_tracking_notcomplete_delivered,
            'shipments_with_tracking_notcomplete_notdelivered':
            shipments_with_tracking_notcomplete_notdelivered,
            'shipments_with_tracking_notcomplete_notrackingno':
            shipments_with_tracking_notcomplete_notrackingno,
            #other favors lists
            'otherfavors_all_paid': otherfavors_all_paid,
        })
コード例 #3
0
 def do(self):
     watch_packages()
     #pass    # do your thing here
     message = ''
コード例 #4
0
ファイル: cron.py プロジェクト: JessAtBlocBoxCo/blocbox
 def do(self):
 	watch_packages()
     #pass    # do your thing here
     message = ''