Esempio n. 1
0
def create_event(request):
    form = CreateEventForm(request.POST or None,request.FILES or None)
    if form.is_valid():
        event = form.save(commit=False)
        photo = PhotoModel()
        photo.image = form.cleaned_data['cover']
        photo.name = form.cleaned_data['name']
        desc = '%s cover photo' %(form.cleaned_data['name'])
        photo.desc = desc
        photo.save()
        event.cover = photo
        event.created_by = request.user.get_profile()
        try:
            event.club = form.cleaned_data['club']
            event.save()
        except:
            pass
        event=form.save_m2m()
        messages.success(request,'Created event successfully')
        return HttpResponseRedirect(reverse('event_main'))
    title = "Create Event"
    return_url = reverse('create_event')
    to_return={
        'form' : form,
        'title' : title,
        'return_url' : return_url,
        'button' : 'Create' ,
    }
    return render(request,'form1.html',to_return,context_instance=RequestContext(request))
Esempio n. 2
0
def editevent(event_id=None):
    event=Event.query.get_or_404(event_id)
    form = CreateEventForm(obj=event)
    if form.validate_on_submit():
        form.populate_obj(event)
        event.image=event.image.replace("https://www.dropbox.com","https://dl.dropboxusercontent.com/")
        db.session.add(event)
        db.session.commit()
        flash("Event edited succesfully")
        return redirect(url_for("admin.index"))
    return render_template('newevent.html',form=form)
Esempio n. 3
0
File: views.py Progetto: SunnyQ/cmu
def create_event(request, success_url=None,
        template_name='event/create_event.html'):
    if request.method == 'POST':
        form = CreateEventForm(data=request.POST)
        if form.is_valid():
            new_event = form.save(request.user)
            if success_url is None:
                success_url = reverse('view-event', kwargs={'event_id' : new_event.eid })
            return redirect(success_url)
    else:
        form = CreateEventForm()

    return render(request, template_name, {'form':form,})
Esempio n. 4
0
def create_post(request):
    current_user = request.user
    form = CreateEventForm(request.POST or None,
                           request.FILES or None,
                           user=current_user)
    if request.method == 'POST':
        if form.is_valid():
            post = form.instance
            post.author = current_user
            form.save()
    return render(request, "posts/post.html", {
        'form': form,
    })
Esempio n. 5
0
def create(request):
    if request.method == 'POST':
        # print request.POST.get('event_type')
        form = CreateEventForm(request.POST, request.FILES)
        if form.is_valid():
            event = form.save(commit=False)
            event.organizer = User.objects.get(pk=request.user.id)
            event.save()
            types = form.cleaned_data.get('event_type')
            if types:
                for type in types:
                    event.event_type.add(type)
            return redirect('ffx:event_detail', pk=event.event_id)
    else:
        form = CreateEventForm()

    event_types = EventType.objects.order_by('name')
    return render(request, 'events_create.html', {'form': form, 'event_types': event_types, 'is_organizer': request.user.groups.filter(name='organizers').exists()})
Esempio n. 6
0
def copyevent(event_id=None):
    new_event=Event()
    event=Event.query.get_or_404(event_id)
    new_event.title=event.title
    new_event.image=event.image
    new_event.description=event.description
    new_event.begin=event.begin
    new_event.end=event.end
    new_event.location=event.location
    new_event.price=event.price
    form = CreateEventForm(obj=new_event)
    if form.validate_on_submit():
        form.populate_obj(new_event)
        new_event.image=new_event.image.replace("https://www.dropbox.com","https://dl.dropboxusercontent.com/")
        db.session.add(new_event)
        db.session.commit()
        flash("Event edited succesfully")
        return redirect(url_for("admin.index"))
    return render_template('newevent.html',form=form)
Esempio n. 7
0
def create(request):
    if request.POST:
        new_data = request.POST.copy()
        event_form = CreateEventForm(new_data)
        if event_form.is_valid():
            #Create the event and save the values to it
            event = Event(owner=request.user)
            new_event_form = CreateEventForm(new_data,instance=event)
            new_event = new_event_form.save()
            return redirect(new_event)
        else:
            return render(request,'create_event.djhtml',
                       {'form':event_form,
                        'errors':event_form.errors})
    event_form = CreateEventForm()
    return render(request,'create_event.djhtml',
                       {'form':event_form})