Пример #1
0
    def get(self):
        logging.debug('In register->get')
        username = None
        user_logged_in = False
        user_registered = False
        notification = None
        url = users.create_login_url(self.request.uri)
        if users.get_current_user():
            url = users.create_logout_url('/')	
            user_logged_in = True
            username=users.get_current_user().nickname()
            tripuser = TripFilesUser.gql("WHERE who = :who",
                                who=users.get_current_user())
            if tripuser.count() > 0:
                self.redirect('/account/update')
        else:
            self.redirect(users.create_login_url(self.request.uri))
            
        viewhelper = ViewHelper(self.request)
        template_values = viewhelper.get_navigation_options()
        template_values.update(viewhelper.get_menu_options())
        notification = 'Please fill your details and click Register to start your free trial'
        
        template_values.update({ 'app_notification': '{"app_notification": "'+notification+'", "app_notification_type": "app_tip"}'})
        subscriptionMgr = SubscriptionManager()
        
        #subscription data
        active_subscriptions = subscriptionMgr.get_all_active_subscriptions()
        
        template_values.update({'active_subscriptions': active_subscriptions})
                                   
        path = os.path.join(os.path.dirname(__file__), '../../templates', 'account.html')

        self.response.out.write(template.render(path, template_values))
Пример #2
0
 def fix_user_id(self):
     tripusers = TripFilesUser.gql('')
     logging.debug('User ids #'+str(tripusers.count()))
     ids=''
     for tripuser in tripusers:
         provisions = UserProvisions.gql('WHERE who = :who', who=tripuser.who)
         if provisions.count()==1:
             provision = provisions.get()
             tripuser.user_id = provision.user_id
             tripuser.save()
             logstr = ''.join([tripuser.who.nickname(), ' - ', tripuser.user_id, ' <br />'])
             logging.debug('Updated '+logstr)
             ids = ids+logstr
             
     self.response.out.write('<html><body>User ids updated<br /> '+ids+'</body></html>');
Пример #3
0
    def post(self, action=None):       
        '''
        Updates user account - /account/update
        '''
        if not users.get_current_user():
            self.redirect('/')

        tripusers = TripFilesUser.gql("WHERE who = :who",
                    who=users.get_current_user())
        tripuser = tripusers.get()
        
        #if self.request.get('input_first_name'):
        tripuser.first_name = self.request.get('input_first_name').strip()
        #if self.request.get('input_middle_name'):
        tripuser.middle_name = self.request.get('input_middle_name').strip()
        #if self.request.get('input_last_name'):
        tripuser.last_name = self.request.get('input_last_name').strip()
            
        #if self.request.get('input_work_title'):
        tripuser.work_title = self.request.get('input_work_title').strip()

        #if self.request.get('input_work_id'):
        tripuser.work_id = self.request.get('input_work_id').strip()
        #if self.request.get('input_work_department'):
        tripuser.work_department = self.request.get('input_work_department').strip()
            
            
        #if self.request.get('input_mileage_template'):
        tripuser.mileage_template = self.request.get('input_mileage_template').strip()
            
            
        #if self.request.get('input_home_address'):
        tripuser.home_address = self.request.get('input_home_address').strip()
        #if self.request.get('input_office_base_address'):
        tripuser.office_base_address = self.request.get('input_office_base_address').strip()
        #if self.request.get('input_vehicle_make'):
        tripuser.vehicle_make = self.request.get('input_vehicle_make').strip()
        #if self.request.get('input_vehicle_cc'):
        tripuser.vehicle_cc = self.request.get('input_vehicle_cc').strip()
            
        #if self.request.get('input_vehicle_registration'):
        tripuser.vehicle_registration = self.request.get('input_vehicle_registration').strip()

        #tripuser.work_organization = 'Hillingdon PCT'
        tripuser.save()
            
        self.redirect('/account/update')
Пример #4
0
    def fix_user_id(self):
        tripusers = TripFilesUser.gql('')
        logging.debug('User ids #' + str(tripusers.count()))
        ids = ''
        for tripuser in tripusers:
            provisions = UserProvisions.gql('WHERE who = :who',
                                            who=tripuser.who)
            if provisions.count() == 1:
                provision = provisions.get()
                tripuser.user_id = provision.user_id
                tripuser.save()
                logstr = ''.join([
                    tripuser.who.nickname(), ' - ', tripuser.user_id, ' <br />'
                ])
                logging.debug('Updated ' + logstr)
                ids = ids + logstr

        self.response.out.write('<html><body>User ids updated<br /> ' + ids +
                                '</body></html>')
