def form (request, id=False): if id: instance = get_object_or_404(Event, id=id, deleted=False) msg = _("Successfully edited contact") else: instance = Event() msg = _("Successfully added new contact") repeat_instance = RepeatOption() if instance.repeat: repeat_instance = instance.repeat if request.method == 'POST': event_form = EventForm(request.POST, instance=instance) repeat_form = RepeatOptionForm(request.POST, instance=repeat_instance) if event_form.is_valid(): event = event_form.save() if repeat_form.is_valid(): event.repeat = repeat_form.save() event.save() return redirect(overview) else: event_form = EventForm(instance=instance) repeat_form = RepeatOptionForm(instance=repeat_instance) return render(request, "calendar/form.html", {'title': _("Event"), 'event': instance, 'event_form': event_form, 'repeat_form': repeat_form, })
def plan_work(request, id, year=datetime.now().year, month=datetime.now().month): order = get_object_or_404(Order, id=id) if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): event = form.save() order.events.add(event) form = EventForm() cal = {} users = order.who_has_permission_to("VIEW") year = int(year) month = int(month) days_in_month = calendar.monthrange(year, month) for user in users: cal[user] = {} for day in range(1, days_in_month[1] + 1): cal[user][day] = [] for event in user.events.all(): for date in event.get_dates(): if date.year == year and date.month == month: cal[user][date.day].append(event) return render( request, "orders/plan_work.html", { 'order': order, 'title': _("Plan work"), 'form': form, 'cal': cal, 'days_in_month': range(1, days_in_month[1] + 1), 'current_month': (year, month), 'next_month_link': get_month_link("next", order, year, month), 'last_month_link': get_month_link("last", order, year, month) })
def plan_work(request, id, year=datetime.now().year, month=datetime.now().month): order = get_object_or_404(Order, id=id) if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): event = form.save() order.events.add(event) form = EventForm() cal = {} users = order.who_has_permission_to("VIEW") year = int(year) month = int(month) days_in_month = calendar.monthrange(year, month) for user in users: cal[user] = {} for day in range(1, days_in_month[1] + 1): cal[user][day] = [] for event in user.events.all(): for date in event.get_dates(): if date.year == year and date.month == month: cal[user][date.day].append(event) return render(request, "orders/plan_work.html", {'order': order, 'title': _("Plan work"), 'form': form, 'cal': cal, 'days_in_month': range(1, days_in_month[1] + 1), 'current_month': (year, month), 'next_month_link': get_month_link("next", order, year, month), 'last_month_link': get_month_link("last", order, year, month) })
def form(request, id=False): if id: instance = get_object_or_404(Event, id=id, deleted=False) msg = _("Successfully edited contact") else: instance = Event() msg = _("Successfully added new contact") repeat_instance = RepeatOption() if instance.repeat: repeat_instance = instance.repeat if request.method == 'POST': event_form = EventForm(request.POST, instance=instance) repeat_form = RepeatOptionForm(request.POST, instance=repeat_instance) if event_form.is_valid(): event = event_form.save() if repeat_form.is_valid(): event.repeat = repeat_form.save() event.save() return redirect(overview) else: event_form = EventForm(instance=instance) repeat_form = RepeatOptionForm(instance=repeat_instance) return render( request, "calendar/form.html", { 'title': _("Event"), 'event': instance, 'event_form': event_form, 'repeat_form': repeat_form, })