Ejemplo n.º 1
0
def edit_event(request, event_id):
    event = Event.objects.get(id=event_id)
    form = EventForm(request.POST or None, instance=event)
    if form.is_valid():
        form.save()
        return view_event(request, event_id)
    return render(request, 'edit_event.html', {'form': form})
Ejemplo n.º 2
0
def createevent(request):
	#create form and enter into database
	if (request.user!=""):
		if request.method == 'POST':
			#print 'in request'
			#print request
			createevent_form=EventForm(request.POST,request.FILES)
			#print 'in request'
			print createevent_form
			if createevent_form.is_valid():
				print 'in request'
				createevent_form.save()
				return redirect('dashboard')
			#return render_to_response('wrongpage.html', {},{})
		else :
			
			s=User.objects.get(username=request.user)
			s1=Seek_User.objects.get(username=request.user)
			print s1.profilePhoto
			createevent_form={'createevent_form':EventForm({'username':request.user,'email':s.email,'status':'active','userid':s.id,'profilePhoto':s1.profilePhoto,'pubdate':timezone.now()})}
#			print createevent_form['createevent_form']
#			createevent_form['createevent_form'].update({'profilePhoto' = s1.profilePhoto})

			#createevent_form['createevent_form']['profilePhoto'] = s1.profilePhoto
			print createevent_form['createevent_form']['profilePhoto'].value()

			return render_to_response('CreateEvent.html',createevent_form,RequestContext(request))
	#return render_to_response('wrongpage.html', {},{})
	return HttpResponse('hello')
Ejemplo n.º 3
0
def add_event(request):
    if request.POST:
        form = EventForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Task added!')
            return HttpResponseRedirect('/events/')
    else:
        form = EventForm()

    return render(request, 'add.html', locals())
Ejemplo n.º 4
0
def edit(request, pk):
    template_name = 'events/edit.html'
    event = get_object_or_404(Event, pk=pk,
                              user=request.user)
    context = {}
    context['event'] = event
    if request.method == 'POST':
        form = EventForm(data=request.POST, instance=event)
        if form.is_valid():
            form.save()
            return redirect('events_my')
    else:
        form = EventForm(instance=event)
    context['form'] = form
    return render(request, template_name, context)
Ejemplo n.º 5
0
def create_event(request):
	# Returns false on empty
	if request.POST:
		form = EventForm(request.POST)
		if form.is_valid():
			form.save()
		return HttpResponseRedirect('')
	else:
		form = EventForm

	## Page Context Arguments
	args = {}
	args.update(csrf(request))
	args['form'] = form
	return render(request, 'img_upload/create_event.html', args)
Ejemplo n.º 6
0
def ajax_event_edit(request, pk):
	"""
	Ajax call to edit an event.
	
	@param pk: the event's pk
	@return (in JSON format):
		{error: error message} if there's been an error
		{html: form html} if GET request or there are errors in the form
		{success: true} if the form was successfully submitted
	"""
	return_data = None
	try:
		# get event to edit
		event_to_edit = Event.objects.get(pk=pk)
		# check if user allowed to edit event
		if event_to_edit.user != request.user.get_profile():
			raise Exception('You are not allowed to edit event %s.' % pk)
		
		# get form data
		form_data = None
		if request.method == 'POST':
			form_data = request.POST
		# create event form
		event_form = EventForm(user_profile=request.user.get_profile(),
							instance=event_to_edit, data=form_data)
		
		# check what to return
		if request.method == 'POST' and event_form.is_valid():
			event_form.save()
			
			return_data = simplejson.dumps({'success': True,})
		else:
			# create template context
			template_context = Context({
				'form': event_form,
				'submit_value': 'Save changes',
			})
			# add CSRF token to prevent errors from not using RequestContext
			template_context.update(csrf(request))
			# get the form's html
			form_html = get_template('sussedical/_form.djhtml').render(template_context)
			
			return_data = simplejson.dumps({'html': form_html,})
			
	except Exception as e:
		return_data = simplejson.dumps({'error': e.message,})
		
	return HttpResponse(return_data, mimetype='application/javascript')
