Ejemplo n.º 1
0
def organize(request):
  if request.method == 'POST':
    form = EventForm(data=request.POST)
    if form.is_valid():
      event = form.save()
      event.start_time = datetime.time(form.cleaned_data['start_hours'], form.cleaned_data['start_minutes'])
      event.end_time = datetime.time(form.cleaned_data['end_hours'], form.cleaned_data['end_minutes'])
      event.organizer = request.user
      event.save()

      # Send a notification to the Slack channel.
      url = "%s/admin/web/event/%d/" % (Site.objects.get_current().domain, event.pk)
      try:
        send_new_event(url)
      except:
        for exc in sys.exc_info():
          print(exc)

      return redirect(reverse('index'))
    for error in form.errors:
      print(error)

  else:
    form = EventForm()

  return render(request, 'organize/organize.html', {
    'create_event_form': form,
    'login_form': LoginForm(),
  })
Ejemplo n.º 2
0
def organize(request):
  if request.method == 'POST':
    form = EventForm(data=request.POST)
    if form.is_valid() and request.user.is_authenticated():
      event = form.save(commit=False)
      event.start_time = datetime.time(form.cleaned_data['start_hours'], form.cleaned_data['start_minutes'])
      event.end_time = datetime.time(form.cleaned_data['end_hours'], form.cleaned_data['end_minutes'])

      if form.cleaned_data['signup_open_date']:
        time_string = "%s %s:%s" % (form.cleaned_data['signup_open_date'],
                                    form.cleaned_data['signup_open_hours'],
                                    form.cleaned_data['signup_open_minutes'])
        event.signup_open = datetime.datetime.strptime(time_string, '%Y-%m-%d %H:%M')

      event.organizer = request.user
      event.save()

      # Send a notification to the Slack channel.
      url = "%s/admin/web/event/%d/" % (Site.objects.get_current().domain, event.pk)
      try:
        send_new_event(url)
      except:
        for exc in sys.exc_info():
          print(exc)

      return redirect(reverse('index'))
    else:
      return HttpResponseServerError

  else:
    form = EventForm()

  return render(request, 'organize/organize.html', {
    'create_event_form': form,
    'login_form': LoginForm(),
  })