Exemplo n.º 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))
Exemplo n.º 2
0
 def get(self):
     viewhelper = ViewHelper(self.request)
     
     template_values = viewhelper.get_navigation_options()
     template_values.update(viewhelper.get_menu_options())
     template_values.update(viewhelper.get_placeholder_trips())
     
     path = os.path.join(os.path.dirname(__file__), '../../templates', 'help.html')
     self.response.out.write(template.render(path, template_values))
Exemplo n.º 3
0
    def get(self):
        if not users.get_current_user():
            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())
        if users.get_current_user():
            if users.get_current_user().email() == "*****@*****.**" or users.is_current_user_admin():
                template_values.update({"adminEnabled": True, "user_email": users.get_current_user().email()})
        else:
            self.redirect(users.create_login_url(self.request.uri))

        path = os.path.join(os.path.dirname(__file__), "../../templates", "reporthome.html")
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 4
0
    def get(self):
        if not users.get_current_user():
            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())
        if users.get_current_user():
            if users.get_current_user().email(
            ) == '*****@*****.**' or users.is_current_user_admin():
                template_values.update({
                    'adminEnabled':
                    True,
                    'user_email':
                    users.get_current_user().email()
                })
        else:
            self.redirect(users.create_login_url(self.request.uri))

        path = os.path.join(os.path.dirname(__file__), '../../templates',
                            'reporthome.html')
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 5
0
    def post(self):
        trip_key = self.request.get('trip_key').strip()
        if users.get_current_user():
            trip = db.get(db.Key(trip_key))
            viewhelper = ViewHelper(self.request)
            template_values = viewhelper.get_navigation_options()
            template_values.update(viewhelper.get_menu_options())

            if trip and trip.who == users.get_current_user():
                count = 0
                triplegs = []
                total_distance = 0
                for waypoint, distance in zip(trip.waypoints, trip.distances):
                    distance_miles = '%.1f' % (distance * 0.000621371192)
                    tripleg = TripLegView(waypoint, None, distance_miles, trip.when, count)
                    triplegs.append(tripleg)
                    count=count+1
                    total_distance = total_distance + distance
                
                #fill triplegs with blank i it is less than 10
                if len(triplegs) < 10:
                    extras = 10-len(triplegs)
                    trips_length = len(triplegs)
                    for i in range(extras):
                        tripleg = TripLegView('', None, 0, '', trips_length+i)
                        logging.debug('Added filler tripleg #' +str(trips_length+i))
                        triplegs.append(tripleg)
            
                if trip.total_distance and trip.total_distance > 0:
                    total_miles = '%.1f' % trip.total_distance
                else:
                    total_miles = '%.1f' % (total_distance * 0.000621371192)
                    
                tripdate = trip.when.strftime('%m/%d/%Y')

                try:
                    cost_per_mile_pound = int(trip.pence_per_mile/100)
                except:
                    cost_per_mile_pound = 0

                if cost_per_mile_pound > 0:
                    cost_per_mile_pence = trip.pence_per_mile - (cost_per_mile_pound*100)
                else:
                    cost_per_mile_pence = 0

                label_parking_expenses = trip.other_expenses_label or ''

                try:
                    other_expenses_charges_pound = int(trip.other_expenses_charge/100)
                except:
                    other_expenses_charges_pound = 0

                if trip.other_expenses_charge > 0:
                    other_expenses_charges_pence = trip.other_expenses_charge - (other_expenses_charges_pound*100)
                else:
                    other_expenses_charges_pence = 0

                other_no_passengers = trip.passenger_count if trip.passenger_count else 0
                other_passenger_miles = trip.passenger_mileage if trip.passenger_mileage else 0

                mode_of_travel = trip.trip_code.strip() if trip.trip_code else ''

                template_values.update({'triplegs': triplegs, 
                                        'total_miles': total_miles,
                                        'tripdate': tripdate, 
                                        'trip_key': trip_key,
                                        'cost_per_mile_pound': cost_per_mile_pound,
                                        'cost_per_mile_pence': cost_per_mile_pence,
                                        'label_parking_expenses': label_parking_expenses,
                                        'other_expenses_charges_pound': other_expenses_charges_pound,
                                        'other_expenses_charges_pence': other_expenses_charges_pence,
                                        'mode_of_travel': mode_of_travel,
                                        'other_no_passengers': other_no_passengers,
                                        'other_passenger_miles': other_passenger_miles})

            else:
                template_values.update({'app_notification': 'Cannot find the trip.', 'app_notification_type': 'app_error'})

            path = os.path.join(os.path.dirname(__file__), '../../templates', 'index.html')
            self.response.out.write(template.render(path, template_values))
        else:
            self.redirect('/')