Ejemplo n.º 7
0
def today(request):
    form = EventForm()
    today = get_begining(datetime.datetime.now())
    events = Event.objects.filter(author=request.user).filter(
            timestamp__gt=today)
    context = {
            'form': form,
            'events': events,
    }
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.author = request.user
            try:
                event.save()
                context['msgs'] = ['Event added successfully.',]
            except:
                context['msgs'] = ['Some error occured. Please enter \
                        valid data.',]
                context['form'] = form
        else:
            context['msgs'] = ['Error: You must enter a title.',]
            context['form'] = form
    return render_to_response('diary/today.html',
            RequestContext(request, context))
Ejemplo n.º 8
0
def event_edit(request, event_id, response_format='html'):
    "Event edit"

    event = get_object_or_404(Event, pk=event_id)
    if not request.user.profile.has_permission(event, mode='w'):
        return user_denied(request,
                           message="You don't have access to this Event")

    if request.POST:
        if 'cancel' not in request.POST:
            form = EventForm(request.user.profile,
                             None,
                             None,
                             request.POST,
                             instance=event)
            if form.is_valid():
                event = form.save()
                return HttpResponseRedirect(
                    reverse('events_event_view', args=[event.id]))
        else:
            return HttpResponseRedirect(reverse('events'))
    else:
        form = EventForm(request.user.profile, instance=event)

    return render_to_response('events/event_edit', {
        'event': event,
        'form': form
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 9
0
def today(request):
    form = EventForm()
    today = get_begining(datetime.datetime.now())
    events = Event.objects.filter(author=request.user).filter(
        timestamp__gt=today)
    context = {
        'form': form,
        'events': events,
    }
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.author = request.user
            try:
                event.save()
                context['msgs'] = [
                    'Event added successfully.',
                ]
            except:
                context['msgs'] = [
                    'Some error occured. Please enter \
                        valid data.',
                ]
                context['form'] = form
        else:
            context['msgs'] = [
                'Error: You must enter a title.',
            ]
            context['form'] = form
    return render_to_response('diary/today.html',
                              RequestContext(request, context))
Ejemplo n.º 10
0
def edit_event(request, event_name):
    try:
        event = Event.objects.get(name=event_name)
    except Event.DoesNotExist:
        raise Http404('Event does not exist')
    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if (form.is_valid()):
            e = form.save(commit=False)
            events = Event.objects.filter(name=e.name)
            # To allow editing the same event and keeping its short name.
            alreadyExists = False
            for ev in events:
                if ev != event:
                    alreadyExists = True
                    break
            if not alreadyExists:
                e.save()
                return redirect('feedback:index', e.name)
            messages.add_message(request, messages.WARNING,
                                 'Event with that short name already exists.')
    else:
        form = EventForm(instance=event)
    context = {
        'form': form,
        'event_name': event_name,
    }
    return render(request, 'feedback/edit_event.html', context)
Ejemplo n.º 11
0
def edit_event(request, event_name):
  try:
    event = Event.objects.get(name=event_name)
  except Event.DoesNotExist:
    raise Http404('Event does not exist')
  if request.method == 'POST':
    form = EventForm(request.POST, instance=event)
    if (form.is_valid()):
      e = form.save(commit=False)
      events = Event.objects.filter(name=e.name)
      # To allow editing the same event and keeping its short name.
      alreadyExists = False
      for ev in events:
        if ev != event:
          alreadyExists = True
          break
      if not alreadyExists:
        e.save()
        return redirect('feedback:index', e.name)
      messages.add_message(request, messages.WARNING, 'Event with that short name already exists.')
  else:
    form = EventForm(instance=event)
  context = {
      'form': form,
      'event_name': event_name,
  }
  return render(request, 'feedback/edit_event.html', context)
Ejemplo n.º 12
0
def create(request):
	if request.POST: 
		form = EventForm(request.POST, request.FILES)

		if form.is_valid():
			Event = form.save(commit=False)
			Event.author = request.user
			Event.pub_date = datetime.datetime.now()
			Event = Event.save()
			form.save_m2m()

			return HttpResponseRedirect(reverse('event.views.home'))

	else:
		form = EventForm()


	eighthour_advanced = datetime.datetime.now()+timedelta(hours=8)
	d = eighthour_advanced.strftime("%Y-%m-%d %H:%M")

	return render_to_response('create_event.html', 
														{'form': form,
														'organizations': Organization.objects.order_by('title'),
														'categories': Category.objects.order_by('title'),
														'users': User.objects.order_by('username'),
														'time2': d },
														context_instance = RequestContext(request))
Ejemplo n.º 13
0
def edit_event(request, slug):
    event = get_object_or_404(Event, slug=slug)

    if request.user.speaker not in event.speakers.all():
        return redirect('access')

    done = False
    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            done = True
    else:
        form = EventForm(instance=event)

    return render(request, 'access/edit_event.html',
            {'title': u"Editar: " + event.title, 'form': form, 'done': done} )
Ejemplo n.º 14
0
def create(request):
    if request.POST:
        form = EventForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/events')
    else:
        form = EventForm()
        
    args = {}
    args.update(csrf(request))

    args['form'] = form

    return render_to_response('form.html', 
                              args,
                              context_instance=RequestContext(request))
Ejemplo n.º 15
0
def create_event(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    if request.method == 'POST':
        event_form = EventForm(request.POST,
                               request.FILES,
                               prefix='event_form')

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':
                EventContentForm(request.POST,
                                 prefix='event_content' + lang[0]),
                'lang':
                lang[0]
            })
        if event_form.is_valid():
            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.library = library
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(
                        commit=False)
                    event_content.lang = event_content_form['lang']
                    event_content.event = event
                    event_content.save()
                event_form.save_m2m()
                return redirect(
                    'participant_events:administration:events_list',
                    library_code=library_code)
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':
                EventContentForm(prefix='event_content' + lang[0]),
                'lang':
                lang[0]
            })

    return render(
        request, 'participant_events/administration/create_event.html', {
            'library': library,
            'event_form': event_form,
            'event_content_forms': event_content_forms,
        })
