Beispiel #1
0
def add_event(request):
    if request.user.is_authenticated():
        current_user= request.user 
        if request.method == 'POST':
            event=Event(user=current_user)
                     
            event_form = AddEventForm(request.POST,request.FILES,instance=event)
            photo_form = AddPhotoForm(request.POST,request.FILES)
            add_tag_form=AddTagForm(request.POST)
            event=event_form.save(commit=False)
            event.user=current_user
            event.save()
            
            photos= photo_form.save(commit=False)
            photos.event =event
            photos.save()
            tags=request.POST.get('tags-name')
            tags=tags.split(",") 
            for tag in tags:
                tag= tag.replace(' ','')

                all_tags = EventTag.objects.filter(name=tag)
                if all_tags.count()==0:
                    a1 = EventTag(name=tag)
                    a1.save()
                    a1.event.add(event)

                else:
                    a1 = EventTag.objects.get(name=tag)
                    a1.event.add(event)
                    
            event_id=event.id
            site= 'http://%s%s' % (Site.objects.get_current().domain,
                               reverse('zpi_django.events.views.event_detail', kwargs={'event_id':event_id}))
    #        print site        
            return render_to_response("events/add_succesfull.html", {
                'message': 'Wydarzenie zostało dodane!','url':site
            }, context_instance=RequestContext(request))   
    
        else:
            event_form=AddEventForm()
            photo_form = AddPhotoForm()
            add_tag_form=AddTagForm(prefix='tags')
            return render_to_response('events/add_event_wizard.html', { 'add_event_form': event_form, 'add_photo_form':photo_form,
                                                                       'add_tag_form':add_tag_form},
                                      context_instance=RequestContext(request))
    else:
                        return render_to_response('auth/registration.html',
                                      context_instance=RequestContext(request))
Beispiel #2
0
def modify_event(request,event_id):
    event=Event.objects.get(id=event_id)
    e_id=event.id
    tagFormset=inlineformset_factory(Event,EventTag,can_delete=True,extra=1)       
    print event.place.location.x  
    if request.method == 'POST':
        eventform=AddEventForm(request.POST,request.FILES,instance=event)
        tagform=tagFormset(request.POST,instance=event)       
        eventform.save()
        tagform.save()

        
        print 'zmienione'
        url = reverse('zpi_django.events.views.event_detail', kwargs={'event_id': e_id})
        return HttpResponseRedirect(url)   
    else:
            eventform=AddEventForm(instance=event)
            tagform=tagFormset(instance=event)

            return render_to_response("events/edit_event.html", {'event':event,'add_event_form': eventform,'add_tag_form':tagform
                                                                      }, context_instance=RequestContext(request))