def test_by_date(self): # create published calendar published_cal = Calendar(title='title', state='published') published_cal.save() published_cal.sites.add(self.web_site) published_cal.save() # create published content content = ModelBase(title='title', state='published') content.save() content.sites.add(self.web_site) content.save() # create entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=content) entry_obj.save() entry_obj.calendars.add(published_cal) entry_obj.save() now = datetime.now() date = now.date() # result should only contain the entry for the date result = EntryItem.permitted.by_date(date) self.failUnlessEqual(result.count(), 1)
def test_now(self): # create published calendar published_cal = Calendar(title='title', state='published') published_cal.save() published_cal.sites.add(self.web_site) published_cal.save() # create published content content = ModelBase(title='title', state='published') content.save() content.sites.add(self.web_site) content.save() # create entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=content) entry_obj.save() entry_obj.calendars.add(published_cal) entry_obj.save() # should return currently active entry items, ordered by start queryset = EntryItem.permitted.now() self.failUnless(queryset.count()) for entry_item in queryset: self.failUnless(entry_item.start < datetime.now()) self.failUnless(entry_item.end > datetime.now())
def test_by_model(self): # create published calendar published_cal = Calendar(title='title', state='published') published_cal.save() published_cal.sites.add(self.web_site) published_cal.save() # create published wanted content wanted_content = WantedContent(title='title', state='published') wanted_content.save() wanted_content.sites.add(self.web_site) wanted_content.save() # create published unwanted content unwanted_content = UnwantedContent(title='title', state='published') unwanted_content.save() unwanted_content.sites.add(self.web_site) unwanted_content.save() # create entries for wanted entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=wanted_content) entry_obj.save() entry_obj.calendars.add(published_cal) entry_obj.save() # create entries for unwanted entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=unwanted_content) entry_obj.save() entry_obj.calendars.add(published_cal) entry_obj.save() # should only return entry items for content of the provided model. queryset = EntryItem.permitted.by_model(WantedContent) for obj in queryset: self.failUnlessEqual(obj.content.class_name, 'WantedContent')
def handle(year, month, day, def_orders): start_date = datetime.date(year, month, day) list_of_dates = [] for i in range(0,7): k = start_date + datetime.timedelta(days=i) list_of_dates.append(k) list_of_times = [] deliv_times = [(7,45),(8,00),(8,15),(8,30),(8,45),(9,00),(9,15),(9,30),(9,45),(10,00),(10,15),(10,30)] for time in deliv_times: k = datetime.time(time[0], time[1]) list_of_times.append(k) for d in list_of_dates: for t in list_of_times: e = Entry(start_time=t, date=d, deliveries_avail=def_orders) e.save() date_str = str(year) + "-" + str(month) + "-" + str(date) print "Successfully populated"
def populate_menu(request): # Get today's date today = datetime.date.today() # Current week will be this week unless it is Friday, Saturday, or Sunday current_week = datetime.date.today().isocalendar()[1] mon_date = today - datetime.timedelta(days=today.weekday()) if datetime.date.today().isocalendar()[2] == 5 or datetime.date.today().isocalendar()[2] == 6 or datetime.date.today().isocalendar()[2] == 7: current_week = datetime.date.today().isocalendar()[1] + 1 mon_date = today + datetime.timedelta(days=-today.weekday(), weeks=1) # Get a list of all days of the week days = [] # And populate it (make 0-5 if weekdays only) for i in range(0,7): to_add = mon_date + datetime.timedelta(days=i) days.append(to_add) # Add and save entries restaurant = Restaurant.objects.get(id=1) for day in days: for hour in range(8,10): for k in [0, 20, 40]: new_entry = Entry(start_time=datetime.time(hour, k), date=day, deliveries_available=2, restaurant=restaurant, revenue=0, window_length=20) new_entry.save() print "Successfully populated" return dashboard(request)
def initialize_week(request): context = RequestContext(request) mon = request.POST.get("m") tue = request.POST.get("t") wed = request.POST.get("w") thu = request.POST.get("th") fri = request.POST.get("f") sat = request.POST.get("s") sun = request.POST.get("su") start_hour = int(request.POST.get("start_time_hour")) start_min = int(request.POST.get("start_time_min")) daily_entries = int(request.POST.get("num_entries")) window_length = int(request.POST.get("win_len")) days = [mon, tue, wed, thu, fri, sat, sun] today = datetime.today().date() + timedelta(days=7) week = today.isocalendar()[1] weekday = today.isocalendar()[2] weekday = today.isocalendar()[2] monday = today - timedelta(days=weekday-1) tuesday = today - timedelta(days=weekday-2) wednesday = today - timedelta(days=weekday-3) thursday = today - timedelta(days=weekday-4) friday = today - timedelta(days=weekday-5) saturday = today - timedelta(days=weekday-6) sunday = today - timedelta(days=weekday-7) if (weekday == 6) or (weekday == 7): week = week + 1 monday = monday + timedelta(days=7) tuesday = tuesday + timedelta(days=7) wednesday = wednesday + timedelta(days=7) thursday = thursday + timedelta(days=7) friday = friday + timedelta(days=7) saturday = saturday + timedelta(days=7) sunday = sunday + timedelta(days=7) if mon == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = monday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() if tue == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = tuesday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() if wed == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = wednesday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() if thu == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = thursday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() if fri == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = friday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() if sat == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = saturday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() if sun == "on": start_time = time(start_hour, start_min) for k in range(daily_entries): new_entry = Entry( time = start_time, date = sunday, restaurant = Restaurant.objects.get(id=1), length = window_length ) new_entry.save() d = date(2000, 01, 01) dt = datetime.combine(d, start_time) start_dt = dt + timedelta(minutes=window_length) start_time = start_dt.time() return redirect('set_calendar')
def test_get_query_set(self): # create unpublished calendar unpublished_cal = Calendar(title='title', state='unpublished') unpublished_cal.save() unpublished_cal.sites.add(self.web_site) unpublished_cal.save() # create staging calendar staging_cal = Calendar(title='title', state='staging') staging_cal.save() staging_cal.sites.add(self.web_site) staging_cal.save() # create published calendar published_cal = Calendar(title='title', state='published') published_cal.save() published_cal.sites.add(self.web_site) published_cal.save() # create unpublished content unpublished_content = ModelBase(title='title', state='unpublished') unpublished_content.save() unpublished_content.sites.add(self.web_site) unpublished_content.save() # create staging content staging_content = ModelBase(title='title', state='staging') staging_content.save() staging_content.sites.add(self.web_site) staging_content.save() # create published content published_content = ModelBase(title='title', state='published') published_content.save() published_content.sites.add(self.web_site) published_content.save() # entries with unpublished calendars and content should not be available in queryset # create unpublished cal and content entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=unpublished_content) entry_obj.save() entry_obj.calendars.add(unpublished_cal) entry_obj.save() queryset = EntryItem.permitted.all() self.failIf(queryset.count()) Entry.objects.all().delete() # entries with unpublished calendars should not be available in queryset, regardless of content state # create unpublished cal, published content entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=published_content) entry_obj.save() entry_obj.calendars.add(unpublished_cal) entry_obj.save() queryset = EntryItem.permitted.all() self.failIf(queryset.count()) Entry.objects.all().delete() # entries with unpublished content should not be available in queryset, regardless of cal state # create unpublished content, published cal entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=unpublished_content) entry_obj.save() entry_obj.calendars.add(published_cal) entry_obj.save() queryset = EntryItem.permitted.all() self.failIf(queryset.count()) Entry.objects.all().delete() # entries with staging calendars and content should be available in queryset but only if settings.STAGING = True # create staging cal and content entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=staging_content) entry_obj.save() entry_obj.calendars.add(staging_cal) entry_obj.save() settings.STAGING = False queryset = EntryItem.permitted.all() self.failIf(queryset.count()) settings.STAGING = True queryset = EntryItem.permitted.all() self.failUnless(queryset.count()) Entry.objects.all().delete() # entries with published cal and content should be available in queryset # create published cal and content entries entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=published_content) entry_obj.save() entry_obj.calendars.add(published_cal) entry_obj.save() queryset = EntryItem.permitted.all() self.failUnless(queryset.count()) Entry.objects.all().delete() # queryset should not contain items for other sites mobile_site = Site(domain="mobi.address.com") mobile_site.save() # create published calendar for mobile site published_cal_mobile = Calendar(title='title', state='published') published_cal_mobile.save() published_cal_mobile.sites.add(mobile_site) published_cal_mobile.save() # create published calendar for mobile site published_content_mobile = ModelBase(title='title', state='published') published_content_mobile.save() published_content_mobile.sites.add(mobile_site) published_content_mobile.save() entry_obj = Entry(start=datetime.now(), end=datetime.now() + timedelta(days=1), repeat="daily", repeat_until=(datetime.now() + timedelta(days=30)).date(), content=published_content_mobile) entry_obj.save() entry_obj.calendars.add(published_cal_mobile) entry_obj.save() queryset = EntryItem.permitted.all() self.failIf(queryset.count())