Ejemplo n.º 16
0
def create(request):
    nav_selected = "events"
    form = EventForm(user=request.user, data=(request.POST or None))
    if form.is_valid():
        event = form.save()
        Record.objects.create_record(request.user, "event_create", event)
        messages.success(request, "%s has been created." % event)
        return redirect(event)
    return render_to_response("events/create.html", locals(), context_instance=RequestContext(request))
Ejemplo n.º 17
0
def edit_event(request, id):
	context = {}
	context['user'] = request.user
	context['event'] = get_object_or_404(Event, id=id)
	# Only the host of the event can edit (prevents url hacking)
	if context['user'].geolocuser != context['event'].host:
		raise Http404

	if request.method=="GET":
		context['form'] = EventForm(instance=context['event'])
		return render(request,'events/edit.html', context)

	form = EventForm(request.POST, request.FILES, instance=context['event'])
	if not form.is_valid():
		context['form'] = form
		return redirect(reverse('edit', args=[id]))
	form.save()
	return redirect(reverse('eventpage', args=[id]))
Ejemplo n.º 18
0
def create(request):
    if request.method == "POST":
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save()
            return HttpResponseRedirect('/agenda/%i/details/' % event.pk)
    else:
        form = EventForm()
    return render(request, 'personal_calendar/event/create.html', {'form': form})
Ejemplo n.º 19
0
def edit(request, event_id):
    nav_selected = "events"
    event = get_object_or_404(Event, id=event_id)
    form = EventForm(user=request.user, instance=event, data=(request.POST or None))
    if form.is_valid():
        event = form.save()
        messages.success(request, "%s has been changed." % event)
        return redirect(event)
    return render_to_response("events/edit.html", locals(), context_instance=RequestContext(request))
Ejemplo n.º 20
0
def add_event(request):
    if request.method == 'POST':
        event_form = EventForm(request.POST)
        if event_form.is_valid():
            event_form.save()
            return HttpResponseRedirect('/admin_forms/')
        else:
            degree_values = Degree.objects.values('name').distinct()
            news_form = NewsForm()
            directory_form = DirectoryForm()
            news = NewsArticle.objects.all()
            events = Event.objects.all()
            return render(request, 'admin_forms.html',
                          {'degree_values': degree_values, 'news_form': news_form, 'event_form': event_form,
                           'directory_form': directory_form, 'event_class': "active", 'all_news': news,
                           'all_events': events})

    else:
        return HttpResponseBadRequest("THE REQUESTED URL IS INVALID")
