Exemplo n.º 1
0
    def _show_prep(self, report_id):
        report = Report.load(report_id)
        campaigns = products = companies = users = vendors = None
        if report.show_campaign_id:
            campaigns = util.select_list(Campaign.find_all(self.enterprise_id), 'campaign_id', 'name', True)

        if report.show_vendor_id:
            vendors = util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name', True)

        if report.show_company_id:
            companies = util.select_list(Company.find_all(self.enterprise_id), 'company_id', 'name', True)

        if report.show_user_id:
            users = util.select_list(Users.find_all(self.enterprise_id), 'user_id', 'user_id', True)

        if report.show_product_id:
            products = util.select_list(Product.find_all(self.enterprise_id), 'product_id', 'name', True)

        return {
            'today' : util.today_date(),
            'tomorrow' : util.tomorrow(),
            'thirty_ago' : util.today_date() - datetime.timedelta(days=30),
            'rpt_end_dt' : self.request.GET.get('rpt_end_dt'),
            'rpt_start_dt' : self.request.GET.get('rpt_start_dt'),
            'enterprise_id' : self.enterprise_id,
            'report' : report,
            'campaigns' : campaigns,
            'products' : products,
            'companies' : companies,
            'users' : users,
            'vendors' : vendors
            }
Exemplo n.º 2
0
    def _edit_impl(self):
        discount_id = self.request.matchdict.get('discount_id')
        discount = None
        if discount_id:
            discount = Discount.load(discount_id)
            self.forbid_if(not discount or discount.enterprise_id != self.enterprise_id)
        else:
            discount = Discount()

        included_products = discount.get_products()
        not_included_products = []
        for prod in Product.find_all(self.enterprise_id):
            found = False
            for incl in included_products:
                if incl.product_id == prod.product_id:
                    found = True
                    break
            if found == False:
                not_included_products.append(prod)

        return {
            'discount': discount,
            'included_products' : included_products,
            'not_included_products' : not_included_products,
            'excluded' : Product.find_all(self.enterprise_id),
            'tomorrow' : util.today_date() + datetime.timedelta(days=1),
            'plus14' : util.today_date() + datetime.timedelta(days=14)
            }
Exemplo n.º 3
0
 def _edit_impl(self):
     appointment_id = self.request.matchdict.get('appointment_id')
     customer_id = self.request.matchdict.get('customer_id')
     if appointment_id:
         appointment = Appointment.load(appointment_id)
         self.forbid_if(not appointment)
     else:
         appointment = Appointment()
     hours = util.hours_list()
     customer = None
     customer = Customer.load(customer_id)
     self.forbid_if(customer and customer.campaign.company.enterprise_id != self.enterprise_id)
     appointment.customer_id = customer_id
     return {
         'today' : util.today_date(),
         'tomorrow' : util.today_date() + datetime.timedelta(days=1),
         'customer' : customer,
         'appointment' : appointment,
         'timezones' : country_timezones('US'),
         'hours' : hours
         }
Exemplo n.º 4
0
 def _month_view_impl(self, year=None, month=None):
     year = year if year else int(self.request.matchdict.get('year'))
     month = month if month else int(self.request.matchdict.get('month'))
     appointments = Appointment.find_by_month(year, month, self.request.ctx.user)
     first_day_of_month = datetime.date(year, month, 1)
     calendar.setfirstweekday(6)
     month_list = util.month_list_simple()
     month_name = month_list[month-1]
     next_month = first_day_of_month + datetime.timedelta(weeks=5)
     last_month = first_day_of_month - datetime.timedelta(weeks=1)
     month_cal = calendar.monthcalendar(year, month)
     return {
         'today' : util.today_date(),
         'appointments' : appointments,
         'month_cal' : month_cal,
         'month_name' : month_name,
         'month' : month,
         'year' : year,
         'next_month' : next_month,
         'last_month' : last_month
         }
Exemplo n.º 5
0
 def test_util(self):
     d8e = util.today_date()
     dtime = util.today()
     assert util.format_rss_date(d8e) == d8e.strftime("%a, %d %b %Y %H:%M:%S EST")
     assert util.words_date(dtime) == dtime.strftime("%B %d, %Y")
     assert util.is_empty(" ") == True
     assert util.float_("8") == None
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 2) == [3, 4]
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], None, None) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
     assert util.parse_date("2012-05-06") == datetime.datetime.strptime("2012-05-06", "%Y-%m-%d")
     today_ = datetime.date.today()
     assert [today_.year + 10, today_.year + 10] in util.year_list()
     assert util.month_list()[0] == ["1", "January"]
     assert util.this_year() == datetime.date.today().year
     assert util.get_first_day(today_) == util.get_first_day(
         today_
     )  # this is pretty dumb.  it works, just get it covered.
     assert util.get_last_day(today_) == util.get_last_day(today_)
     assert util.to_uuid("ken") == None
     assert int(util.average([1, 2, 3])) == 2
     assert util.format_date(util.truncate_datetime(dtime)) == util.str_today()
     assert util.is_today(d8e) == True
Exemplo n.º 6
0
    def test_dates(self):
        d8e = util.today_date()
        dtime = util.today()
        assert h.is_today(d8e)
        assert h.str_today() == util.str_today()
        assert h.date_time(None) == ''
        assert h.date_time(d8e) == d8e.strftime("%Y-%m-%d %H:%M:%S")
        assert h.date_(None) == ''
        assert h.date_(d8e) == d8e.strftime("%Y-%m-%d")
        assert h.format_date(None) == ''
        assert h.format_date(d8e) == d8e.strftime("%Y-%m-%d")
        assert h.words_date_time(None) == ''
        assert h.words_date_time(dtime) == dtime.strftime("%B %d, %Y at %I:%M %p")
        assert h.slash_date(None) == ''
        assert h.slash_date(dtime) == dtime.strftime("%m/%d/%Y")
        assert h.words_date(None) == ''
        assert h.words_date(dtime) == dtime.strftime("%B %d, %Y")
        assert h.this_year() == datetime.date.today().year
        self.assertEqual('checkbox' in h.chkbox('fud'), True)

        dobj = TestObj()
        assert h.get(dobj, 'a') == 'aa'
        assert h.get(dobj, 'bogus') == ''
Exemplo n.º 7
0
 def tomorrow(self):
     tomorrow = util.today_date() + datetime.timedelta(days=1)
     return self._day_view_impl(int(tomorrow.year), int(tomorrow.month), int(tomorrow.day))