def event_create(request): if not may_manage_planning(request.user): raise PermissionDenied if request.method == 'POST': form = EventCreateForm(request.POST) if form.is_valid(): fd = form.cleaned_data day = date_to_dt(fd['date']) e = Event({ 'name': fd['name'], 'date': day, 'kind': fd['template'] }) e.save() for poolname, periods in templates[fd['template']].items(): pool = Pool.by_name(poolname) for period in periods: begin_date = day + datetime.timedelta(seconds=period[0][0]) end_date = day + datetime.timedelta(seconds=period[1][0]) v = Vacancy({ 'name': period[2], 'event': _id(e), 'begin': (begin_date, period[0][1]), 'end': (end_date, period[1][1]), 'pool': _id(pool), 'assignee': None, 'reminder_needed': True, }) v.save() return HttpResponseRedirect( reverse('planning-event-edit', args=(e._id, ))) else: form = EventCreateForm() return render(request, 'planning/event_create.html', {'form': form})
def event_create(request): if request.method == 'POST': form = EventCreateForm(request.POST) if form.is_valid(): fd = form.cleaned_data day = date_to_dt(fd['date']) e = Event({ 'name': fd['name'], 'date': day, 'kind': fd['template']}) e.save() for poolname, periods in templates[fd['template']].items(): pool = Pool.by_name(poolname) for period in periods: begin_date = day + datetime.timedelta(seconds=period[0][0]) end_date = day + datetime.timedelta(seconds=period[1][0]) v = Vacancy({ 'name': period[2], 'event': _id(e), 'begin': (begin_date, period[0][1]), 'end': (end_date, period[1][1]) , 'pool': _id(pool), 'assignee': None, 'reminder_needed': True, }) v.save() return HttpResponseRedirect(reverse('planning-event-edit', args=(e._id,))) else: form = EventCreateForm() return render_to_response('planning/event_create.html', {'form': form}, context_instance=RequestContext(request))
def event_edit(request, eventid): if not may_manage_planning(request.user): raise PermissionDenied avform = None e = Event.by_id(eventid) if e is None: raise Http404 if request.method == 'POST': if request.POST['action'] == 'remove_event': for vacancy in e.vacancies(): vacancy.delete() e.delete() return HttpResponseRedirect(reverse('planning-poollist')) elif request.POST['action'] == 'remove_vacancy': Vacancy.by_id(_id(request.POST['vacancy_id'])).delete() return HttpResponseRedirect(reverse('planning-event-edit', args=(eventid,))) elif request.POST['action'] == 'add_vacancy': avform = AddVacancyForm(request.POST) if avform.is_valid(): fd = avform.cleaned_data (begin_hour, begin_minute) = map(int, fd['begin'].split(':')) (end_hour, end_minute) = map(int, fd['end'].split(':')) begin_offset = hm2s(begin_hour, begin_minute) end_offset = hm2s(end_hour, end_minute) begin_date = e.date + datetime.timedelta(seconds=begin_offset) end_date = e.date + datetime.timedelta(seconds=end_offset) v = Vacancy({ 'name': fd['name'], 'event': _id(e), 'begin': (begin_date, fd['begin_is_approximate'] == "True"), 'end': (end_date, fd['end_is_approximate'] == "True"), 'pool': _id(fd['pool']), 'assignee': None, 'reminder_needed': True, }) v.save() return HttpResponseRedirect(reverse('planning-event-edit', args=(eventid,))) if avform is None: avform = AddVacancyForm() pools = dict() for p in Pool.all(): pools[_id(p)] = p vacancies = list() for v in e.vacancies(): v.poolname = pools[v.pool_id].name v.assignee_text = str(v.assignee.name) if v.assignee else "-" v.vid = str(v._id) vacancies.append(v) vacancies.sort(key=lambda x: str(x.pool_id) + str(x.begin)) return render( request, 'planning/event_edit.html', {'name': e.name, 'kind': e.kind, 'date': e.date.date(), 'avform': avform, 'vacancies': vacancies}, )
def event_edit(request, eventid): if not may_manage_planning(request.user): raise PermissionDenied avform = None e = Event.by_id(eventid) if e is None: raise Http404 if request.method == 'POST': if request.POST['action'] == 'remove_event': for vacancy in e.vacancies(): vacancy.delete() e.delete() return HttpResponseRedirect(reverse('planning-poollist')) elif request.POST['action'] == 'remove_vacancy': Vacancy.by_id(_id(request.POST['vacancy_id'])).delete() return HttpResponseRedirect( reverse('planning-event-edit', args=(eventid, ))) elif request.POST['action'] == 'add_vacancy': avform = AddVacancyForm(request.POST) if avform.is_valid(): fd = avform.cleaned_data (begin_hour, begin_minute) = map(int, fd['begin'].split(':')) (end_hour, end_minute) = map(int, fd['end'].split(':')) begin_offset = hm2s(begin_hour, begin_minute) end_offset = hm2s(end_hour, end_minute) begin_date = e.date + datetime.timedelta(seconds=begin_offset) end_date = e.date + datetime.timedelta(seconds=end_offset) v = Vacancy({ 'name': fd['name'], 'event': _id(e), 'begin': (begin_date, fd['begin_is_approximate'] == "True"), 'end': (end_date, fd['end_is_approximate'] == "True"), 'pool': _id(fd['pool']), 'assignee': None, 'reminder_needed': True, }) v.save() return HttpResponseRedirect( reverse('planning-event-edit', args=(eventid, ))) if avform is None: avform = AddVacancyForm() pools = dict() for p in Pool.all(): pools[_id(p)] = p vacancies = list() for v in e.vacancies(): v.poolname = pools[v.pool_id].name v.assignee_text = str(v.assignee.name) if v.assignee else "-" v.vid = str(v._id) vacancies.append(v) vacancies.sort(key=lambda x: str(x.pool_id) + str(x.begin)) return render( request, 'planning/event_edit.html', { 'name': e.name, 'kind': e.kind, 'date': e.date.date(), 'avform': avform, 'vacancies': vacancies }, )
'tappers': [[hm2s(20, 30), hm2s(23), 'eerste dienst'], [hm2s(23), hm2s(25), 'tweede dienst'], [hm2s(25), hm2s(28), 'derde dienst']], 'bestuur': [[hm2s(20, 30), hm2s(24), 'openen'], [hm2s(24), hm2s(28), 'sluiten']], 'draai': [[hm2s(20, 45), hm2s(23), 'openen'], [hm2s(23), hm2s(24), 'prime-time'], [hm2s(24), hm2s(25), 'sluiten']]} day = datetime.datetime.strptime(sys.argv[1], '%Y-%m-%d') e = Event({ 'name': 'Borrel', 'date': day, 'kind': 'borrel' }) e.save() for _type, periods in typePeriods.items(): pool = Pool.by_name(_type) for period in periods: v = Vacancy({ 'name': period[2], 'event': _id(e), 'begin': day + datetime.timedelta(seconds=period[0]), 'end': day + datetime.timedelta(seconds=period[1]), 'pool': _id(pool), 'assignee': None, }) print v._data v.save()