Ejemplo n.º 21
0
def create(request):
    data = {}
    data["user"] = request.user
    form = EventForm(request.POST or None)
    data["form"] = form
    if form.is_valid():
        obj = form.save(commit=False)  # get an unbound object
        obj.save()
        return HttpResponseRedirect("/event/%s" % obj.id)
    return render_to_response("event/create.html", data)
Ejemplo n.º 22
0
def new_event(request):
    from forms import EventForm
    if request.method == "POST":
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.save()
            return redirect('events', event.event_url)
    else:
        form = EventForm()
    return render(request, 'edit_event.html', {"form": form})
Ejemplo n.º 23
0
def add_event(request):
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.user = request.user
            event.save()

            return view_event(request, event.id)
    else:
        form = EventForm()
    return render(request, 'add_event.html', {'form': form})
Ejemplo n.º 24
0
def post_advert(request):
    logged_in =request.user.is_authenticated() # get login status
    if logged_in:
        form=EventForm()
        current_user=request.user
        this_advertiser= Advertiser.objects.get(user=current_user)
        if request.method == 'POST': # if user clicks submit button do...
            event_instance= Event(event_advertiser=this_advertiser,
                                  reminder_date=request.POST['event_date'],
                                  reminder_time=request.POST['event_time'])
            form=EventForm(request.POST,request.FILES,instance=event_instance)# get form field inputs
            
            if form.is_valid():
                form.save() # save in database
                return render_to_response("post_done.html",locals())
        else:
            return render_to_response("post_advert.html",locals())
    else:
        return HttpResponseRedirect('/utriga/reg/login/')
    
    return render_to_response("post_advert.html",locals())
Ejemplo n.º 25
0
def ajax_event_add(request):
	"""
	Ajax call to create a new event.
	
	@return (in JSON format):
		{error: error message} if there's been an error
		{html: form html} if GET request or there are errors in the form
		{success: true} if the form was successfully submitted
	"""
	return_data = None
	try:
		# get form data from POST (if available)
		form_data = None
		if request.method == 'POST':
			form_data = request.POST
		# create event form
		event_form = EventForm(user_profile=request.user.get_profile(), data=form_data)
		
		# check what to return
		if request.method == 'POST' and event_form.is_valid():
			event_form.save()
			
			return_data = simplejson.dumps({'success': True,})
		else:
			# create template context
			template_context = Context({
				'form': event_form,
				'submit_value': 'Create event',
			})
			# add CSRF token to prevent errors from not using RequestContext
			template_context.update(csrf(request))
			# get the form's html
			form_html = get_template('sussedical/_form.djhtml').render(template_context)
			
			return_data = simplejson.dumps({'html': form_html,})
			
	except Exception as e:
		return_data = simplejson.dumps({'error': e.message,})
		
	return HttpResponse(return_data, mimetype='application/javascript')
Ejemplo n.º 26
0
def create(request):
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save()
            inset_one(event)
            return HttpResponseRedirect(reverse('administration_events_index'))
    else:
        form = EventForm()

    return render(request, 'events/administration/events_create.html',
                              {'form': form,
                               'active_module': 'events'})
Ejemplo n.º 27
0
def sendmail(request):
	#need the event at which the user clicked
	if (request.user!=""):
		if request.method == 'POST':
			createevent_form=EventForm(request.POST,request.FILES)
			#print 'in request'
			if createevent_form.is_valid():
				#print 'in request'
				createevent_form.save()
				s=""
				s=s+createevent_form.cleaned_data.get('username')+' ('+createevent_form.cleaned_data.get('email')+') '
				print s
				send_mail(s, s,'*****@*****.**', ['*****@*****.**'])
				
				return redirect('done')
			return render_to_response('wrongpage.html', {},{})
		else :
			
			s=Seek_User.objects.get(username=request.user)
			createevent_form={'createevent_form':EventForm({'username':request.user,'email':s.email,'status':'active','userid':s.id,'profilePhoto':s.profilePhoto,'pubdate':timezone.now()})}
			return render_to_response('CreateEvent.html',createevent_form,RequestContext(request))

	return render_to_response('wrongpage.html', {},{})
