当前位置: 首页>>代码示例>>Python>>正文


Python Calendar.save方法代码示例

本文整理汇总了Python中schedule.models.Calendar.save方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.save方法的具体用法?Python Calendar.save怎么用?Python Calendar.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schedule.models.Calendar的用法示例。


在下文中一共展示了Calendar.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
 def setUp(self):
     rule = Rule(frequency="WEEKLY")
     rule.save()
     cal = Calendar(name="MyCal")
     cal.save()
     self.recurring_data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'rule': rule,
         'calendar': cal
     }
     self.data = {
         'title': 'Recent Event',
         'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
         'calendar': cal
     }
     self.near_periodend_recurring_data = {
         'title': 'Special Event',
         'start': datetime.datetime(2014, 5, 1, 8, 0, tzinfo=pytz.utc),
         'end': datetime.datetime(2014, 5, 1, 9, 0, tzinfo=pytz.utc),
         'end_recurring_period': datetime.datetime(2014, 5, 8, 9, 0, tzinfo=pytz.utc),
         'rule': rule,
         'calendar': cal
     }
     self.recurring_event = Event.objects.create(**self.recurring_data)
     self.start = datetime.datetime(2008, 1, 12, 0, 0, tzinfo=pytz.utc)
     self.end = datetime.datetime(2008, 1, 27, 0, 0, tzinfo=pytz.utc)
开发者ID:jrutila,项目名称:django-schedule,代码行数:33,代码来源:test_occurrence.py

示例2: test_recurring_event_get_occurrence_in_timezone

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
    def test_recurring_event_get_occurrence_in_timezone(self):
        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency = "WEEKLY")
        rule.save()

        # Event start and end are UTC because that is what is coming
        # from the database
        event = self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2014, 3, 21, 6, 0, tzinfo=pytz.utc),
                    datetime.datetime(2014, 3, 21, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2014, 4, 11, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )
        event.save()
        tzinfo = pytz.timezone('Europe/Helsinki')
        start = tzinfo.localize(datetime.datetime(2014, 3, 28, 8, 0)) # +2
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
        occurrence.save()
        # DST change on March 30th from +2 to +3
        start = tzinfo.localize(datetime.datetime(2014, 4, 4, 8, 0)) # +3
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
开发者ID:jrutila,项目名称:django-scheduler,代码行数:28,代码来源:test_event.py

示例3: create

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
def create(request, form_class=TribeForm, template_name="tribes/create.html"):
    if request.user.is_authenticated() and request.method == "POST":
        if request.POST["action"] == "create":
            tribe_form = form_class(request.POST)
            if tribe_form.is_valid():
                tribe = tribe_form.save(commit=False)
                tribe.creator = request.user
                tribe.save()
                tribe.members.add(request.user)
                tribe.save()
                # @@@ this is just temporary to give tribes a single calendar -- will revisit during whole
                # tribe/project merge effort
                calendar = Calendar(name = "%s Calendar" % tribe.name)
                calendar.save()
                CalendarRelation.objects.create_relation(calendar, tribe, distinction="default", inheritable=True)
                if notification:
                    # @@@ might be worth having a shortcut for sending to all users
                    notification.send(User.objects.all(), "tribes_new_tribe", {"tribe": tribe}, queue=True)
                    if friends: # @@@ might be worth having a shortcut for sending to all friends
                        notification.send((x['friend'] for x in Friendship.objects.friends_for_user(tribe.creator)), "tribes_friend_tribe", {"tribe": tribe})
                #return render_to_response("base.html", {
                #}, context_instance=RequestContext(request))
                return HttpResponseRedirect(tribe.get_absolute_url())
        else:
            tribe_form = form_class()
    else:
        tribe_form = form_class()
    
    return render_to_response(template_name, {
        "tribe_form": tribe_form,
    }, context_instance=RequestContext(request))
开发者ID:bikeshkumar,项目名称:pinax,代码行数:33,代码来源:views.py