Пример #5
0
 def is_registered(self, user):
     tripusers = TripFilesUser.gql("WHERE who = :who", who=user)
     if tripusers.count() == 1:
         return True
     else:
         return False
Пример #6
0
    def post(self, action=None):
        if not users.get_current_user():
            self.redirect('/')

        startparam = self.request.get('startdate').strip()
        endparam = self.request.get('enddate').strip()
        dateformat = '%m/%d/%Y'

        if startparam != '' or endparam != '':
            startdate = time.strptime(startparam, dateformat)
            enddate = time.strptime(endparam, dateformat)

        if not startparam or not endparam:
            startdate = time.gmtime(
            )  #time.strftime(dateformat, time.gmtime())
            enddate = time.gmtime()  #time.strftime(dateformat, time.gmtime())

        startdate = time.strftime('%Y-%m-%d %H:%M:%S', startdate)
        enddate = time.strftime('%Y-%m-%d %H:%M:%S', enddate)

        trips = []
        userdata = None
        #AND when >= :start AND when <= :end
        if users.get_current_user():
            user = users.get_current_user()
            trip_user = TripFilesUser.gql("WHERE who =:who", who=user)
            userdata = trip_user.get()
            #if admin user is getting report for another user
            if self.request.get('user_email'):
                user_email = self.request.get('user_email').strip()
                logging.debug('user_email=' + user_email)
                user = User(email=self.request.get('user_email').strip())
                trip_users = TripFilesUser.gql("WHERE who =:who", who=user)
                logging.debug("Count=" + str(trip_users.count()))
                trip_user = trip_users.get()
                logging.debug('Report user='******'/')

        viewtrips = []
        report_total_distance = 0.0
        report_total_other_pound = 0
        report_total_other_pence = 0
        report_total_passenger_mileage = 0

        tripcount = 0
        firstpage_trips = []
        middlepage_trips = []  #trips in each middlepage
        for trip in trips:
            viewlegs = []
            trip_total_distance = 0.0
            count = len(trip.waypoints)
            waypoints_description = ''
            for i in xrange(count - 1):
                distance = (trip.distances[i + 1]) * 0.000621371192
                distance = round(distance, 2)
                viewleg = TripLegView(trip.waypoints[i], trip.waypoints[i + 1],
                                      distance,
                                      trip.when.strftime('%a, %d %b %Y'),
                                      i + 1)
                viewlegs.append(viewleg)
                trip_total_distance = trip_total_distance + distance
                if i == 0:
                    waypoints_description = trip.waypoints[i].upper(
                    ) + ' - ' + trip.waypoints[i + 1].upper()
                else:
                    waypoints_description = waypoints_description.upper(
                    ) + ' - ' + trip.waypoints[i + 1].upper()

            #if we have total_distance saved, use it since the user may have updated the total manually
            if trip.total_distance and trip.total_distance > 0:
                trip_total_distance = trip.total_distance

            other_expense_label = trip.other_expenses_label
            try:
                other_charges_pound = int(trip.other_expenses_charge / 100)
            except:
                other_charges_pound = 0

            if trip.other_expenses_charge > 0:
                other_charges_pence = trip.other_expenses_charge - (
                    other_charges_pound * 100)
            else:
                other_charges_pence = 0

            report_total_other_pence = report_total_other_pence + other_charges_pence + (
                other_charges_pound * 100)

            other_expense_pound = other_charges_pound if other_charges_pound > 0 else 0
            other_expense_pence = other_charges_pence if other_charges_pence > 0 else 0

            viewtrip = TripView(trip.when.strftime('%a, %d %b %Y'), viewlegs,
                                round(trip_total_distance, 2), trip.trip_code,
                                trip.key(), waypoints_description,
                                other_expense_label, other_expense_pound,
                                other_expense_pence, trip.passenger_count,
                                trip.passenger_mileage)

            #add viewtrip to report pages
            if tripcount < FIRSTPAGE_TRIPS_COUNT:
                firstpage_trips.append(viewtrip)

            if tripcount >= FIRSTPAGE_TRIPS_COUNT:
                middlepage_trips.append(viewtrip)

            report_total_distance = report_total_distance + trip_total_distance

            report_total_passenger_mileage = report_total_passenger_mileage + (
                trip.passenger_mileage if trip.passenger_mileage else 0)

            tripcount = tripcount + 1

        #split middle pages for report paging
        nextpages = []
        apage = []
        logging.debug('#middlepage_trips ' + str(len(middlepage_trips)))
        for (counter, atrip) in enumerate(middlepage_trips):
            apage.append(atrip)
            if (((counter + 1) % TRIPS_PER_PAGE) == 0):  #counter!= 0 and
                logging.debug('nextpage counter' + str(counter))
                nextpages.append(apage)
                apage = []
        #append all remaining trips
        if apage:
            nextpages.append(apage)

        startdate = time.strptime(startdate, '%Y-%m-%d %H:%M:%S')
        enddate = time.strptime(enddate, '%Y-%m-%d %H:%M:%S')
        startparam = time.strftime('%a, %d %b %Y', startdate)
        endparam = time.strftime('%a, %d %b %Y', enddate)

        try:
            report_other_charges_pound = int(report_total_other_pence / 100)
        except:
            report_other_charges_pound = 0

        if report_total_other_pence > 0:
            report_other_charges_pence = report_total_other_pence - (
                report_other_charges_pound * 100)
        else:
            report_other_charges_pence = 0

        viewreport = ReportView(startparam, endparam,
                                [firstpage_trips, nextpages],
                                round(report_total_distance,
                                      2), report_other_charges_pound,
                                report_other_charges_pence,
                                report_total_passenger_mileage)

        #reusing date for display
        template_values = {
            'reportview': viewreport,
            'userdata': userdata,
        }

        if action == 'download':
            path = os.path.join(os.path.dirname(__file__), '../../templates/',
                                'printable-tripreport.html')
            if userdata.mileage_template == 'BUCKS NHS TRUST':
                path = os.path.join(os.path.dirname(__file__),
                                    '../../templates/reports/',
                                    'bucks_nhs_trust.html')
            elif userdata.mileage_template == 'HILLINGDON PRIMARY CARE TRUST':
                path = os.path.join(os.path.dirname(__file__),
                                    '../../templates/',
                                    'printable-tripreport.html')
            html = template.render(path, template_values)
            logging.debug('Generating pdf...')
            self.pdf(html)
        else:
            path = os.path.join(os.path.dirname(__file__), '../../templates',
                                'tripreport.html')
            html = template.render(path, template_values)
            self.response.out.write(template.render(path, template_values))