Ejemplo n.º 28
0
def edit(request, event_id):
    event = get_object_or_404(Event, id=event_id)
    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            event = form.save()
            inset_one(event)
            return HttpResponseRedirect(reverse('administration_events_index'))
    else:

        form = EventForm(model_to_dict(event),instance=event)
    return render(request, 'events/administration/events_edit.html',
                              {'form': form,
                               'event':event,
                               'active_module': 'events'})
Ejemplo n.º 29
0
def main_list_event(request):
    e_list = Event.objects.all()
    if request.method == 'POST':
        e_form = EventForm(request.POST)
        if e_form.is_valid():
            event_data = e_form.save(commit=False)
            event_data.user = request.user
            event_data.save()            
    else:
        e_form = EventForm()

    return render(request, 'event-list-block.html', {
        'e_list': e_list,
        'e_form': e_form,
    })
Ejemplo n.º 30
0
def create(request):
    template_name = 'events/create.html'
    context = {}
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.user = request.user
            event.save()
            next_url = event.get_absolute_url()
            return HttpResponseRedirect(next_url)
    else:
        form = EventForm()
    context['form'] = form
    return render(request, template_name, context)
Ejemplo n.º 31
0
def create_event(request):

    if request.method == 'POST':
        event_form = EventForm(request.POST, prefix='event_form')

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':
                EventContentForm(request.POST,
                                 prefix='event_content' + lang[0]),
                'lang':
                lang[0]
            })

        if event_form.is_valid():

            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(
                        commit=False)
                    event_content.lang = event_content_form['lang']
                    event_content.event = event
                    event_content.save()
                return redirect('events:administration:events_list')
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':
                EventContentForm(prefix='event_content' + lang[0]),
                'lang':
                lang[0]
            })

    return render(request, 'events/administration/create_event.html', {
        'event_form': event_form,
        'event_content_forms': event_content_forms,
    })
Ejemplo n.º 32
0
def create_event(request):
  event = Event()
  if request.method == 'POST':
    form = EventForm(request.POST, instance=event)
    if (form.is_valid()):
      e = form.save(commit=False)
      if not Event.objects.filter(name=e.name).exists():
        e.save()
        return redirect('feedback:index', e.name)
      messages.add_message(request, messages.WARNING, 'Event with that short name already exists.')
  else:
    form = EventForm(instance=event)
  context = {
      'form': form,
  }
  return render(request, 'feedback/create_event.html', context)
Ejemplo n.º 33
0
def create_event(request, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации')

    if request.method == 'POST':
        event_form = EventForm(request.POST, request.FILES, prefix='event_form')

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form': EventContentForm(request.POST, prefix='event_content' + lang[0]),
                'lang': lang[0]
            })
        if event_form.is_valid():
            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.library = library
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(commit=False)
                    event_content.lang = event_content_form['lang']
                    event_content.event = event
                    event_content.save()
                event_form.save_m2m()
                return redirect('participant_events:administration:events_list', library_code=library_code)
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form': EventContentForm(prefix='event_content' + lang[0]),
                'lang': lang[0]
            })

    return render(request, 'participant_events/administration/create_event.html', {
        'library': library,
        'event_form': event_form,
        'event_content_forms': event_content_forms,
    })
Ejemplo n.º 34
0
def create_event(request):
    event = Event()
    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if (form.is_valid()):
            e = form.save(commit=False)
            if not Event.objects.filter(name=e.name).exists():
                e.save()
                return redirect('feedback:index', e.name)
            messages.add_message(request, messages.WARNING,
                                 'Event with that short name already exists.')
    else:
        form = EventForm(instance=event)
    context = {
        'form': form,
    }
    return render(request, 'feedback/create_event.html', context)
Ejemplo n.º 35
0
def create_event(request):

    if request.method == 'POST':
        event_form = EventForm(request.POST,prefix='event_form')

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form':EventContentForm(request.POST,prefix='event_content' + lang[0]),
                'lang':lang[0]
            })

        if event_form.is_valid():



            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                print valid
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(commit=False)
                    event_content.lang = event_content_form['lang']
                    event_content.event = event
                    event_content.save()
                return redirect('events:administration:events_list')
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({
                'form': EventContentForm(prefix='event_content' + lang[0]),
                'lang': lang[0]
            })

    return render(request, 'events/administration/create_event.html', {
        'event_form': event_form,
        'event_content_forms': event_content_forms,
    })