示例4: test_recurring_event_with_moved_get_occurrences_after

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
    def test_recurring_event_with_moved_get_occurrences_after(self):

        cal = Calendar(name="MyCal")
        cal.save()
        rule = Rule(frequency="WEEKLY")
        rule.save()
        recurring_event= self.__create_recurring_event(
                    'Recurrent event test get_occurrence',
                    datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
                    datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
                    rule,
                    cal,
                    )

        recurring_event.save()
        occurrence = recurring_event.get_occurrence(datetime.datetime(2008, 1, 12, 8, 0, tzinfo=pytz.utc))
        occurrence.move(
          datetime.datetime(2008, 1, 15, 8, 0, tzinfo=pytz.utc),
          datetime.datetime(2008, 1, 15, 9, 0, tzinfo=pytz.utc))
        gen = recurring_event.occurrences_after(
          datetime.datetime(2008, 1, 14, 8, 0, tzinfo=pytz.utc))
        occurrence2 = next(gen)
        #    end = datetime.datetime(2008, 1, 6, tzinfo=pytz.utc))
        #occurrence = occurrences[0]
        #occurrence2 = recurring_event.occurrences_after(datetime.datetime(2008, 1, 5, tzinfo=pytz.utc)).next()
        self.assertEqual(occurrence, occurrence2)
开发者ID:nwaxiomatic,项目名称:django-scheduler,代码行数:29,代码来源:test_event.py

示例5: test_edge_case_events

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
    def test_edge_case_events(self):
        cal = Calendar(name="MyCal")
        cal.save()
        data_1 = {
            'title': 'Edge case event test one',
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        data_2 = {
            'title': 'Edge case event test two',
            'start': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        event_one = Event(**data_1)
        event_two = Event(**data_2)
        event_one.save()
        event_two.save()
        occurrences_two = event_two.get_occurrences(datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                                                    datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc))
        self.assertEqual(1, len(occurrences_two))

        occurrences_one = event_one.get_occurrences(datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                                                    datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc))
        self.assertEqual(0, len(occurrences_one))
开发者ID:nwaxiomatic,项目名称:django-scheduler,代码行数:28,代码来源:test_event.py

示例6: setUp

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
    def setUp(self):
        weekly = Rule(frequency="WEEKLY")
        weekly.save()
        daily = Rule(frequency="DAILY")
        daily.save()
        cal = Calendar(name="MyCal")
        cal.save()

        self.event1 = Event(**{
            'title': 'Weekly Event',
            'start': datetime.datetime(2009, 4, 1, 8, 0),
            'end': datetime.datetime(2009, 4, 1, 9, 0),
            'end_recurring_period': datetime.datetime(2009, 10, 5, 0, 0),
            'rule': weekly,
            'calendar': cal
        })
        self.event1.save()
        self.event2 = Event(**{
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 9, 0),
            'end': datetime.datetime(2008, 1, 5, 10, 0),
            'end_recurring_period': datetime.datetime(2009, 5, 5, 0, 0),
            'rule': daily,
            'calendar': cal
        })
        self.event2.save()
开发者ID:macanhhuy,项目名称:django-schedule,代码行数:28,代码来源:test_utils.py

示例7: save

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
 def save(self, force_insert=False, force_update=False):
     super(CircleEvent, self).save(force_insert, force_update)
     try:
         cal = Calendar.objects.get(pk=1)
     except Calendar.DoesNotExist:
         cal = Calendar(name="Community Calendar")
         cal.save()
     cal.events.add(self)
开发者ID:TheProjecter,项目名称:pinax-cohousing,代码行数:10,代码来源:models.py

示例8: test_get_calendar_for_object

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
 def test_get_calendar_for_object(self):
     calendar = Calendar(name='My Cal')
     calendar.save()
     rule = Rule()
     rule.save()
     calendar.create_relation(rule)
     result = Calendar.objects.get_calendar_for_object(rule)
     self.assertEqual(result.name, 'My Cal')
开发者ID:JoshLabs,项目名称:django-scheduler,代码行数:10,代码来源:test_calendar.py

示例9: TestEventViews

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
class TestEventViews(LoggedInTestCase):

    def setUp(self):
        super(TestEventViews, self).setUp()
        self.cal = Calendar(
            name=random_string(),
            slug=random_string(),
        )
        self.cal.save()
        self.event = Event(
            start=timezone.now(),
            end=timezone.now() + timedelta(weeks=6),
            title=random_string(),
            calendar=self.cal,
        )
        self.event.save()

    def tearDown(self):
        super(TestEventViews, self).tearDown()
        try:
            self.cal.delete()
            self.event.delete()
        except:
            pass

    def test_event_can_be_recurring(self):
        rule = Rule(
            name=random_string(),
            description=random_string(),
            frequency='WEEKLY',
        )
        rule.save()
        try:
            url = reverse(
                'openduty.events.create_or_edit_event',
                kwargs = {
                    'calendar_slug': self.cal.slug,
                    'event_id': str(self.event.id),
                },
            )
            response = self.client.post(
                path = url,
                data = {
                    "start_0": self.event.start.strftime('%Y-%m-%d'),
                    "start_1": "09:00",
                    "end_0": self.event.end.strftime('%Y-%m-%d'),
                    "end_1": "23:00",
                    "description": "desc",
                    "rule": str(rule.id),
                    "oncall": "foo",
                    "fallback": "bar",
                },
            )
            self.assertEqual(302, response.status_code)
            e = Event.objects.get(id=self.event.id)
            self.assertEqual(rule, e.rule)
        finally:
            rule.delete()
