Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get(self, request, *args, **kwargs):
cal = icalendar.Calendar()
cal.add('prodid', '-// {} calendar //'.format(settings.BRAND_NAME))
cal.add('version', '2.0')
for module in self.instance.course_modules.all():
event = icalendar.Event()
event.add('summary', module.name)
event.add('dtstart',
module.closing_time - datetime.timedelta(hours=1))
event.add('dtend', module.closing_time)
event.add('dtstamp', module.closing_time)
event['uid'] = "module/" + str(module.id) + "/A+"
cal.add_component(event)
return HttpResponse(cal.to_ical(),
content_type="text/calendar; charset=utf-8")
def item_organizer(self, obj):
organizer_dic = obj.get('organizer', None)
if organizer_dic:
if isinstance(organizer_dic, dict):
organizer = icalendar.vCalAddress('MAILTO:%s' % organizer_dic['email'])
for key, val in organizer_dic.items():
if key is not 'email':
organizer.params[key] = icalendar.vText(val)
else:
organizer = icalendar.vCalAddress('MAILTO:%s' % organizer_dic)
return organizer
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=-1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
)
def test_check_understood_rrule():
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=1SU')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
)
def test_check_understood_rrule():
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=1SU')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
def test_check_understood_rrule():
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=1SU')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=-1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
)
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=-1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
)
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=1SU')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=-1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
)
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=-1')
)
assert not RecurrenceEditor.check_understood_rrule(
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
)