def event(request): if request.user is not None and str(request.user) != 'AnonymousUser': if request.method == "POST": ev = Event() form = EventForm(request.POST, instance=ev) if form.is_valid(): form.save() events = Event.objects.all() return render(request, "events.html", {"title": "Event", "records": events}) else: form = EventForm() return render(request, "create_event.html", {"form": form}) else: return redirect("/logout/")
def test_event_form_anon(django_user_model): user = django_user_model.objects.create(username='******') user.set_password('takeajacket') user.save() cult = Cult.objects.create( name='Sweet Dreams', slug='sweet-dreams', doctrine='Hold your head up, keep your head up!', city='Amsterdam', ) form_data = { 'title': 'Stayin alive', 'details': 'Whether you are a brother or whether you are a mother', 'date': '2018-02-02', 'time': '19:00', 'venue': 'Berghain', 'address': '123 Nowehere Strasse', 'maps_url': 'https://goo.gl/maps/here', } form = EventForm(data=form_data) assert form.is_valid() c = Client() logged_in = c.login(username='******', password='******') response = c.post('/' + cult.slug + '/new/', form_data) assert logged_in assert response.status_code == 403
def create_event(request): if request.method == 'POST': event_form = EventForm(request.POST) if event_form.is_valid(): event_form.save(request.user) return HttpResponseRedirect('/') else: return HttpResponseRedirect('/')
def add_event(request): if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): new_event = form.save(commit=False) new_event.organization = request.user new_event.event_name = request.POST.get('event_name') new_event.event_link = request.POST.get('event_link') new_event.event_start_date = request.POST.get('event_start_date') new_event.event_end_date = request.POST.get('event_end_date') new_event.event_start_time = request.POST.get('event_start_time') new_event.event_end_time = request.POST.get('event_end_time') new_event.slug = slugify(request.POST.get('event_name')) new_event.save() return redirect('main:events_list') else: form = EventForm() context = { 'form': form, } return render(request, 'admin/add_events.html', context=context)
def test_event_new_anon(django_user_model): cult = Cult.objects.create( name='Sweet Dreams', slug='sweet-dreams', doctrine='Hold your head up, keep your head up!', city='Amsterdam', ) form_data = { 'title': 'Stayin alive', 'details': 'Whether you are a brother or whether you are a mother', 'date': '2018-02-02', 'time': '19:00', 'venue': 'Berghain', 'address': '123 Nowehere Strasse', 'maps_url': 'https://goo.gl/maps/here', } form = EventForm(data=form_data) assert form.is_valid() c = Client() response = c.get('/' + cult.slug + '/new/') assert response.status_code == 302
def test_event_form(django_user_model): user = django_user_model.objects.create(username='******') user.set_password('takeajacket') user.save() cult = Cult.objects.create( name='Sweet Dreams', slug='sweet-dreams', doctrine='Hold your head up, keep your head up!', city='Amsterdam', ) Membership.objects.create( cult=cult, user=user, role=Membership.LEADER, ) form_data = { 'title': 'Stayin alive', 'details': 'Whether you are a brother or whether you are a mother', 'date': '2018-02-02', 'time': '19:00', 'venue': 'Berghain', 'address': '123 Nowehere Strasse', 'maps_url': 'https://goo.gl/maps/here', } form = EventForm(data=form_data) assert form.is_valid() c = Client() logged_in = c.login(username='******', password='******') response = c.post('/' + cult.slug + '/new/', form_data) assert logged_in assert response.status_code == 302 assert Event.objects.first() assert Event.objects.first().title == form_data['title'] assert Event.objects.first().details == form_data['details'] assert Event.objects.first().date.strftime('%Y-%m-%d') == form_data['date'] assert Event.objects.first().time.strftime('%H:%M') == form_data['time'] assert Event.objects.first().venue == form_data['venue'] assert Event.objects.first().address == form_data['address'] assert Event.objects.first().maps_url == form_data['maps_url']