def dashboard_host_test(request, host_id=None, trans=None, track_id=None, confirm_id=None, issue_id=None, message_trans_id=None, archive_id=None): thepersonviewingthepage = request.user #set timezone local_timezone = request.session.setdefault('django_timezone', 'UTC') #added local_timezone = pytz.timezone(local_timezone) #added #define empty list and other variables used for the availabiility and conflict functions #may not nbeed these days_withconflicts_thismonth = [] #added days_withconflicts_nextmonth = [] #added calendar_submit_button_text = "Submit Updated Availability" #added cal_form_submitted = False #added if thepersonviewingthepage.host == True: transactions_all = Transaction.objects.filter(host=thepersonviewingthepage) #custom is the field for user email transactions_all_paid = transactions_all.filter(payment_processed=True) transactions_count = Transaction.objects.filter(host=thepersonviewingthepage).count() #count all of the transactions shipments_all_paid = transactions_all_paid.filter(favortype="package") shipments_all_paid_notarchived = shipments_all_paid.exclude(trans_archived=True) shipments_all_paid_notarchived_notcomplete = shipments_all_paid_notarchived.exclude(trans_complete=True) otherfavors_all_paid = transactions_all_paid.exclude(favortype="package") otherfavors_all_paid_notarchived = otherfavors_all_paid.exclude(trans_archived=True) #Create lists restricted to shipmetns that are on aftership shipments_complete_fordash = shipments_all_paid_notarchived.filter(trans_complete=True) #Shipments in transit shipments_in_transit = shipments_all_paid_notarchived_notcomplete.exclude(last_tracking_status="Delivered",) shipments_in_transit_no_fails = shipments_in_transit.exclude(last_tracking_status="AttemptFail") shipment_fail = shipments_in_transit.filter(last_tracking_status="AttemptFail") shipment_fail_count = shipment_fail.count() shipments_in_transit_count = shipments_in_transit.count() #Shipments awaiting pickup shipments_waiting_pickup = shipments_all_paid_notarchived_notcomplete.filter(last_tracking_status="Delivered") shipments_waiting_pickup_count = shipments_waiting_pickup.count() connections_all = Connection.objects.filter(host_user=thepersonviewingthepage) #JB - displays hosts connected to connections_count = Connection.objects.filter(host_user=thepersonviewingthepage).count() #count them,removing status=0 after host_user=host #Get all of the host conflicts - JMY ADDING ON 9/7/2016 conflicts = HostConflicts_DateVersion.objects.filter(host=thepersonviewingthepage) for conflict in conflicts: if conflict.month == thismonth_num: days_withconflicts_thismonth.append(conflict.day) if conflict.month == nextmonth_num: days_withconflicts_nextmonth.append(conflict.day) else: #if not authenticated set these to None transactions_all = None transactions_all_paid = None shipments_all_paid = None shipments_all_paid_notarchived = None otherfavors_all_paid = None otherfavors_all_paid_notarchived = None shipments_complete_fordash = None shipments_in_transit = None shipments_in_transit_count = None shipments_in_transit_no_fails = None shipment_fail = None shipment_fail_count = None shipments_waiting_pickup = None connections_all = None connections_count = None transactions_count = None shipments_waiting_pickup_count = None conflicts = None if confirm_id: #if the open the package_received modal #JB - confirming what? confirm_id_int = confirm_id.strip() confirm_id_int = int(confirm_id_int) host_received_modal(request, confirm_id) else: confirm_id_int = None #then do the stuff if the form is posted if request.method == 'POST': cal_form = CalendarCheckBoxes(data=request.POST) if cal_form.is_valid(): for daynumber in range(1,32): #starts at zero otherwise so this will stop at 31 conflict_new = HostConflicts_DateVersion() daycheckedmonth1 = cal_form.cleaned_data['month1day'+str(daynumber)] if daycheckedmonth1: #add the conflicts monty, day and year - conflict in this month conflict_new.host = thepersonviewingthepage conflict_new.month = thismonth_num conflict_new.day = daynumber conflict_new.year = thisyear conflict_new.date = str(thisyear) + "-" + str(thismonth_num) + "-" + str(daynumber) conflict_new.save() for daynumber in range(1,32): conflict_new = HostConflicts_DateVersion() daycheckedmonth2 = cal_form.cleaned_data['month2day'+str(daynumber)] if daycheckedmonth2: #add the conflicts monty, day and year - conflict in this month conflict_new.host = thepersonviewingthepage conflict_new.month = nextmonth_num conflict_new.day = daynumber conflict_new.year = thisyear conflict_new.date = str(nextmonth_calendar_year) + "-" + str(thismonth_num) + "-" + str(daynumber) conflict_new.save() cal_form_submitted = True #test whether line 401 has error else: print cal_form.errors else: cal_form = CalendarCheckBoxes() return render(request, 'testing/dashboard-host.html', { 'enduser':thepersonviewingthepage, #transactions all 'transactions_all': transactions_all, 'transactions_all_paid': transactions_all_paid, 'shipments_complete_fordash': shipments_complete_fordash, 'shipments_in_transit': shipments_in_transit, 'shipments_in_transit_count': shipments_in_transit_count, 'shipments_in_transit_no_fails': shipments_in_transit_no_fails, 'shipment_fail': shipment_fail, 'shipments_waiting_pickup': shipments_waiting_pickup, 'shipments_waiting_pickup_count': shipments_waiting_pickup_count, #otherfavors all 'otherfavors_all_paid': otherfavors_all_paid, 'otherfavors_all_paid_notarchived': otherfavors_all_paid_notarchived, 'connections_all': connections_all, 'connections_count': connections_count, 'transactions_count': transactions_count, 'shipment_fail_count': shipment_fail_count, 'confirm_id': confirm_id, 'confirm_id_int': confirm_id_int, #JMY ADDED THE FOLLOWING VARIABLES TO PASS TO THE TEMPLATE ON 9/6/2015 TO PUT THE HOST AVAILBILITY CALENDAR INTO THE HOST DASHBOARD 'cal_form': cal_form, #Calendar and date variables 'local_timezone': local_timezone, 'date_today': date_today, 'datetime_now': datetime_now, 'thisyear': thisyear, 'nextyear': nextyear, 'thisyeaer_isleap': thisyear_isleap, 'nextyear_isleap': nextyear_isleap, 'thismonth': thismonth, 'nextmonth': nextmonth, 'thismonth_calendar': thismonth_calendar, 'nextmonth_calendar': nextmonth_calendar, 'monthrange_thismonth': monthrange_thismonth, 'monthrange_nextmonth': monthrange_nextmonth, 'days_in_thismonth': days_in_thismonth, 'days_in_nextmonth': days_in_nextmonth, 'today_dayofmonth_num': today_dayofmonth_num, 'nextmonth_calendar_year': nextmonth_calendar_year, #Unavailable days 'conflicts': conflicts, 'days_withconflicts_thismonth': days_withconflicts_thismonth, 'days_withconflicts_nextmonth': days_withconflicts_nextmonth, 'calendar_submit_button_text': calendar_submit_button_text, })
def startashipment(request, host_id=None, transaction_form_submitted=False, invoice=None, cal_form_submitted=False, packagedays_count = None, ): random3digits = random.randint(100,999) #set timezone local_timezone = request.session.setdefault('django_timezone', 'UTC') local_timezone = pytz.timezone(local_timezone) enduser = request.user calendar_submit_button_text = "Select Dates and Proceed to Payment" if host_id: host = get_object_or_404(UserInfo, pk=host_id) else: host = None #Determine if payment is needed or balance will suffice balance = enduser.account_balance_packages if balance > 0: payment_needed = False amount_due = 0.00 remaining_balance = balance - 1 else: if enduser.betauser_free: payment_needed = False else: payment_needed = True amount_due = None #this is processed on the payment page if they aren't applying account balance remaining_balance = None connections_all = Connection.objects.filter(end_user=enduser) #Empty variables for availability/ conflict stuff days_package_may_come_thismonth = [] days_package_may_come_nextmonth = [] month1days_count = None month2days_count = None conflicts_date_from = [] conflicts_startmonths = [] conflicts_startthismonth = [] conflicts_startnextmonth = [] conflicts_startandend_thismonth = [] conflicts_startandend_nextmonth = [] conflicts_startthismonth_endnextmonth = [] conflicts_startthismonth_endlater = [] conflicts_startnextmonth_endlater = [] days_withconflicts_thismonth = [] days_withconflicts_nextmonth = [] days_withconflicts_later = [] #if host/no host - get caklendar_homebrew created fields if host: transcount = Transaction.objects.filter(host=host).count() + 1 #counts transactions that this receiver_email has received (could change to host email) #invoice = "H" + str(host.id) + "U" + str(enduser.id) + "N" +str(transcount) +"D" + str(date_today.month) + str(date_today.day) + str(time.hour) + "R" + str(random3digits) #h2u14N13D112210R123 = transaciton between host2, user14, host's 13th transaction #JMY updating invoice algorithm - removing date to make it smaller invoice = "H" + str(host.id) + "U" + str(enduser.id) + "N" +str(transcount) + "R" + str(random3digits) #h2u14N13D112210R123 = transaciton between host2, user14, host's 13th transaction conflicts = HostConflicts_DateVersion.objects.filter(host=host) for conflict in conflicts: if conflict.month == thismonth_num: days_withconflicts_thismonth.append(conflict.day) if conflict.month == nextmonth_num: days_withconflicts_nextmonth.append(conflict.day) #i think i do this to remove duplicates days_withconflicts_thismonth = list(set(days_withconflicts_thismonth)) days_withconflicts_nextmonth = list(set(days_withconflicts_nextmonth)) #determine if there is a conflict host_package_conflict = False for day in days_package_may_come_thismonth: if day in days_withconflicts_thismonth: host_package_conflict = True for day in days_package_may_come_nextmonth: if day in days_withconflicts_nextmonth: host_package_conflict = True else: #if no host specified that stuff is empty/none conflicts = None host_package_conflict = False #do payment variables/ transaction form stuff once they've checked the calendar day favortype='package' #transaction_form_submitted = False #packagedays_count = None if cal_form_submitted: cal_form = CalendarCheckBoxes() packagedays = None packagedays_string = None trans_form_package = None trans = Transaction() #request.method = 'GET' if request.method == 'POST': trans_form_package = CreatePackageTransaction(request.POST) if trans_form_package.is_valid(): title = trans_form_package.cleaned_data['title'] payment_option = trans_form_package.cleaned_data['payment_option'] note_to_host = trans_form_package.cleaned_data['note_to_host'] paypal_quantity = 1 if payment_option=="bundle10": price=host.price_package_bundle10 youselected="Bundle of 10 Packages" balance_created = 9 #10 minus the 1 they just bought elif payment_option=="bundle20": price=host.price_package_bundle20 youselected="Bundle of 20 Packages" balance_created = 19 #20 minus the 1 they just bought elif payment_option=="annual": price=host.price_package_annual youselected="Annual" balance_created = 1000 #Notional - this option is not in place currently else: price=host.price_package_per youselected="Per Package" balance_created = None #Next, add the data to the transaction table trans.balance_created_packages = balance_created trans.payment_option = payment_option trans.title = title trans.favortype = favortype trans.note_to_host = note_to_host trans.price = price trans.youselected = youselected trans.paypal_quantity = paypal_quantity trans.host = host trans.enduser = enduser trans.invoice = invoice #Account balance/ create amount_due if enduser.account_balance_packages: if enduser.account_balance_packages > 0: trans.amount_due = 0 trans.payment_needed = False else: trans.amount_due = price trans.payment_needed = True else: trans.amount_due = price trans.payment_needed = True arrivalwindow_days_count = trans_form_package.cleaned_data['packagedays_count'] trans.arrivalwindow_days_count = arrivalwindow_days_count day1 = trans_form_package.cleaned_data['arrivalwindow_day1'] day1string = trans_form_package.cleaned_data['arrivalwindow_day1string'] if day1: trans.arrivalwindow_day1 = day1 day2 = trans_form_package.cleaned_data['arrivalwindow_day2'] day2string = trans_form_package.cleaned_data['arrivalwindow_day2string'] if day2: trans.arrivalwindow_day2 = day2 day3 = trans_form_package.cleaned_data['arrivalwindow_day3'] day3string = trans_form_package.cleaned_data['arrivalwindow_day3string'] if day3: trans.arrivalwindow_day3 = day3 day4 = trans_form_package.cleaned_data['arrivalwindow_day4'] day4string = trans_form_package.cleaned_data['arrivalwindow_day4string'] if day4: trans.arrivalwindow_day4 = day4 day5 = trans_form_package.cleaned_data['arrivalwindow_day5'] day5string = trans_form_package.cleaned_data['arrivalwindow_day5string'] if day5: trans.arrivalwindow_day5 = day5 day6 = trans_form_package.cleaned_data['arrivalwindow_day6'] day6string = trans_form_package.cleaned_data['arrivalwindow_day6string'] if day6: trans.arrivalwindow_day6 = day6 day7 = trans_form_package.cleaned_data['arrivalwindow_day7'] day7string = trans_form_package.cleaned_data['arrivalwindow_day7string'] if day7: trans.arrivalwindow_day7 = day7 if arrivalwindow_days_count == 1: trans.arrivalwindow_string = str(day1string) trans.arrivalwindow_lastday = day1 if arrivalwindow_days_count == 2: trans.arrivalwindow_string = str(day1string) + " or " + str(day2string) trans.arrivalwindow_lastday = day2 if arrivalwindow_days_count == 3: trans.arrivalwindow_string = str(day1string) + ", " + str(day2string) + ", or " + str(day3string) trans.arrivalwindow_lastday = day3 if arrivalwindow_days_count == 4: trans.arrivalwindow_string = str(day1string) + ", " + str(day2string) + ", " + str(day3string) + ", or " + str(day4string) trans.arrivalwindow_lastday = day4 if arrivalwindow_days_count == 5: trans.arrivalwindow_string = str(day1string) + ", " + str(day2string) + ", " + str(day3string) + ", " + str(day4string) + ", or " + str(day5string) trans.arrivalwindow_lastday = day5 if arrivalwindow_days_count == 6: trans.arrivalwindow_string = str(day1string) + ", " + str(day2string) + ", " + str(day3string) + ", " + str(day4string) + ", " + str(day5string) + ", or " + str(day6string) trans.arrivalwindow_lastday = day6 if arrivalwindow_days_count == 7: trans.arrivalwindow_lastday = day7 trans.arrivalwindow_string = str(day1string) + ", " + str(day2string) + ", " + str(day3string) + ", " + str(day4string) + ", " + str(day5string) + ", " + str(day6string) + ", or " + str(day7string) trans.save() transaction_form_submitted = True else: print trans_form_package.errors transaction_form_submitted = False errors_on_trans_form = 'There are errors on the transaction form' else: trans_form_package = CreatePackageTransaction() transaction_form_submitted = False errors_on_trans_form = 'Method is not POST' #if cal_form_submitted is false else: transaction_form_submitted = False errors_on_trans_form = 'Cal_form was not submitted' trans_form_package = None transaction_form_submitted = False packagedays = [] packagedays_string = [] #do the cal_form submission stuff if request.method == 'POST': cal_form = CalendarCheckBoxes(data=request.POST) if cal_form.is_valid(): for daynumber in range(1,32): #starts at zero otherwise so this will stop at 31 daycheckedmonth1 = cal_form.cleaned_data['month1day'+str(daynumber)] if daycheckedmonth1: #checked day needs to be in YYYY-MM-DD format checked_day = str(thisyear) + "-" + str(thismonth_num) + "-" + str(daynumber) checked_day_string = str(thismonth) + " " + str(daynumber) packagedays.append(checked_day) packagedays_string.append(checked_day_string) days_package_may_come_thismonth.append(daynumber) for daynumber in range(1,32): daycheckedmonth2 = cal_form.cleaned_data['month2day'+str(daynumber)] if daycheckedmonth2: checked_day = str(nextmonth_calendar_year) + "-" + str(nextmonth_num) + "-" + str(daynumber) checked_day_string = str(nextmonth) + " " + str(daynumber) packagedays.append(checked_day) packagedays_string.append(checked_day_string) days_package_may_come_nextmonth.append(daynumber) month1days_count = len(days_package_may_come_thismonth) month2days_count = len(days_package_may_come_nextmonth) cal_form_submitted = True else: print cal_form.errors else: cal_form = CalendarCheckBoxes() packagedays_count = len(packagedays) #if the transaction form has been submitted redirect to new page if transaction_form_submitted == True: cal_form = None if payment_needed: return HttpResponseRedirect("/transactions/payment/host" + str(host.id) + "/invoice" + str(invoice) + "/favortype" + str(favortype) + "/") else: return HttpResponseRedirect("/transactions/shippackage/host" + str(host.id) + "/account_balance/invoice" + str(invoice) + "/") #if the transaction form has not been submitted else: return render(request, 'blocbox/startashipment.html', { 'enduser':enduser, 'host': host, 'connections_all': connections_all, #'cal_relations_host_count': cal_relations_host_count, 'cal_relations_host': cal_relations_host, 'cal_list_host': cal_list_host, 'here': quote(request.get_full_path()), #Python calendar variables (independent of conflict app) 'local_timezone': local_timezone, 'date_today': date_today, 'datetime_now': datetime_now, 'thisyear': thisyear, 'nextyear': nextyear, 'thisyeaer_isleap': thisyear_isleap, 'nextyear_isleap': nextyear_isleap, 'thismonth': thismonth, 'nextmonth': nextmonth, 'thismonth_calendar': thismonth_calendar, 'nextmonth_calendar': nextmonth_calendar, 'monthrange_thismonth': monthrange_thismonth, 'monthrange_nextmonth': monthrange_nextmonth, 'days_in_thismonth': days_in_thismonth, 'days_in_nextmonth': days_in_nextmonth, 'today_dayofmonth_num': today_dayofmonth_num, 'nextmonth_calendar_year': nextmonth_calendar_year, #conflict app variables (if host) 'conflicts': conflicts, 'conflicts_startthismonth': conflicts_startthismonth, 'conflicts_startnextmonth': conflicts_startnextmonth, 'conflicts_startandend_thismonth': conflicts_startandend_thismonth, 'conflicts_startandend_nextmonth': conflicts_startandend_nextmonth, 'days_withconflicts_thismonth': days_withconflicts_thismonth, 'days_withconflicts_nextmonth': days_withconflicts_nextmonth, #days package may come 'days_package_may_come_thismonth': days_package_may_come_thismonth, 'days_package_may_come_nextmonth': days_package_may_come_nextmonth, 'host_package_conflict': host_package_conflict, #Calendar check boxes form 'cal_form': cal_form, 'packagedays': packagedays, 'packagedays_string': packagedays_string, 'packagedays_count': packagedays_count, 'cal_form_submitted': cal_form_submitted, 'calendar_submit_button_text': calendar_submit_button_text, #payment stuff once the calendar checkboxes are checked 'trans_form_package': trans_form_package, 'invoice': invoice, 'favortype': favortype, 'errors_on_trans_form': errors_on_trans_form, 'transaction_form_submitted': transaction_form_submitted, 'random3digits': random3digits, 'payment_needed': payment_needed, 'amount_due': amount_due, 'remaining_balance': remaining_balance, 'request': request, })
def dashboard_host_test(request, host_id=None, trans=None, track_id=None, confirm_id=None, issue_id=None, message_trans_id=None, archive_id=None): thepersonviewingthepage = request.user #set timezone local_timezone = request.session.setdefault('django_timezone', 'UTC') #added local_timezone = pytz.timezone(local_timezone) #added #define empty list and other variables used for the availabiility and conflict functions #may not nbeed these days_withconflicts_thismonth = [] #added days_withconflicts_nextmonth = [] #added calendar_submit_button_text = "Submit Updated Availability" #added cal_form_submitted = False #added if thepersonviewingthepage.host == True: transactions_all = Transaction.objects.filter( host=thepersonviewingthepage) #custom is the field for user email transactions_all_paid = transactions_all.filter(payment_processed=True) transactions_count = Transaction.objects.filter( host=thepersonviewingthepage).count( ) #count all of the transactions shipments_all_paid = transactions_all_paid.filter(favortype="package") shipments_all_paid_notarchived = shipments_all_paid.exclude( trans_archived=True) shipments_all_paid_notarchived_notcomplete = shipments_all_paid_notarchived.exclude( trans_complete=True) otherfavors_all_paid = transactions_all_paid.exclude( favortype="package") otherfavors_all_paid_notarchived = otherfavors_all_paid.exclude( trans_archived=True) #Create lists restricted to shipmetns that are on aftership shipments_complete_fordash = shipments_all_paid_notarchived.filter( trans_complete=True) #Shipments in transit shipments_in_transit = shipments_all_paid_notarchived_notcomplete.exclude( last_tracking_status="Delivered", ) shipments_in_transit_no_fails = shipments_in_transit.exclude( last_tracking_status="AttemptFail") shipment_fail = shipments_in_transit.filter( last_tracking_status="AttemptFail") shipment_fail_count = shipment_fail.count() shipments_in_transit_count = shipments_in_transit.count() #Shipments awaiting pickup shipments_waiting_pickup = shipments_all_paid_notarchived_notcomplete.filter( last_tracking_status="Delivered") shipments_waiting_pickup_count = shipments_waiting_pickup.count() connections_all = Connection.objects.filter( host_user=thepersonviewingthepage ) #JB - displays hosts connected to connections_count = Connection.objects.filter( host_user=thepersonviewingthepage).count( ) #count them,removing status=0 after host_user=host #Get all of the host conflicts - JMY ADDING ON 9/7/2016 conflicts = HostConflicts_DateVersion.objects.filter( host=thepersonviewingthepage) for conflict in conflicts: if conflict.month == thismonth_num: days_withconflicts_thismonth.append(conflict.day) if conflict.month == nextmonth_num: days_withconflicts_nextmonth.append(conflict.day) else: #if not authenticated set these to None transactions_all = None transactions_all_paid = None shipments_all_paid = None shipments_all_paid_notarchived = None otherfavors_all_paid = None otherfavors_all_paid_notarchived = None shipments_complete_fordash = None shipments_in_transit = None shipments_in_transit_count = None shipments_in_transit_no_fails = None shipment_fail = None shipment_fail_count = None shipments_waiting_pickup = None connections_all = None connections_count = None transactions_count = None shipments_waiting_pickup_count = None conflicts = None if confirm_id: #if the open the package_received modal #JB - confirming what? confirm_id_int = confirm_id.strip() confirm_id_int = int(confirm_id_int) host_received_modal(request, confirm_id) else: confirm_id_int = None #then do the stuff if the form is posted if request.method == 'POST': cal_form = CalendarCheckBoxes(data=request.POST) if cal_form.is_valid(): for daynumber in range( 1, 32): #starts at zero otherwise so this will stop at 31 conflict_new = HostConflicts_DateVersion() daycheckedmonth1 = cal_form.cleaned_data['month1day' + str(daynumber)] if daycheckedmonth1: #add the conflicts monty, day and year - conflict in this month conflict_new.host = thepersonviewingthepage conflict_new.month = thismonth_num conflict_new.day = daynumber conflict_new.year = thisyear conflict_new.date = str(thisyear) + "-" + str( thismonth_num) + "-" + str(daynumber) conflict_new.save() for daynumber in range(1, 32): conflict_new = HostConflicts_DateVersion() daycheckedmonth2 = cal_form.cleaned_data['month2day' + str(daynumber)] if daycheckedmonth2: #add the conflicts monty, day and year - conflict in this month conflict_new.host = thepersonviewingthepage conflict_new.month = nextmonth_num conflict_new.day = daynumber conflict_new.year = thisyear conflict_new.date = str( nextmonth_calendar_year) + "-" + str( thismonth_num) + "-" + str(daynumber) conflict_new.save() cal_form_submitted = True #test whether line 401 has error else: print cal_form.errors else: cal_form = CalendarCheckBoxes() return render( request, 'testing/dashboard-host.html', { 'enduser': thepersonviewingthepage, #transactions all 'transactions_all': transactions_all, 'transactions_all_paid': transactions_all_paid, 'shipments_complete_fordash': shipments_complete_fordash, 'shipments_in_transit': shipments_in_transit, 'shipments_in_transit_count': shipments_in_transit_count, 'shipments_in_transit_no_fails': shipments_in_transit_no_fails, 'shipment_fail': shipment_fail, 'shipments_waiting_pickup': shipments_waiting_pickup, 'shipments_waiting_pickup_count': shipments_waiting_pickup_count, #otherfavors all 'otherfavors_all_paid': otherfavors_all_paid, 'otherfavors_all_paid_notarchived': otherfavors_all_paid_notarchived, 'connections_all': connections_all, 'connections_count': connections_count, 'transactions_count': transactions_count, 'shipment_fail_count': shipment_fail_count, 'confirm_id': confirm_id, 'confirm_id_int': confirm_id_int, #JMY ADDED THE FOLLOWING VARIABLES TO PASS TO THE TEMPLATE ON 9/6/2015 TO PUT THE HOST AVAILBILITY CALENDAR INTO THE HOST DASHBOARD 'cal_form': cal_form, #Calendar and date variables 'local_timezone': local_timezone, 'date_today': date_today, 'datetime_now': datetime_now, 'thisyear': thisyear, 'nextyear': nextyear, 'thisyeaer_isleap': thisyear_isleap, 'nextyear_isleap': nextyear_isleap, 'thismonth': thismonth, 'nextmonth': nextmonth, 'thismonth_calendar': thismonth_calendar, 'nextmonth_calendar': nextmonth_calendar, 'monthrange_thismonth': monthrange_thismonth, 'monthrange_nextmonth': monthrange_nextmonth, 'days_in_thismonth': days_in_thismonth, 'days_in_nextmonth': days_in_nextmonth, 'today_dayofmonth_num': today_dayofmonth_num, 'nextmonth_calendar_year': nextmonth_calendar_year, #Unavailable days 'conflicts': conflicts, 'days_withconflicts_thismonth': days_withconflicts_thismonth, 'days_withconflicts_nextmonth': days_withconflicts_nextmonth, 'calendar_submit_button_text': calendar_submit_button_text, })
def startashipment( request, host_id=None, transaction_form_submitted=False, invoice=None, cal_form_submitted=False, packagedays_count=None, ): random3digits = random.randint(100, 999) #set timezone local_timezone = request.session.setdefault('django_timezone', 'UTC') local_timezone = pytz.timezone(local_timezone) enduser = request.user calendar_submit_button_text = "Select Dates and Proceed to Payment" if host_id: host = get_object_or_404(UserInfo, pk=host_id) else: host = None #Determine if payment is needed or balance will suffice balance = enduser.account_balance_packages if balance > 0: payment_needed = False amount_due = 0.00 remaining_balance = balance - 1 else: if enduser.betauser_free: payment_needed = False else: payment_needed = True amount_due = None #this is processed on the payment page if they aren't applying account balance remaining_balance = None connections_all = Connection.objects.filter(end_user=enduser) #Empty variables for availability/ conflict stuff days_package_may_come_thismonth = [] days_package_may_come_nextmonth = [] month1days_count = None month2days_count = None conflicts_date_from = [] conflicts_startmonths = [] conflicts_startthismonth = [] conflicts_startnextmonth = [] conflicts_startandend_thismonth = [] conflicts_startandend_nextmonth = [] conflicts_startthismonth_endnextmonth = [] conflicts_startthismonth_endlater = [] conflicts_startnextmonth_endlater = [] days_withconflicts_thismonth = [] days_withconflicts_nextmonth = [] days_withconflicts_later = [] #if host/no host - get caklendar_homebrew created fields if host: transcount = Transaction.objects.filter(host=host).count( ) + 1 #counts transactions that this receiver_email has received (could change to host email) #invoice = "H" + str(host.id) + "U" + str(enduser.id) + "N" +str(transcount) +"D" + str(date_today.month) + str(date_today.day) + str(time.hour) + "R" + str(random3digits) #h2u14N13D112210R123 = transaciton between host2, user14, host's 13th transaction #JMY updating invoice algorithm - removing date to make it smaller invoice = "H" + str( host.id ) + "U" + str(enduser.id) + "N" + str(transcount) + "R" + str( random3digits ) #h2u14N13D112210R123 = transaciton between host2, user14, host's 13th transaction conflicts = HostConflicts_DateVersion.objects.filter(host=host) for conflict in conflicts: if conflict.month == thismonth_num: days_withconflicts_thismonth.append(conflict.day) if conflict.month == nextmonth_num: days_withconflicts_nextmonth.append(conflict.day) #i think i do this to remove duplicates days_withconflicts_thismonth = list(set(days_withconflicts_thismonth)) days_withconflicts_nextmonth = list(set(days_withconflicts_nextmonth)) #determine if there is a conflict host_package_conflict = False for day in days_package_may_come_thismonth: if day in days_withconflicts_thismonth: host_package_conflict = True for day in days_package_may_come_nextmonth: if day in days_withconflicts_nextmonth: host_package_conflict = True else: #if no host specified that stuff is empty/none conflicts = None host_package_conflict = False #do payment variables/ transaction form stuff once they've checked the calendar day favortype = 'package' #transaction_form_submitted = False #packagedays_count = None if cal_form_submitted: cal_form = CalendarCheckBoxes() packagedays = None packagedays_string = None trans_form_package = None trans = Transaction() #request.method = 'GET' if request.method == 'POST': trans_form_package = CreatePackageTransaction(request.POST) if trans_form_package.is_valid(): title = trans_form_package.cleaned_data['title'] payment_option = trans_form_package.cleaned_data[ 'payment_option'] note_to_host = trans_form_package.cleaned_data['note_to_host'] paypal_quantity = 1 if payment_option == "bundle10": price = host.price_package_bundle10 youselected = "Bundle of 10 Packages" balance_created = 9 #10 minus the 1 they just bought elif payment_option == "bundle20": price = host.price_package_bundle20 youselected = "Bundle of 20 Packages" balance_created = 19 #20 minus the 1 they just bought elif payment_option == "annual": price = host.price_package_annual youselected = "Annual" balance_created = 1000 #Notional - this option is not in place currently else: price = host.price_package_per youselected = "Per Package" balance_created = None #Next, add the data to the transaction table trans.balance_created_packages = balance_created trans.payment_option = payment_option trans.title = title trans.favortype = favortype trans.note_to_host = note_to_host trans.price = price trans.youselected = youselected trans.paypal_quantity = paypal_quantity trans.host = host trans.enduser = enduser trans.invoice = invoice #Account balance/ create amount_due if enduser.account_balance_packages: if enduser.account_balance_packages > 0: trans.amount_due = 0 trans.payment_needed = False else: trans.amount_due = price trans.payment_needed = True else: trans.amount_due = price trans.payment_needed = True arrivalwindow_days_count = trans_form_package.cleaned_data[ 'packagedays_count'] trans.arrivalwindow_days_count = arrivalwindow_days_count day1 = trans_form_package.cleaned_data['arrivalwindow_day1'] day1string = trans_form_package.cleaned_data[ 'arrivalwindow_day1string'] if day1: trans.arrivalwindow_day1 = day1 day2 = trans_form_package.cleaned_data['arrivalwindow_day2'] day2string = trans_form_package.cleaned_data[ 'arrivalwindow_day2string'] if day2: trans.arrivalwindow_day2 = day2 day3 = trans_form_package.cleaned_data['arrivalwindow_day3'] day3string = trans_form_package.cleaned_data[ 'arrivalwindow_day3string'] if day3: trans.arrivalwindow_day3 = day3 day4 = trans_form_package.cleaned_data['arrivalwindow_day4'] day4string = trans_form_package.cleaned_data[ 'arrivalwindow_day4string'] if day4: trans.arrivalwindow_day4 = day4 day5 = trans_form_package.cleaned_data['arrivalwindow_day5'] day5string = trans_form_package.cleaned_data[ 'arrivalwindow_day5string'] if day5: trans.arrivalwindow_day5 = day5 day6 = trans_form_package.cleaned_data['arrivalwindow_day6'] day6string = trans_form_package.cleaned_data[ 'arrivalwindow_day6string'] if day6: trans.arrivalwindow_day6 = day6 day7 = trans_form_package.cleaned_data['arrivalwindow_day7'] day7string = trans_form_package.cleaned_data[ 'arrivalwindow_day7string'] if day7: trans.arrivalwindow_day7 = day7 if arrivalwindow_days_count == 1: trans.arrivalwindow_string = str(day1string) trans.arrivalwindow_lastday = day1 if arrivalwindow_days_count == 2: trans.arrivalwindow_string = str( day1string) + " or " + str(day2string) trans.arrivalwindow_lastday = day2 if arrivalwindow_days_count == 3: trans.arrivalwindow_string = str(day1string) + ", " + str( day2string) + ", or " + str(day3string) trans.arrivalwindow_lastday = day3 if arrivalwindow_days_count == 4: trans.arrivalwindow_string = str(day1string) + ", " + str( day2string) + ", " + str(day3string) + ", or " + str( day4string) trans.arrivalwindow_lastday = day4 if arrivalwindow_days_count == 5: trans.arrivalwindow_string = str(day1string) + ", " + str( day2string) + ", " + str(day3string) + ", " + str( day4string) + ", or " + str(day5string) trans.arrivalwindow_lastday = day5 if arrivalwindow_days_count == 6: trans.arrivalwindow_string = str(day1string) + ", " + str( day2string) + ", " + str(day3string) + ", " + str( day4string) + ", " + str( day5string) + ", or " + str(day6string) trans.arrivalwindow_lastday = day6 if arrivalwindow_days_count == 7: trans.arrivalwindow_lastday = day7 trans.arrivalwindow_string = str(day1string) + ", " + str( day2string) + ", " + str(day3string) + ", " + str( day4string) + ", " + str(day5string) + ", " + str( day6string) + ", or " + str(day7string) trans.save() transaction_form_submitted = True else: print trans_form_package.errors transaction_form_submitted = False errors_on_trans_form = 'There are errors on the transaction form' else: trans_form_package = CreatePackageTransaction() transaction_form_submitted = False errors_on_trans_form = 'Method is not POST' #if cal_form_submitted is false else: transaction_form_submitted = False errors_on_trans_form = 'Cal_form was not submitted' trans_form_package = None transaction_form_submitted = False packagedays = [] packagedays_string = [] #do the cal_form submission stuff if request.method == 'POST': cal_form = CalendarCheckBoxes(data=request.POST) if cal_form.is_valid(): for daynumber in range( 1, 32): #starts at zero otherwise so this will stop at 31 daycheckedmonth1 = cal_form.cleaned_data['month1day' + str(daynumber)] if daycheckedmonth1: #checked day needs to be in YYYY-MM-DD format checked_day = str(thisyear) + "-" + str( thismonth_num) + "-" + str(daynumber) checked_day_string = str(thismonth) + " " + str( daynumber) packagedays.append(checked_day) packagedays_string.append(checked_day_string) days_package_may_come_thismonth.append(daynumber) for daynumber in range(1, 32): daycheckedmonth2 = cal_form.cleaned_data['month2day' + str(daynumber)] if daycheckedmonth2: checked_day = str(nextmonth_calendar_year) + "-" + str( nextmonth_num) + "-" + str(daynumber) checked_day_string = str(nextmonth) + " " + str( daynumber) packagedays.append(checked_day) packagedays_string.append(checked_day_string) days_package_may_come_nextmonth.append(daynumber) month1days_count = len(days_package_may_come_thismonth) month2days_count = len(days_package_may_come_nextmonth) cal_form_submitted = True else: print cal_form.errors else: cal_form = CalendarCheckBoxes() packagedays_count = len(packagedays) #if the transaction form has been submitted redirect to new page if transaction_form_submitted == True: cal_form = None if payment_needed: return HttpResponseRedirect("/transactions/payment/host" + str(host.id) + "/invoice" + str(invoice) + "/favortype" + str(favortype) + "/") else: return HttpResponseRedirect("/transactions/shippackage/host" + str(host.id) + "/account_balance/invoice" + str(invoice) + "/") #if the transaction form has not been submitted else: return render( request, 'blocbox/startashipment.html', { 'enduser': enduser, 'host': host, 'connections_all': connections_all, #'cal_relations_host_count': cal_relations_host_count, 'cal_relations_host': cal_relations_host, 'cal_list_host': cal_list_host, 'here': quote(request.get_full_path()), #Python calendar variables (independent of conflict app) 'local_timezone': local_timezone, 'date_today': date_today, 'datetime_now': datetime_now, 'thisyear': thisyear, 'nextyear': nextyear, 'thisyeaer_isleap': thisyear_isleap, 'nextyear_isleap': nextyear_isleap, 'thismonth': thismonth, 'nextmonth': nextmonth, 'thismonth_calendar': thismonth_calendar, 'nextmonth_calendar': nextmonth_calendar, 'monthrange_thismonth': monthrange_thismonth, 'monthrange_nextmonth': monthrange_nextmonth, 'days_in_thismonth': days_in_thismonth, 'days_in_nextmonth': days_in_nextmonth, 'today_dayofmonth_num': today_dayofmonth_num, 'nextmonth_calendar_year': nextmonth_calendar_year, #conflict app variables (if host) 'conflicts': conflicts, 'conflicts_startthismonth': conflicts_startthismonth, 'conflicts_startnextmonth': conflicts_startnextmonth, 'conflicts_startandend_thismonth': conflicts_startandend_thismonth, 'conflicts_startandend_nextmonth': conflicts_startandend_nextmonth, 'days_withconflicts_thismonth': days_withconflicts_thismonth, 'days_withconflicts_nextmonth': days_withconflicts_nextmonth, #days package may come 'days_package_may_come_thismonth': days_package_may_come_thismonth, 'days_package_may_come_nextmonth': days_package_may_come_nextmonth, 'host_package_conflict': host_package_conflict, #Calendar check boxes form 'cal_form': cal_form, 'packagedays': packagedays, 'packagedays_string': packagedays_string, 'packagedays_count': packagedays_count, 'cal_form_submitted': cal_form_submitted, 'calendar_submit_button_text': calendar_submit_button_text, #payment stuff once the calendar checkboxes are checked 'trans_form_package': trans_form_package, 'invoice': invoice, 'favortype': favortype, 'errors_on_trans_form': errors_on_trans_form, 'transaction_form_submitted': transaction_form_submitted, 'random3digits': random3digits, 'payment_needed': payment_needed, 'amount_due': amount_due, 'remaining_balance': remaining_balance, 'request': request, })