def calculate_start_date_and_week_navigation(self, start_date, period):
     if start_date:
         start_date = datetime.strptime(start_date, "%Y-%m-%d").date()
         week_nav = WeekNav(start_date - period, start_date, start_date + period)
         if start_date <= time.tomorrow():  # start_date too early
             start_date = time.tomorrow()
             week_nav = WeekNav(None, start_date, start_date + period)
         max_date = date.today() + timedelta(days=45)
         logging.info("max date %s" % max_date)
         if start_date >= max_date:
             start_date = max_date
             week_nav = WeekNav(start_date - period, start_date, None)
     else:
         start_date = time.tomorrow()
         week_nav = WeekNav(None, start_date, start_date + period)
     # return 2 values: stat_date and week_nav
     return start_date, week_nav
 def calculate_start_date_and_week_navigation(self, start_date, period):
     if start_date:
         start_date = datetime.strptime(start_date, "%Y-%m-%d").date()
         week_nav = WeekNav(start_date - period, start_date,
                            start_date + period)
         if (start_date <= time.tomorrow()):  # start_date too early
             start_date = time.tomorrow()
             week_nav = WeekNav(None, start_date, start_date + period)
         max_date = date.today() + timedelta(days=45)
         logging.info('max date %s' % max_date)
         if (start_date >= max_date):
             start_date = max_date
             week_nav = WeekNav(start_date - period, start_date, None)
     else:
         start_date = time.tomorrow()
         week_nav = WeekNav(None, start_date, start_date + period)
     # return 2 values: stat_date and week_nav
     return start_date, week_nav
Beispiel #3
0
    def get(self, vanity_url=None):
        # convert to lowercase
        vanity_url = vanity_url.lower()

        logging.info(
            '(ProviderPublicProfileHandler.get) Received vanity_url: %s' %
            vanity_url)
        provider = db.get_provider_from_vanity_url(vanity_url)
        if provider:
            logging.info(
                '(ProviderPublicProfileHandler.get) Found provider %s, rendering profile'
                % provider.email)

            # set the display language to provider's preference
            language = provider.profile_language
            if language:
                self.set_language(language)
            else:
                self.set_language(util.DEFAULT_LANG)

            # add some dates & times to display part of schedule on page
            start_date = time.tomorrow()
            period = timedelta(days=14)

            schedules = provider.get_schedules()
            confirmed_bookings = provider.get_future_confirmed_bookings()
            datetimes_map = util.generate_complete_datetimes_dict(
                schedules, start_date, period, confirmed_bookings)
            #
            #datetimes_map = util.remove_confirmed_bookings_from_schedule(schedule_datetimes_dict, confirmed_bookings)

            dtm = datetimes_map

            date_time_list = []

            # flatten the map and give first 5 results
            # TODO: sort
            count = 0
            for (day_key, day_times) in dtm.items():
                if count >= 5:
                    break

                for t in day_times:
                    date_time_list.append((day_key, day_times, t))
                    count += 1
                    if count >= 5:
                        break

            date_time_list = sorted(date_time_list, key=itemgetter(0, 2))

            # found a provider, render profile
            self.render_public_profile(
                provider=provider, date_time_list=date_time_list)

            # increment view count, store async
            # we don't really care if it doesn't work
            # old --> use event log instead
            provider.profile_views += 1
            provider.put_async()

            # log the event
            user = self.get_current_user()
            if user and user.key == provider.user:
                self.log_event(
                    user=provider.user, msg="Public profile: self-view")
            else:
                self.log_event(
                    user=provider.user, msg="Public profile: public view")

        else:
            logging.info(
                '(ProviderPublicProfileHandler.get) No provider found, sending to index'
            )

            # nobody found, send them to the homepage
            self.redirect("/")
Beispiel #4
0
    def get(self, vanity_url=None):
        # convert to lowercase
        vanity_url = vanity_url.lower()

        logging.info(
            '(ProviderPublicProfileHandler.get) Received vanity_url: %s' %
            vanity_url)
        provider = db.get_provider_from_vanity_url(vanity_url)
        if provider:
            logging.info(
                '(ProviderPublicProfileHandler.get) Found provider %s, rendering profile'
                % provider.email)

            # set the display language to provider's preference
            language = provider.profile_language
            if language:
                self.set_language(language)
            else:
                self.set_language(util.DEFAULT_LANG)

            # add some dates & times to display part of schedule on page
            start_date = time.tomorrow()
            period = timedelta(days=14)

            schedules = provider.get_schedules()
            confirmed_bookings = provider.get_future_confirmed_bookings()
            datetimes_map = util.generate_complete_datetimes_dict(
                schedules, start_date, period, confirmed_bookings)
            #
            #datetimes_map = util.remove_confirmed_bookings_from_schedule(schedule_datetimes_dict, confirmed_bookings)

            dtm = datetimes_map

            date_time_list = []

            # flatten the map and give first 5 results
            # TODO: sort
            count = 0
            for (day_key, day_times) in dtm.items():
                if count >= 5:
                    break

                for t in day_times:
                    date_time_list.append((day_key, day_times, t))
                    count += 1
                    if count >= 5:
                        break

            date_time_list = sorted(date_time_list, key=itemgetter(0, 2))

            # found a provider, render profile
            self.render_public_profile(provider=provider,
                                       date_time_list=date_time_list)

            # increment view count, store async
            # we don't really care if it doesn't work
            # old --> use event log instead
            provider.profile_views += 1
            provider.put_async()

            # log the event
            user = self.get_current_user()
            if user and user.key == provider.user:
                self.log_event(user=provider.user,
                               msg="Public profile: self-view")
            else:
                self.log_event(user=provider.user,
                               msg="Public profile: public view")

        else:
            logging.info(
                '(ProviderPublicProfileHandler.get) No provider found, sending to index'
            )

            # nobody found, send them to the homepage
            self.redirect("/")