Exemplo n.º 6
0
    def post(self):
        trip_key = self.request.get('trip_key').strip()
        if users.get_current_user():
            trip = db.get(db.Key(trip_key))
            viewhelper = ViewHelper(self.request)
            template_values = viewhelper.get_navigation_options()
            template_values.update(viewhelper.get_menu_options())

            if trip and trip.who == users.get_current_user():
                count = 0
                triplegs = []
                total_distance = 0
                for waypoint, distance in zip(trip.waypoints, trip.distances):
                    distance_miles = '%.1f' % (distance * 0.000621371192)
                    tripleg = TripLegView(waypoint, None, distance_miles,
                                          trip.when, count)
                    triplegs.append(tripleg)
                    count = count + 1
                    total_distance = total_distance + distance

                #fill triplegs with blank i it is less than 10
                if len(triplegs) < 10:
                    extras = 10 - len(triplegs)
                    trips_length = len(triplegs)
                    for i in range(extras):
                        tripleg = TripLegView('', None, 0, '',
                                              trips_length + i)
                        logging.debug('Added filler tripleg #' +
                                      str(trips_length + i))
                        triplegs.append(tripleg)

                if trip.total_distance and trip.total_distance > 0:
                    total_miles = '%.1f' % trip.total_distance
                else:
                    total_miles = '%.1f' % (total_distance * 0.000621371192)

                tripdate = trip.when.strftime('%m/%d/%Y')

                try:
                    cost_per_mile_pound = int(trip.pence_per_mile / 100)
                except:
                    cost_per_mile_pound = 0

                if cost_per_mile_pound > 0:
                    cost_per_mile_pence = trip.pence_per_mile - (
                        cost_per_mile_pound * 100)
                else:
                    cost_per_mile_pence = 0

                label_parking_expenses = trip.other_expenses_label or ''

                try:
                    other_expenses_charges_pound = int(
                        trip.other_expenses_charge / 100)
                except:
                    other_expenses_charges_pound = 0

                if trip.other_expenses_charge > 0:
                    other_expenses_charges_pence = trip.other_expenses_charge - (
                        other_expenses_charges_pound * 100)
                else:
                    other_expenses_charges_pence = 0

                other_no_passengers = trip.passenger_count if trip.passenger_count else 0
                other_passenger_miles = trip.passenger_mileage if trip.passenger_mileage else 0

                mode_of_travel = trip.trip_code.strip(
                ) if trip.trip_code else ''

                template_values.update({
                    'triplegs':
                    triplegs,
                    'total_miles':
                    total_miles,
                    'tripdate':
                    tripdate,
                    'trip_key':
                    trip_key,
                    'cost_per_mile_pound':
                    cost_per_mile_pound,
                    'cost_per_mile_pence':
                    cost_per_mile_pence,
                    'label_parking_expenses':
                    label_parking_expenses,
                    'other_expenses_charges_pound':
                    other_expenses_charges_pound,
                    'other_expenses_charges_pence':
                    other_expenses_charges_pence,
                    'mode_of_travel':
                    mode_of_travel,
                    'other_no_passengers':
                    other_no_passengers,
                    'other_passenger_miles':
                    other_passenger_miles
                })

            else:
                template_values.update({
                    'app_notification': 'Cannot find the trip.',
                    'app_notification_type': 'app_error'
                })

            path = os.path.join(os.path.dirname(__file__), '../../templates',
                                'index.html')
            self.response.out.write(template.render(path, template_values))
        else:
            self.redirect('/')
Exemplo n.º 7
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('/')