Пример #7
0
    def post(self, action=None):
        if not users.get_current_user():
            self.redirect("/")

        startparam = self.request.get("startdate").strip()
        endparam = self.request.get("enddate").strip()
        dateformat = "%m/%d/%Y"

        if startparam != "" or endparam != "":
            startdate = time.strptime(startparam, dateformat)
            enddate = time.strptime(endparam, dateformat)

        if not startparam or not endparam:
            startdate = time.gmtime()  # time.strftime(dateformat, time.gmtime())
            enddate = time.gmtime()  # time.strftime(dateformat, time.gmtime())

        startdate = time.strftime("%Y-%m-%d %H:%M:%S", startdate)
        enddate = time.strftime("%Y-%m-%d %H:%M:%S", enddate)

        trips = []
        userdata = None
        # AND when >= :start AND when <= :end
        if users.get_current_user():
            user = users.get_current_user()
            trip_user = TripFilesUser.gql("WHERE who =:who", who=user)
            userdata = trip_user.get()
            # if admin user is getting report for another user
            if self.request.get("user_email"):
                user_email = self.request.get("user_email").strip()
                logging.debug("user_email=" + user_email)
                user = User(email=self.request.get("user_email").strip())
                trip_users = TripFilesUser.gql("WHERE who =:who", who=user)
                logging.debug("Count=" + str(trip_users.count()))
                trip_user = trip_users.get()
                logging.debug("Report user="******"WHERE who = :who AND when >= DATETIME(:start) AND when <= DATETIME(:end) ORDER BY when ASC",
                who=user,
                start=startdate,
                end=enddate,
            )

        else:
            self.redirect("/")

        viewtrips = []
        report_total_distance = 0.0
        report_total_other_pound = 0
        report_total_other_pence = 0
        report_total_passenger_mileage = 0

        tripcount = 0
        firstpage_trips = []
        middlepage_trips = []  # trips in each middlepage
        for trip in trips:
            viewlegs = []
            trip_total_distance = 0.0
            count = len(trip.waypoints)
            waypoints_description = ""
            for i in xrange(count - 1):
                distance = (trip.distances[i + 1]) * 0.000621371192
                distance = round(distance, 2)
                viewleg = TripLegView(
                    trip.waypoints[i], trip.waypoints[i + 1], distance, trip.when.strftime("%a, %d %b %Y"), i + 1
                )
                viewlegs.append(viewleg)
                trip_total_distance = trip_total_distance + distance
                if i == 0:
                    waypoints_description = trip.waypoints[i].upper() + " - " + trip.waypoints[i + 1].upper()
                else:
                    waypoints_description = waypoints_description.upper() + " - " + trip.waypoints[i + 1].upper()

            # if we have total_distance saved, use it since the user may have updated the total manually
            if trip.total_distance and trip.total_distance > 0:
                trip_total_distance = trip.total_distance

            other_expense_label = trip.other_expenses_label
            try:
                other_charges_pound = int(trip.other_expenses_charge / 100)
            except:
                other_charges_pound = 0

            if trip.other_expenses_charge > 0:
                other_charges_pence = trip.other_expenses_charge - (other_charges_pound * 100)
            else:
                other_charges_pence = 0

            report_total_other_pence = report_total_other_pence + other_charges_pence + (other_charges_pound * 100)

            other_expense_pound = other_charges_pound if other_charges_pound > 0 else 0
            other_expense_pence = other_charges_pence if other_charges_pence > 0 else 0

            viewtrip = TripView(
                trip.when.strftime("%a, %d %b %Y"),
                viewlegs,
                round(trip_total_distance, 2),
                trip.trip_code,
                trip.key(),
                waypoints_description,
                other_expense_label,
                other_expense_pound,
                other_expense_pence,
                trip.passenger_count,
                trip.passenger_mileage,
            )

            # add viewtrip to report pages
            if tripcount < FIRSTPAGE_TRIPS_COUNT:
                firstpage_trips.append(viewtrip)

            if tripcount >= FIRSTPAGE_TRIPS_COUNT:
                middlepage_trips.append(viewtrip)

            report_total_distance = report_total_distance + trip_total_distance

            report_total_passenger_mileage = report_total_passenger_mileage + (
                trip.passenger_mileage if trip.passenger_mileage else 0
            )

            tripcount = tripcount + 1

        # split middle pages for report paging
        nextpages = []
        apage = []
        logging.debug("#middlepage_trips " + str(len(middlepage_trips)))
        for (counter, atrip) in enumerate(middlepage_trips):
            apage.append(atrip)
            if ((counter + 1) % TRIPS_PER_PAGE) == 0:  # counter!= 0 and
                logging.debug("nextpage counter" + str(counter))
                nextpages.append(apage)
                apage = []
        # append all remaining trips
        if apage:
            nextpages.append(apage)

        startdate = time.strptime(startdate, "%Y-%m-%d %H:%M:%S")
        enddate = time.strptime(enddate, "%Y-%m-%d %H:%M:%S")
        startparam = time.strftime("%a, %d %b %Y", startdate)
        endparam = time.strftime("%a, %d %b %Y", enddate)

        try:
            report_other_charges_pound = int(report_total_other_pence / 100)
        except:
            report_other_charges_pound = 0

        if report_total_other_pence > 0:
            report_other_charges_pence = report_total_other_pence - (report_other_charges_pound * 100)
        else:
            report_other_charges_pence = 0

        viewreport = ReportView(
            startparam,
            endparam,
            [firstpage_trips, nextpages],
            round(report_total_distance, 2),
            report_other_charges_pound,
            report_other_charges_pence,
            report_total_passenger_mileage,
        )

        # reusing date for display
        template_values = {"reportview": viewreport, "userdata": userdata}

        if action == "download":
            path = os.path.join(os.path.dirname(__file__), "../../templates/", "printable-tripreport.html")
            if userdata.mileage_template == "BUCKS NHS TRUST":
                path = os.path.join(os.path.dirname(__file__), "../../templates/reports/", "bucks_nhs_trust.html")
            elif userdata.mileage_template == "HILLINGDON PRIMARY CARE TRUST":
                path = os.path.join(os.path.dirname(__file__), "../../templates/", "printable-tripreport.html")
            html = template.render(path, template_values)
            logging.debug("Generating pdf...")
            self.pdf(html)
        else:
            path = os.path.join(os.path.dirname(__file__), "../../templates", "tripreport.html")
            html = template.render(path, template_values)
            self.response.out.write(template.render(path, template_values))
