Example #1
0
 def __init__(self, filename = 'event.json'):
     '''
     EventRepository class constructor
     :param filename: Default value 'event.json'
     :return:
     '''
     self.__datafile = filename
     Event.set_class_id(self.get_max_id())
Example #2
0
    def test_get_max_id(self):
        Event.set_class_id(0)
        io = IO('test.json')
        io.set([])
        repo = EventRepository('test.json')
        self.assertEqual(repo.get_max_id(), 0)
        content = repo.get_all()
        self.assertEqual(content, [])

        event1 = Event('14/01/2015', '14:00', 'Colectiv')
        event2 = Event('14/01/2015', '14:00', 'Colectiv')
        repo.insert(event1)
        repo.insert(event2)

        content = repo.get_all()
        self.assertEqual(repo.get_max_id(), 2)
Example #3
0
    def test_delete(self):
        Event.set_class_id(0)
        io = IO('test.json')
        io.set([])
        repo = EventRepository('test.json')

        event1 = Event('14/01/2015', '14:00', 'Colectiv')
        event2 = Event('14/01/2015', '14:00', 'Colectiv')
        repo.insert(event1)
        repo.insert(event2)

        event = repo.get(0)
        self.assertIs(type(event), Event)

        repo.delete(event)

        with self.assertRaisesRegex(ValueError, 'Event not found!'):
            updated_event = repo.get(0)
Example #4
0
    def test_get(self):
        Event.set_class_id(0)
        io = IO('test.json')
        io.set([])
        repo = EventRepository('test.json')

        event1 = Event('14/01/2015', '14:00', 'Colectiv')
        event2 = Event('14/01/2015', '14:00', 'Colectiv')
        repo.insert(event1)
        repo.insert(event2)

        content = repo.get(0)
        self.assertIs(type(content), Event)

        self.assertEqual(content.get_date(), '14/01/2015')
        self.assertEqual(content.get_time(), '14:00')
        self.assertEqual(content.get_description(), 'Colectiv')

        with self.assertRaisesRegex(ValueError, 'Event not found!'):
            content = repo.get(10)
Example #5
0
    def test_update(self):
        Event.set_class_id(0)
        io = IO('test.json')
        io.set([])
        repo = EventRepository('test.json')

        event1 = Event('14/01/2015', '14:00', 'Colectiv')
        event2 = Event('14/01/2015', '14:00', 'Colectiv')
        repo.insert(event1)
        repo.insert(event2)

        event = repo.get(0)
        self.assertIs(type(event), Event)
        event.update('15/01/2015', '15:00', 'Untold festival')

        repo.update(event)

        updated_event = repo.get(0)

        self.assertEqual(updated_event.get_date(), '15/01/2015')
        self.assertEqual(updated_event.get_time(), '15:00')
        self.assertEqual(updated_event.get_description(), 'Untold festival')
Example #6
0
def update_or_create_event(request, form, event_id):
    print(event_id)
    f_date = form.cleaned_data['event_date']
    f_title = form.cleaned_data['event_title']
    f_auto = form.cleaned_data['event_auto_send']
    f_sender = form.cleaned_data['event_sender']
    template_id = request.POST.get('event_default_template')
    if template_id != '':
        f_template = EmailTemplate.objects.get(id=request.POST.get('event_default_template'))
    else:
        f_template = None
    job_posting_ids = request.POST.getlist('event_jobs')
    if event_id is None:
        event = Event(title=f_title, date_time=f_date, enabled=True, auto_email=f_auto, auto_email_from=f_sender, email_template=f_template)
        event.save()
        event.job_postings=job_posting_ids
    else:
        event = Event.objects.get(id=event_id)
        event.title = f_title
        event.date_time = f_date
        event.job_postings = job_posting_ids
        event.auto_email = f_auto
        event.auto_email_from = f_sender
        event.email_template = f_template

    event.save()
    return