Ejemplo n.º 36
0
def event_add(request, date=None, hour=12, response_format='html'):
    "Event add form"

    if request.POST:
        if 'cancel' not in request.POST:
            event = Event()
            form = EventForm(
                request.user.profile, date, hour, request.POST, instance=event)
            if form.is_valid():
                event = form.save()
                event.set_user_from_request(request)
                return HttpResponseRedirect(reverse('events_event_view', args=[event.id]))
        else:
            return HttpResponseRedirect(reverse('events'))
    else:
        form = EventForm(request.user.profile, date, hour)

    return render_to_response('events/event_add',
                              {'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 37
0
def create_event(request):
    if request.method == "POST":
        event_form = EventForm(request.POST, prefix="event_form")

        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append(
                {"form": EventContentForm(request.POST, prefix="event_content" + lang[0]), "lang": lang[0]}
            )

        if event_form.is_valid():

            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form["form"].is_valid()
                print valid
                if not valid:
                    break

            if valid:
                event = event_form.save(commit=False)
                event.save()
                for event_content_form in event_content_forms:
                    event_content = event_content_form["form"].save(commit=False)
                    event_content.lang = event_content_form["lang"]
                    event_content.event = event
                    event_content.save()
                return redirect("events:administration:events_list")
    else:
        event_form = EventForm(prefix="event_form")
        event_content_forms = []
        for lang in settings.LANGUAGES:
            event_content_forms.append({"form": EventContentForm(prefix="event_content" + lang[0]), "lang": lang[0]})

    return render(
        request,
        "events/administration/create_event.html",
        {"event_form": event_form, "event_content_forms": event_content_forms},
    )
Ejemplo n.º 38
0
def eventForm(request, patient_id):
    a = Patient.objects.get(id=patient_id)

    if request.method == "POST":
        f = EventForm(request.POST)
        if f.is_valid():
            c = f.save(commit=False)
            c.created_by_id = request.user.id

            c.patient = a
            c.save()
            #takes user back to patient profile
            return HttpResponseRedirect('/patient/get/%s' % patient_id)
    else:
        f = EventForm()

    args = {}
    args.update(csrf(request))

    args['patient'] = a
    args['form'] = f

    return render(request, 'event_form.html', args)
Ejemplo n.º 39
0
def event_edit(request, event_id, response_format='html'):
    "Event edit"

    event = get_object_or_404(Event, pk=event_id)
    if not request.user.profile.has_permission(event, mode='w'):
        return user_denied(request, message="You don't have access to this Event")

    if request.POST:
        if 'cancel' not in request.POST:
            form = EventForm(
                request.user.profile, None, None, request.POST, instance=event)
            if form.is_valid():
                event = form.save()
                return HttpResponseRedirect(reverse('events_event_view', args=[event.id]))
        else:
            return HttpResponseRedirect(reverse('events'))
    else:
        form = EventForm(request.user.profile, instance=event)

    return render_to_response('events/event_edit',
                              {'event': event,
                               'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 40
0
def event_add(request, date=None, hour=12, response_format='html'):
    "Event add form"

    if request.POST:
        if 'cancel' not in request.POST:
            event = Event()
            form = EventForm(request.user.profile,
                             date,
                             hour,
                             request.POST,
                             instance=event)
            if form.is_valid():
                event = form.save()
                event.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('events_event_view', args=[event.id]))
        else:
            return HttpResponseRedirect(reverse('events'))
    else:
        form = EventForm(request.user.profile, date, hour)

    return render_to_response('events/event_add', {'form': form},
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 41
0
def edit_event(request, id):
    event = get_object_or_404(Event, id=id)
    event_contents = EventContent.objects.filter(event=event)
    event_contents_langs = {}

    for lang in settings.LANGUAGES:
        event_contents_langs[lang] = None

    for event_content in event_contents:
        event_contents_langs[event_content.lang] = event_content

    if request.method == 'POST':
        event_form = EventForm(request.POST,
                               prefix='event_form',
                               instance=event)

        if event_form.is_valid():
            event_form.save()
            event_content_forms = []
            for lang in settings.LANGUAGES:
                if lang in event_contents_langs:
                    lang = lang[0]
                    if lang in event_contents_langs:
                        event_content_forms.append({
                            'form':
                            EventContentForm(
                                request.POST,
                                prefix='event_content_' + lang,
                                instance=event_contents_langs[lang]),
                            'lang':
                            lang
                        })
                    else:
                        event_content_forms.append({
                            'form':
                            EventContentForm(request.POST,
                                             prefix='event_content_' + lang),
                            'lang':
                            lang
                        })

            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(
                        commit=False)
                    event_content.event = event
                    event_content.lang = event_content_form['lang']
                    event_content.save()

                return redirect('events:administration:events_list')
    else:
        event_form = EventForm(prefix="event_form", instance=event)
        event_content_forms = []
        for lang in settings.LANGUAGES:
            lang = lang[0]
            if lang in event_contents_langs:
                event_content_forms.append({
                    'form':
                    EventContentForm(prefix='event_content_' + lang,
                                     instance=event_contents_langs[lang]),
                    'lang':
                    lang
                })
            else:
                event_content_forms.append({
                    'form':
                    EventContentForm(prefix='event_content_' + lang),
                    'lang':
                    lang
                })

    return render(request, 'events/administration/edit_event.html', {
        'event_form': event_form,
        'event_content_forms': event_content_forms,
    })
Ejemplo n.º 42
0
def edit_event(request, id, library_code, managed_libraries=[]):
    library = org_utils.get_library(library_code, managed_libraries)
    if not library:
        return HttpResponseForbidden(
            u'Вы должны быть сотрудником этой организации')

    event = get_object_or_404(Event, id=id)
    event_contents = EventContent.objects.filter(event=event)
    event_contents_langs = {}

    for lang in settings.LANGUAGES:
        event_contents_langs[lang] = None

    for event_content in event_contents:
        event_contents_langs[event_content.lang] = event_content

    if request.method == 'POST':
        event_form = EventForm(request.POST,
                               request.FILES,
                               prefix='event_form',
                               instance=event)
        event_content_forms = []
        if event_form.is_valid():
            event_form.save()
            event_content_forms = []
            for lang in settings.LANGUAGES:
                if lang in event_contents_langs:
                    lang = lang[0]
                    if lang in event_contents_langs:
                        event_content_forms.append({
                            'form':
                            EventContentForm(
                                request.POST,
                                prefix='event_content_' + lang,
                                instance=event_contents_langs[lang]),
                            'lang':
                            lang
                        })
                    else:
                        event_content_forms.append({
                            'form':
                            EventContentForm(request.POST,
                                             prefix='event_content_' + lang),
                            'lang':
                            lang
                        })

            valid = False
            for event_content_form in event_content_forms:
                valid = event_content_form['form'].is_valid()
                if not valid:
                    break

            if valid:
                for event_content_form in event_content_forms:
                    event_content = event_content_form['form'].save(
                        commit=False)
                    event_content.event = event
                    event_content.lang = event_content_form['lang']
                    event_content.save()
                return redirect(
                    'participant_events:administration:events_list',
                    library_code=library_code)
    else:
        event_form = EventForm(prefix="event_form", instance=event)
        event_content_forms = []
        for lang in settings.LANGUAGES:
            lang = lang[0]
            if lang in event_contents_langs:
                event_content_forms.append({
                    'form':
                    EventContentForm(prefix='event_content_' + lang,
                                     instance=event_contents_langs[lang]),
                    'lang':
                    lang
                })
            else:
                event_content_forms.append({
                    'form':
                    EventContentForm(prefix='event_content_' + lang),
                    'lang':
                    lang
                })

    return render(
        request, 'participant_events/administration/edit_event.html', {
            'event': event,
            'library': library,
            'event_form': event_form,
            'event_content_forms': event_content_forms,
            'content_type': 'participant_events_' + str(library.id),
            'content_id': unicode(event.id)
        })