Пример #8
0
    def get(self, action=None):
        '''
        Shows account details.  
        This is also the callback for spreedly - /account/subscription-update
        '''
        if not users.get_current_user():
            self.redirect(users.create_login_url(self.request.uri))

        notification = None
        tripuser = None
        if users.get_current_user():
            user_logged_in = True
            username=users.get_current_user().nickname()
            tripusers = TripFilesUser.gql("WHERE who = :who",
                                who=users.get_current_user())
            if tripusers.count() != 1:
                notification = '{"app_notification_type": "app_error", "app_notification": "We found a minor glitch in your account! Please contact Customer Support if you have a subscription with us" }'
                viewhelper = ViewHelper(self.request)
                template_values = viewhelper.get_navigation_options()
                template_values.update(viewhelper.get_menu_options())
                template_values.update({'notification': notification})
                path = os.path.join(os.path.dirname(__file__), '../../templates', 'error.html')
                self.response.out.write(template.render(path, template_values))                       
                return
            else:
                tripuser = tripusers.get()
                
                subscriptionMgr = SubscriptionManager()
                #retrieve subscription info
                if action=='subscription-update':
                    notification_msg = subscriptionMgr.updateUserProvisions(tripuser.user_id)
                    notification = '{"app_notification_type": "app_tip", "app_notification": "'+notification_msg+'" }'
                elif action=='update':
                    notification = '{"app_notification_type": "app_tip", "app_notification": "Account updated" }'
                    
               #spreedly url 
                subscription_url = subscriptionMgr.getNewSubscriberURL(self.request, 
                                                                       users.get_current_user().nickname(), tripuser)
                
                #subscription data
                active_subscriptions = subscriptionMgr.get_all_active_subscriptions()
                user_subscription = None
                valid_until = None
                valid_subscription = False
                subscription_expired = False
                userprovisions = UserProvisions.gql("WHERE user_id = :user_id", user_id=tripuser.user_id)
                if userprovisions.count() == 1:
                    logging.debug('User provision is valid')
                    userprovision = userprovisions.get()
                    valid_until = userprovision.valid_until.strftime('%a, %d %b %Y') if userprovision.valid_until else None
                    subscription_expired = accesscontroller.subscription_expired(users.get_current_user())
                    if subscription_expired:
                        notification_str = 'Your subscription has expired. Please follow the link below to renew your subscription'
                        notification =  '{"app_notification": "'+notification_str+'", "app_notification_type": "app_error"}'
                    elif userprovision.valid_until < datetime.combine(date.today(), anothertime()) + timedelta(days=3):
                        notification_str = 'Your subscription will expire in a few days. Please follow the link below to renew your subscription'
                        notification =  '{"app_notification": "'+notification_str+'", "app_notification_type": "app_error"}'

                    if userprovision.subscription_token:
                        subscription_url = subscriptionMgr.getSubscriptionUpdateURL(userprovision.subscription_token, self.request)
                        valid_subscription = True
                    for subscription in active_subscriptions:
                        logging.debug('Subscription =', subscription.name)
                        if subscription.code==userprovision.subscription_code:
                            user_subscription = subscription
                else:
                    logging.debug('User not provisioned')                    
                    valid_subscription = False 
                
       
            viewhelper = ViewHelper(self.request)
            template_values = viewhelper.get_navigation_options()
            template_values.update(viewhelper.get_menu_options())
 
            template_values.update({'tripuser': tripuser})
            template_values.update({'subscription_url': subscription_url})
            template_values.update({'valid_subscription': valid_subscription})
            
            template_values.update({'app_notification': notification, 
                                   'active_subscriptions': active_subscriptions,
                                   'user_subscription': user_subscription,
                                   'subscription_expired': subscription_expired,
                                   'subscription_valid_until': valid_until})
            
            if template_values.get('app_notification'):
                logging.debug('Notification='+template_values.get('app_notification'))
            
            path = os.path.join(os.path.dirname(__file__), '../../templates', 'account.html')
            self.response.out.write(template.render(path, template_values))                
        else:
            self.redirect('/')
Пример #9
0
 def is_registered(self, user):
     tripusers = TripFilesUser.gql("WHERE who = :who", who=user)
     if tripusers.count()==1:
         return True
     else:
         return False