Пример #1
0
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
Пример #2
0
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('/')
Пример #3
0
def event_new(request):
    form = EventForm()
    if request.method == 'POST':
        form = EventForm(request.POST)
        
        if form.is_valid():
            event = form.save()
            return redirect('event', pk=event.pk)
        
    return render_to_response('pages/event.html', {
        'form': form
    }, RC(request))
Пример #4
0
def event_add(request):
    if request.method == "POST":
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.instance
            event.save()
            return HttpResponseRedirect( reverse( 'main.views.dance', args=(event.dance.id,) ) )
        
    else:
        form = EventForm()

    return render_to_response('main/event_add.html', {'form':form})
Пример #5
0
def event(request, pk):
    event = Event.objects.get(pk=pk)
    form = EventForm(instance=event)
    
    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            return redirect('event', pk=pk)
    
    return render_to_response('pages/event.html', {
        'form': form,
    }, RC(request))
Пример #6
0
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/")
Пример #7
0
def event_add(request, id):
    dance = Dance.objects.get(pk=id)

    if request.method == "POST":
        form = EventForm(request.POST)
        if form.is_valid():
            # figure out band
            band, band_created = Band.objects.get_or_create(name=form.cleaned_data['band'])
            # figure out caller
            caller, caller_created = Person.objects.get_or_create(name=form.cleaned_data['caller'])

            event = Event(date=form.cleaned_data['date'],band=band,caller=caller,dance=dance)
            event.save()
            return HttpResponseRedirect( reverse( 'main.views.dance', args=(event.dance.id,) ) )
        
    else:
        form = EventForm()

    return render_to_response('main/event_add.html', {'form':form,'dance':dance})
Пример #8
0
def events(request):
    context = {}
    user = user_to_fingr(request.user)
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():

            currTime = datetime.datetime.now()

            good = True
            #we need to do some hacky stuff and set the year, because otherwise it might do 1889 which is an error
            startTime = form.cleaned_data['timeStart']
            endTime = form.cleaned_data['timeEnd']
            startTime = startTime.replace(year=currTime.year)
            endTime = endTime.replace(year=currTime.year)

            #HOW DO I VALIDATE PROPERLY?
            if endTime <= startTime:
                errors = form._errors.setdefault("timeEnd", ErrorList())
                errors.append(u"End time must be after Start time")
                good = False
            if form.cleaned_data['date'] < currTime.date():
                errors = form._errors.setdefault("date", ErrorList())
                errors.append(u"Day must be today or in the future")
                good = False

            if good:
                event = Event(title=form.cleaned_data['title'], owner=user, date=form.cleaned_data['date'],
                              timeStart=startTime, timeEnd=endTime, description=form.cleaned_data['description']
                )
                event.save()
                notify_all_friends(user, "You have been invited to " + user.full_name + "'s event: " + event.title)

    else:
        form = EventForm()

    context['form'] = form

    context['userEvents'] = Event.objects.filter(owner=user)
    context['friendEvents'] = Event.objects.filter(owner__in=user.friends_list)

    return render(request, 'events.html', context)
Пример #9
0
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)
Пример #10
0
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
Пример #11
0
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']