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))
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)
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')
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)
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})
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))
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))
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, })
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})
def add_or_edit_event(request, event_pk=None, is_add=False): user = request.user event = None if not is_add: event = get_object_or_404(Event, pk=event_pk) if event.is_expired(): user.message_set.create(message="You cannot edit an expired event.") return HttpResponseRedirect("/events/") if(not user == event.promoter): user.message_set.create(message="Only an event's promoter can edit it.") return HttpResponseRedirect(request.META.get('HTTP_REFERER', '')) if request.method == 'POST': if is_add: event = Event(promoter=user) elif event.promoter != user: return oops(request, "Only a event's promoter can edit it.") form = EventForm(request.POST, request.FILES) if form.is_valid(): event.name = form.cleaned_data['name'] if 'image' in request.FILES: file = request.FILES['image'] file_content = ContentFile(request.FILES['image'].read()) event.image.save(request.FILES['image'].name, file_content) event.start_date = form.cleaned_data['start_date'] event.end_date = form.cleaned_data['end_date'] event.description_markdown = form.cleaned_data['description'] event.rsvp_link = form.cleaned_data['rsvp_link'] tags = form.cleaned_data['tags'] event.save() event.set_tags(tags) return HttpResponseRedirect(event.get_absolute_url()) elif not is_add: form = EventForm(initial={ 'name':event.name, 'description':event.description_markdown, 'image':event.image, 'start_date':event.start_date, 'end_date':event.end_date, 'tags':event.get_editable_tags, 'rsvp_link':event.rsvp_link, }) else: form = EventForm() return render_to_response('add_or_edit_event.html', {'form': form, 'is_editing': not is_add, 'page_title': (is_add and "Add" or "Edit") + " an Event", 'event': event}, context_instance=RequestContext(request))
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))
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))
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)
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())
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})
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})
def create_event(request): if request.method == 'POST': form = EventForm(request.POST) # check whether it's valid: if form.is_valid(): f = form.cleaned_data event = Event(name=f['name']) event.save() return HttpResponse("Creado") else: event_form = EventForm() return render(request, 'core/create-event.html', {'event_form': event_form})
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'})
def handle_event(request): if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): request.session['arkistoija']['event'] = { 'name': form.cleaned_data['name'], 'date': form.cleaned_data['date'], } request.session.modified = True return HttpResponseRedirect('/arkistoija/p/2/') else: form = EventForm() return {'eventform': form}
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)
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, })
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)
def create_event(request, calendar_id): if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): calendar = get_object_or_404(Calendar, pk=calendar_id) datetime = form.cleaned_data['datetime'] name = form.cleaned_data['name'] tags = form.cleaned_data['tags'] event = Event.objects.create(calendar=calendar, datetime=datetime, name=name, tags=tags) event.save() return HttpResponseRedirect(reverse("view_calendar", args=[calendar.id])) else: return HttpResponse(form.errors) form = EventForm() return render(request, 'create_event.html', {'form': form, 'calendar_id': calendar_id})
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)
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'})
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, })
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')
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)
def calendar(request): family_member = get_family_member(request.user) if request.method == 'POST': event = None event_form = EventForm(request.POST, request.user) if event_form.is_valid(): cd = event_form.cleaned_data event = Event(name=cd["name"], description=cd["description"], location=cd["location"], timestamp=datetime.datetime.now(tz.gettz('America/New_York')), creator=request.user, startTime=cd["startTime"], endTime=cd["endTime"]) event.save() driver_from_id = request.POST['event[driverFrom]'] driver_to_id = request.POST['event[driverTo]'] creator = request.user children_going = request.POST.getlist('event[childrengoingID][]') adults_going = request.POST.getlist('event[adultsgoingID][]') event_details = FamilyEventDetails(event=event, family=family_member.family, notes=" ") event_details.save() try: driverTo = FamilyMember.objects.get(id=driver_to_id).user event_details.driverTo = driverTo event_details.save() except Exception, e: pass try: driverFrom = FamilyMember.objects.get(id=driver_from_id).user event_details.driverFrom = driverFrom event_details.save() except Exception, e: pass for child_id in children_going: try: child = Child.objects.get(id=child_id) event_details.child_attendees.add(child) except Exception, e: pass
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))
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, })
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} )
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, })
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]))
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")
def create_event(request): if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): event = Event( title=form.cleaned_data["title"], start_date=form.cleaned_data["start_date"], end_date=form.cleaned_data["end_date"], user=request.user, ) event.save() for url in request.POST.getlist("attach"): gal = Picture(event=event, url=url) gal.save() return HttpResponseRedirect("/home") else: form = EventForm() variables = RequestContext(request, {"form": form}) return render_to_response("event/event.html", variables)
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)
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())
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)
def addEvent(request): images = request.FILES.getlist('eventImages') eventForm = EventForm(request.POST or None) eventRuleForm = EventRuleForm(request.POST or None) addressForm = AddressForm(request.POST or None) contactForm = ContactForm(request.POST or None) if eventForm.is_valid() and eventRuleForm.is_valid( ) and addressForm.is_valid() and contactForm.is_valid(): event = eventService.createEvent(eventForm, eventRuleForm, addressForm, contactForm) if event: if (images): EventImage.createMultipleInstances(event, images) return redirect(reverse("superUser:event:index")) else: print(contactForm.errors, eventForm.errors, eventRuleForm.errors, addressForm.errors) return render( request, "add.html", { 'eventForm': eventForm, 'eventRuleForm': eventRuleForm, 'addressForm': addressForm, 'contactForm': contactForm })
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, })
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) })
def add(request): def submit_form(form): return render_to_response('add.html', {'form': form}, context_instance=RequestContext(request)) if request.method == 'GET': if not request.user.is_authenticated(): pass # Ask the user if the want to sign on data = {} if 'url' in request.GET: data.update({'url': request.GET['url']}) day = datetime.today() if 'day' in request.GET: if request.GET['day'] != "": day = request.GET[ 'day'] # Javascript hands you Tue May 20 1990 data.update({'date': day}) else: data.update({'date': day.strftime('%a %b %d %Y')}) else: data.update({'date': day.strftime('%a %b %d %Y')}) start_time = datetime.today() start_time = start_time.strftime('%H:%M') if 'start_time' in request.GET: if request.GET['start_time'] != '': start_time = request.GET['start_time'] data.update({'start_time': start_time}) if 'end_time' in request.GET: end_time = request.GET['end_time'] if end_time != 'null': data.update({'end_time': end_time}) data.update({'mail': 'outlook'}) form = EventForm(data) return submit_form(form) # Form was returned with data if request.method == 'POST': form = EventForm(request.POST) if not form.is_valid(): return submit_form(form) title = form.cleaned_data['title'] date = form.cleaned_data['date'] start_time = form.cleaned_data['start_time'] end_time = form.cleaned_data['end_time'] url = form.cleaned_data['url'] describe = form.cleaned_data['describe'] address = form.cleaned_data['address'] mail = form.cleaned_data['mail'] latitude = None longitude = None if address != u'': local = geocode(address) if local != None: if 'address' in local: address = local['address'] if 'latitude' in local and 'longitude' in local: latitude = local['latitude'] longitude = local['longitude'] # If they move the pointer to be more specific override address """ if form.data['lati'] and form.data['lngi']: latitude = form.data['lati'] longitude = form.data['lngi'] """ event = EventModel(title=title, date=date, start_time=start_time, end_time=end_time, address=address, longitude=longitude, latitude=latitude, description=describe, url=url) # Save this event event.save() # Make sure you save the event before connecting it to a user if request.user.is_authenticated(): event.connect(request.user) # Ical or Outlook iCal file if mail == 'outlook' or mail == 'ical': # Create the iCal file cal = Calendar() cal.add('version', '2.0') cal.add('prodid', '-//Microsoft Corporation//Windows Calendar 1.0//EN') cal.add('method', 'PUBLISH') event = Event() event.add('summary', describe) if start_time != None: dt = datetime.combine(date, start_time) else: dt = date event.add('dtstart', dt) event.add('dtstamp', dt) if end_time != None: de = datetime.combine(date, end_time) event.add('dtend', de) g = (latitude, latitude) event.add('geo', g) event.add('location', address) uid = date.isoformat() + '@wenzit.net' event.add('UID', uid) event.add('url', url) cal.add_component(event) f = open('schedule.ics', 'wb') f.write(cal.as_string()) f.close() response = HttpResponse(cal.as_string(), mimetype='text/calendar') response[ 'Content-Disposition'] = 'attachment; filename=schedule.ics' return response # Send the event to google elif mail == 'google': response = "http://www.google.com/calendar/event?action=TEMPLATE" response += "&text=" + urllib.quote_plus(title) if start_time != None: ds = datetime.combine(date, start_time) else: ds = date if end_time != None: de = datetime.combine(date, end_time) response += "&dates=" + vDatetime(ds).ical()+ \ '/'+vDatetime(de).ical() else: response += "&dates=" + vDatetime(ds).ical() response += "&details=" + urllib.quote_plus(title) response += "&location=" + urllib.quote_plus(address) response += "&sprop=" + urllib.quote_plus(url) return HttpResponseRedirect(response) # Send the event to Yahoo if mail == 'yahoo': response = 'http://calendar.yahoo.com/?v=60' response += '&TITLE=' + urllib.quote_plus(title) ds = datetime.combine(date, start_time) if end_time: de = datetime.combine(date, end_time) dur = de - ds hrs, left = divmod(dur.seconds, 3600) mins, secs = divmod(left, 60) dur = '%02d%02d' % (hrs, mins) else: dur = '' response += '&ST=' + vDatetime(ds).ical() response += '&DUR=' + dur response += '&in_loc=' + urllib.quote_plus(address) response += '&DESC=' + urllib.quote_plus(title) response += '&URL=' + urllib.quote_plus(url) return HttpResponseRedirect(response)