开发者ID:40a,项目名称:openduty,代码行数:60,代码来源:test_events.py

示例10: test_occurrences_after_with_events_before_returns_empty

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
 def test_occurrences_after_with_events_before_returns_empty(self):
     calendar = Calendar()
     calendar.save()
     start_after = timezone.now() + datetime.timedelta(days=-1)
     end_after = start_after + datetime.timedelta(hours=1)
     event = self.__create_event(start_after, end_after)
     calendar.events.add(event)
     occurrences = list(calendar.occurrences_after(timezone.now()))
     self.assertEqual(occurrences, [])
开发者ID:JoshLabs,项目名称:django-scheduler,代码行数:11,代码来源:test_calendar.py

示例11: test_occurrences_after_with_events_after_returns_events

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
 def test_occurrences_after_with_events_after_returns_events(self):
     calendar = Calendar()
     calendar.save()
     start_after = timezone.now() + datetime.timedelta(days=1)
     end_after = start_after + datetime.timedelta(hours=1)
     event = self.__create_event(start_after, end_after)
     calendar.events.add(event)
     occurrences = list(calendar.occurrences_after(timezone.now()))
     self.assertEquals(len(occurrences), 1)
     self.assertEquals(occurrences[0].start, start_after)
     self.assertEquals(occurrences[0].end, end_after)
开发者ID:AltSchool,项目名称:django-scheduler,代码行数:13,代码来源:test_calendar.py

示例12: test_get_calendar_for_object_with_more_than_one_calendar

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
 def test_get_calendar_for_object_with_more_than_one_calendar(self):
     calendar_1 = Calendar(name='My Cal 1')
     calendar_1.save()
     calendar_2 = Calendar(name='My Cal 2')
     calendar_2.save()
     rule = Rule()
     rule.save()
     calendar_1.create_relation(rule)
     calendar_2.create_relation(rule)
     with self.assertRaises(AssertionError):
         result = Calendar.objects.get_calendar_for_object(rule)
开发者ID:JoshLabs,项目名称:django-scheduler,代码行数:13,代码来源:test_calendar.py

示例13: test_event_get_ocurrence

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
    def test_event_get_ocurrence(self):

        cal = Calendar(name='MyCal')
        cal.save()
        start = timezone.now() + datetime.timedelta(days=1)
        event = self.__create_event(
                            'Non recurring event test get_occurrence',
                            start,
                            start + datetime.timedelta(hours=1),
                            cal)
        event.save()
        occurrence = event.get_occurrence(start)
        self.assertEqual(occurrence.start, start)
开发者ID:nwaxiomatic,项目名称:django-scheduler,代码行数:15,代码来源:test_event.py

示例14: optionnal_calendar_new

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
def optionnal_calendar_new(sender, **kwargs):
    event = kwargs.pop('instance')

    if not isinstance(event, Event):
        return True
    if not event.calendar:
        try:
            calendar = Calendar._default_manager.get(name='defaulter')
        except Calendar.DoesNotExist:
            calendar = Calendar(name='defaulter', slug='defaulter')
            calendar.save()

        event.calendar = calendar
    return True
开发者ID:gitter-badger,项目名称:brownstonetutors,代码行数:16,代码来源:models.py

示例15: test_occurences_after_with_no_params

# 需要导入模块: from schedule.models import Calendar [as 别名]
# 或者: from schedule.models.Calendar import save [as 别名]
    def test_occurences_after_with_no_params(self):

        cal = Calendar(name='MyCal')
        cal.save()
        start = timezone.now() + datetime.timedelta(days=1)
        event = self.__create_event(
                            'Non recurring event test get_occurrence',
                            start,
                            start + datetime.timedelta(hours=1),
                            cal)
        event.save()
        occurrences = list(event.occurrences_after())
        self.assertEqual(len(occurrences), 1)
        self.assertEqual(occurrences[0].start, start)
        self.assertEqual(occurrences[0].end, start + datetime.timedelta(hours=1))
开发者ID:nwaxiomatic,项目名称:django-scheduler,代码行数:17,代码来源:test_event.py


注:本文中的schedule.models.Calendar.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。