def add_event(request): if request.method == 'GET': event_list = Event.objects.all() return render(request, 'admin/event-add.html', {'event_list': event_list}) validate_event = EventForm(request.POST) errors = {} if validate_event.is_valid(): if validate_event.cleaned_data[ 'end_date'] and validate_event.cleaned_data['start_date']: if validate_event.cleaned_data[ 'start_date'] > validate_event.cleaned_data['end_date']: errors[ 'date_err'] = 'Start Date should not greater than End Date' return JsonResponse(errors) if 'image' not in request.FILES: errors['image'] = 'Please upload Image' return JsonResponse(errors) new_event = validate_event.save(commit=False) new_event.image = request.FILES['image'] new_event.save() data = {"data": 'event created successfully', "error": False} return JsonResponse(data) for k in validate_event.errors: errors[k] = validate_event.errors[k][0] if 'image' not in request.FILES: errors['image'] = 'Please upload Image' return JsonResponse(errors)
def add_event(request): form = EventForm() if request.method == 'POST': form = EventForm(request.POST, request.FILES) if form.is_valid(): print(form.cleaned_data) event = Event( UserID=request.user, EventName=form.cleaned_data["EventName"], Description=form.cleaned_data["Description"], Address=form.cleaned_data["Address"], Picture=form.cleaned_data["Picture"], Longitude=form.cleaned_data["Longitude"], Latitude=form.cleaned_data["Latitude"], DateTime=form.cleaned_data["DateTime"], category=form.cleaned_data["CategoryList"], Rating=0, ) event.save() return redirect(reverse('events:index')) else: print(form.errors) return render(request, 'events/add_event.html', {'form': form})
def create(request): form = EventForm(request.POST or None) if form.is_valid(): event = form.save(commit=False) event.creator = request.user guessed_date = None for word in event.description.split(): try: guessed_date = parse(word) break except ValueError: continue event.start_date = guessed_date event.save() messages.success(request, "Your event was posted") if 'next' in request.POST: next = request.POST['next'] else: next = reverse('ev_tonight') return HttpResponseRedirect(next) return render_to_response( 'events/create.html', {'form':form}, context_instance = RequestContext(request) )
def create_tech_event(request): user = request.user if user.role_set.filter(id=1): if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] description = form.cleaned_data['description'] event_type = 1 user_id = request.user.id date = form.cleaned_data['date'] event = Event(user=request.user, name=name, description=description, type=event_type, date=date) event.save() return redirect('http://127.0.0.1:8000/custom_auth/profile/') else: return render(request, 'new_event.html', {'form': form}) else: form = EventForm() return render(request, "new_event.html", {'form': form}) else: return render(request, 'not_permitted.html')
def post(self, request): # Temporary part of the method to create tickets for test purposes if 'test_baseticket' in request.POST: response = create_test_baseticket() return response event_form = EventForm(request.POST) base_ticket_price_form = BaseTicketPriceForm(request.POST) upload_form = UploadBaseTicketNew(request.POST, request.FILES) if not(event_form.is_valid() and base_ticket_price_form.is_valid() and upload_form.is_valid()): return render(request, self.template_name, {'upload_form': upload_form, 'event_form': event_form, 'base_ticket_price_form': base_ticket_price_form, 'pdf_exists': 'false'}) # if the forms were valid pdf_file = request.FILES['pdf_file'] price = request.POST.get('price') pdf_object = ProcessBaseTicket(pdf_file) if not pdf_object.successful: messages.add_message(request, messages.ERROR, pdf_object.message) return render(request, self.template_name, {'upload_form': upload_form, 'event_form': event_form, 'base_ticket_price_form': base_ticket_price_form, 'pdf_exists': 'false'}) event = event_form.save() self.create_base_ticket(pdf_object, event, price) messages.add_message(request, messages.SUCCESS, message_text.event_creation_successful) return redirect('buy_ticket:available_tickets', event.id)
def create(request): form = EventForm(request.POST or None) if form.is_valid(): event = form.save(commit=False) event.creator = request.user g_d = None for word in event.description.split(): try: g_d = parse(word, fuzzy=True) break except : continue event.start_date = g_d event.save() #request.user.message_set.create(message="Event posted successfully.") if 'next' in request.POST: next = request.POST['next'] else: next = reverse('ev_tonight') return HttpResponseRedirect(next) else: return render_to_response( 'event/create.html', {'form':form}, context_instance = RequestContext(request) )
def eventView(request): events = Event.objects.all() try: event_id = request.GET['id'] Event.objects.filter(id=event_id).delete() except MultiValueDictKeyError: pass if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): name = request.POST['name'] venue = request.POST['venue'] date = request.POST['date'] time = request.POST['time'] new_event = Event(name=name, venue=venue, date=date, time=time) new_event.save() else: form = EventForm() context = { 'events': events, 'form': form, } return render(request, 'users/events.html', context)
def event_update(request, event_id): event_obj = get_object_or_404(Event, pk=event_id) if not (request.user.role == 'ADMIN' or request.user.is_superuser or event_obj.created_by == request.user or request.user in event_obj.assigned_to.all()): raise PermissionDenied if request.method == 'GET': context = {} context["event_obj"] = event_obj context["form"] = EventForm(instance=event_obj, request_user=request.user) selected_recurring_days = Event.objects.filter( name=event_obj.name).values_list('date_of_meeting', flat=True) selected_recurring_days = [ day.strftime('%A') for day in selected_recurring_days ] context['selected_recurring_days'] = selected_recurring_days return render(request, 'event_create.html', context) if request.method == 'POST': form = EventForm(request.POST, instance=event_obj, request_user=request.user) if form.is_valid(): start_date = form.cleaned_data.get('start_date') end_date = form.cleaned_data.get('end_date') # recurring_days # recurring_days = request.POST.getlist('days') if form.cleaned_data.get('event_type') == 'Non-Recurring': event = form.save(commit=False) event.date_of_meeting = start_date # event.created_by = request.user event.save() form.save_m2m() send_email.delay(event.id, domain=request.get_host(), protocol=request.scheme) if form.cleaned_data.get('event_type') == 'Recurring': event = form.save(commit=False) event.save() form.save_m2m() send_email.delay(event.id, domain=request.get_host(), protocol=request.scheme) # event.contacts.add(*request.POST.getlist('contacts')) # event.assigned_to.add(*request.POST.getlist('assigned_to')) return JsonResponse({ 'error': False, 'success_url': reverse('events:events_list') }) else: return JsonResponse({ 'error': True, 'errors': form.errors, })
def edit_event_view(request, event_pk): ''' The view to edit an event. ''' page_name = "Edit Event" profile = UserProfile.objects.get(user=request.user) event = get_object_or_404(Event, pk=event_pk) if event.owner != profile and not request.user.is_superuser: return HttpResponseRedirect( reverse('events:view', kwargs={"event_pk": event_pk}), ) event_form = EventForm( request.POST or None, profile=profile, instance=event, ) if event_form.is_valid(): event = event_form.save() messages.add_message( request, messages.SUCCESS, MESSAGES['EVENT_UPDATED'].format(event=event.title), ) return HttpResponseRedirect( reverse('events:view', kwargs={"event_pk": event_pk}), ) return render_to_response('edit_event.html', { 'page_name': page_name, 'event_form': event_form, }, context_instance=RequestContext(request))
def test_bookmark_invalid(self): '''invalid bookmark''' user = User.objects.create_user(username='******', email='*****@*****.**', password="******") event = Event.objects.create( name='bday', description='fun', tags='tag1, tag2, tag3', pub_date=timezone.now(), location="Bodos", event_date=timezone.now(), author=user.username, ) #ManytoMany to field is not a valid argument data = { 'name': event.name, 'description': event.description, 'event_date': event.event_date, 'location': event.location, 'invitees': event.invitees.all(), #querySets always need .all() 'tags': event.tags, } form = EventForm(data=data) self.assertTrue(form.is_valid()) return data
def VersionEvent(request, pk): # dictionary for initial data with # field names as keys context = {} # fetch the object related to passed id obj = get_object_or_404(Event, pk=pk) #obj.photo.delete() #obj.photo.open(mode='rb') # pass the object as instance in form form = EventForm(request.POST or None, instance=obj) # save the data from the form and # redirect to detail_view if form.is_valid(): obj.pk = int(round(time.time() * 1000)) #form.photo = request.POST.get('photo', False) #form.photo = request.FILES['photo'] form.instance.creator = request.user form.instance.record_status = "Created" form.save() return HttpResponseRedirect(reverse("events:all")) else: # add form dictionary to context context["form"] = form return render(request, "events/event_form.html", context)
def event_new(request, year): fair = get_object_or_404(Fair, year=year) react_props = {'question_types': dict(SignupQuestion.QUESTION_TYPES)} form = EventForm(request.POST or None) users = [ recruitment_application.user for recruitment_application in RecruitmentApplication.objects.filter( status='accepted', recruitment_period__fair=fair).order_by( 'user__first_name', 'user__last_name') ] form.fields['contact_person'].choices = [('', '---------')] + [ (user.pk, user.get_full_name()) for user in users if user.has_perm('companies.base') ] if request.POST and form.is_valid(): event = form.save() questions_data = json.loads(request.POST['questions']) save_questions(questions_data, event) return HttpResponse(status=200) return render(request, 'events/event_new.html', { 'fair': fair, 'form': form, 'react_props': react_props })
def add(request, app_label, model_name, id): ''' Tag an event to another model object ''' try: ct = ContentType.objects.get(\ app_label = app_label, model = model_name) obj = ct.get_object_for_this_type( id=id ) except: return HttpResponseNotFound() if request.method == 'POST': #request.POST.update( { 'owner':request.user.id, 'object_id':id, # 'content_type':ct.id, 'content_obj': obj, } ) form = EventForm(request.POST) if form.is_valid(): ev = form.save(commit=False) ev.owner = request.user ev.object_id = obj.id ev.content_type = ct ev.save() return HttpResponseRedirect(ev.get_absolute_url()) else: form = EventForm() context = { 'form':form, 'object':obj, 'content_type':ct, } context.update(locals()) return render_to_response('events/events_add.html', context,\ context_instance = RequestContext(request))
def event_update(request, event_uuid=None): event = get_object_or_404(Event, event_uuid=event_uuid) template_name = 'events/event_update.html' if request.method == 'POST': event_data = EventService.extract_event_data_from_form(request) if event_data: logger.debug("Event Update : Event date %s", event_data) event = EventService.event_update(event.pk, **event_data) messages.success(request, "The Event has been updated") return redirect('events:event-detail', event_uuid=event_uuid) else : form = EventForm(request.POST, instance=event) logger.debug("Event Update : Event data is None") messages.error(request, "The Event could not be updated. Please check your submitted form") else : form = EventForm(instance=event) context = { 'event': event, 'page_title': 'Event ' + event.name, 'form' : form } return render(request, template_name, context)
def create(request): form = EventForm(request.POST or None) if form.is_valid(): event = form.save(commit=False) event.creator = request.user guessed_date = None for word in event.description.split(): try: guessed_date = parse(word) break except ValueError: pass event.start_date = guessed_date event.save() messages.success(request, 'Your event was posted') if 'next' in request.POST: next = request.POST['next'] else: next = reverse('ev_tonight') return HttpResponseRedirect(next) return render_to_response( 'events/create.html', RequestContext(request, {'form':form}) )
def test_ready_must_have_date(): form_data = { 'title': 'wtf', 'status': 'r', } form = EventForm(data=form_data) assert not form.is_valid(), form.errors assert 'Un événement prêt doit avoir une date de début' in form.errors['__all__']
def test_only_title_and_state_required(user): form_data = { 'title': 'wtf', 'status': 'i', 'organizer': user, } form = EventForm(data=form_data) assert form.is_valid(), form.errors
def test_only_title_and_state_required(): form_data = { 'title': 'wtf', 'status': 'i', 'organizer': user, } form = EventForm(data=form_data) assert form.is_valid(), form.errors
def add(request): if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): event = form.save() return HttpResponseRedirect(reverse('event-edit', args=[event.id])+'?after_add=1') else: form = EventForm() return render_to_response('event_add.html', locals())
def event_create(request, template_name="events/event_form.html"): form = EventForm(request.POST or None) if form.is_valid(): event = form.save(commit=False) event.user = request.user event.save() return redirect("events:event_list") return render(request, template_name, {"form": form})
def test_stop_must_be_after_start(): form_data = { 'title': 'wtf', 'status': 'i', 'start': datetime(2100, 1, 1), 'stop': datetime(2000, 1, 1) } form = EventForm(data=form_data) assert not form.is_valid() assert 'La date de fin ne peut être avant la date de début' in form.errors['__all__']
def create_event(request): """ Creates an event. """ form = EventForm() if request.method == "POST": form = EventForm(request.POST,request.FILES) if form.is_valid(): event = form.save() return HttpResponseRedirect(reverse("event",args=(event.pk,))) return render_to_response("events/event_form.html",{"form":form},context_instance=RequestContext(request))
def test_event_form_valid(self): form = EventForm( data={ 'name': 'Party Outside', 'details': 'This party is gonna be banging again', 'venue': 'Mapo Hall', 'date': '2018-05-18', 'time': '12:25:00', 'category': 'category', }) self.assertTrue(form.is_valid())
def test_no_stop_but_start(): form_data = { 'title': 'wtf', 'status': 'i', 'start': datetime(2000, 1, 1), 'organizer': user, } form = EventForm(data=form_data) assert form.is_valid(), form.errors assert form.cleaned_data['start'] == form.cleaned_data['stop'] assert form.cleaned_data['start'].year == 2000
def add_event(request): if request.method == 'POST': form = EventForm(request.POST) event_data = form.data.dict() event_data.pop('csrfmiddlewaretoken') category = Category.objects.get(pk=event_data.pop('category')) Event.objects.create(host=request.user, category=category, **event_data) return HttpResponseRedirect(reverse('event_list')) form = EventForm() return render(request, 'events/add.html', {'form': form})
def test_no_stop_but_start(user): form_data = { 'title': 'wtf', 'status': 'i', 'start': datetime(2000, 1, 1), 'organizer': user, } form = EventForm(data=form_data) assert form.is_valid(), form.errors assert form.cleaned_data['start'] == form.cleaned_data['stop'] assert form.cleaned_data['start'].year == 2000
def test_event_form_invalid(self): form = EventForm( data={ 'name': '', 'details': '', 'venue': 'Mapo Hall', 'date': '2018-05-18', 'time': '12:25:00', 'category': 'category', 'creator': 'user' }) self.assertFalse(form.is_valid())
def extract_event_data_from_form(request): data = None if request.method == 'POST': postdata = request.POST.copy() form = EventForm(postdata) if form.is_valid(): data = form.cleaned_data else: logger.error("EventForm data is not valid") logger.error('EventForm Errors : %s\n', form.errors) logger.error('EventForm Non Field Errors : %s\n', form.non_field_errors) return data
def edit_event(request, id): if request.method == 'POST': event = get_object_or_404(Event, id=id) form = EventForm(request.POST, instance=event) if form.is_valid(): form.save(commit=False) event.save() return HttpResponseRedirect(event.get_absolute_url()) else: event = get_object_or_404(Event, id=id) form = EventForm(instance=event) return render_to_response('events/new_event.html', {'form': form, 'object': event}, context_instance=RequestContext(request))
def new_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 HttpResponseRedirect('/events') else: event = Event() form = EventForm(instance=event) return render_to_response('events/new_event.html', {'form': form}, context_instance=RequestContext(request))
def event_update(request, pk, template_name="events/event_form.html"): if request.user.is_superuser: event = get_object_or_404(Event, pk=pk) else: event = get_object_or_404(Event, pk=pk) form = EventForm(request.POST or None, instance=event) if form.is_valid(): form.save() return redirect(f"/events/{pk}") return render(request, template_name, {"form": form})
def test_invalid_form(self): '''Cannot have an location, thus form is not valid''' event = self.setup() data = { 'name': event.name, 'description': event.description, 'event_date': event.event_date, 'location': '', } form = EventForm(data=data) self.assertFalse(form.is_valid()) return data
def event_create(request): if request.method == 'POST': eventform = EventForm(request.POST) if eventform.is_valid(): eventform.save() else: eventform = EventForm() print eventform return render_to_response('events/event-create.html', {'eventform': eventform}, context_instance=RequestContext(request) )
def list_all_events_view(request): ''' A list view of all events. Part of archives. ''' page_name = "Archives - All Events" profile = UserProfile.objects.get(user=request.user) event_form = EventForm( request.POST if "post_event" in request.POST else None, profile=profile, ) if event_form.is_valid(): event_form.save() return HttpResponseRedirect(reverse('events:all')) # a pseudo-dictionary, actually a list with items of form (event, ongoing, # rsvpd, rsvp_form, already_past), where ongoing is a boolean of whether the # event is currently ongoing, rsvpd is a boolean of whether the user has # rsvp'd to the event events_dict = list() for event in Event.objects.all(): rsvp_form = None if event.end_time > now(): rsvp_form = RsvpForm( request.POST if "rsvp-{0}".format(event.pk) in request.POST else None, instance=event, profile=profile, ) if rsvp_form.is_valid(): rsvpd = rsvp_form.save() if rsvpd: message = MESSAGES['RSVP_ADD'].format(event=event.title) else: message = MESSAGES['RSVP_REMOVE'].format(event=event.title) messages.add_message(request, messages.SUCCESS, message) return HttpResponseRedirect(reverse('events:all')) ongoing = event.start_time <= now() and event.end_time >= now() rsvpd = profile in event.rsvps.all() events_dict.append( (event, ongoing, rsvpd, rsvp_form) ) if request.method == "POST": messages.add_message(request, messages.ERROR, MESSAGES["EVENT_ERROR"]) return render_to_response('list_events.html', { 'page_name': page_name, 'events_dict': events_dict, 'now': now(), 'event_form': event_form, }, context_instance=RequestContext(request))
def list_all_events_view(request): ''' A list view of all events. Part of archives. ''' page_name = "Archives - All Events" profile = UserProfile.objects.get(user=request.user) event_form = EventForm( request.POST if "post_event" in request.POST else None, profile=profile, ) if event_form.is_valid(): event_form.save() return HttpResponseRedirect(reverse('events:all')) # a pseudo-dictionary, actually a list with items of form (event, ongoing, # rsvpd, rsvp_form, already_past), where ongoing is a boolean of whether the # event is currently ongoing, rsvpd is a boolean of whether the user has # rsvp'd to the event events_dict = list() for event in Event.objects.all(): rsvp_form = None if event.end_time > now(): rsvp_form = RsvpForm( request.POST if "rsvp-{0}".format(event.pk) in request.POST else None, instance=event, profile=profile, ) if rsvp_form.is_valid(): rsvpd = rsvp_form.save() if rsvpd: message = MESSAGES['RSVP_ADD'].format(event=event.title) else: message = MESSAGES['RSVP_REMOVE'].format(event=event.title) messages.add_message(request, messages.SUCCESS, message) return HttpResponseRedirect(reverse('events:all')) ongoing = event.start_time <= now() and event.end_time >= now() rsvpd = profile in event.rsvps.all() events_dict.append((event, ongoing, rsvpd, rsvp_form)) if request.method == "POST": messages.add_message(request, messages.ERROR, MESSAGES["EVENT_ERROR"]) return render_to_response('list_events.html', { 'page_name': page_name, 'events_dict': events_dict, 'now': now(), 'event_form': event_form, }, context_instance=RequestContext(request))
def test_valid_form(self): '''Test valid form''' event = self.setup() data = { 'name': event.name, 'description': event.description, 'event_date': event.event_date, 'location': event.location, 'tags': event.tags, } form = EventForm(data=data) self.assertTrue(form.is_valid()) return data
def event_edit(request, year, pk): fair = get_object_or_404(Fair, year=year) event = get_object_or_404(Event, pk=pk, fair=fair) participants = Participant.objects.filter( event=event).select_related('user_s__profile').all() signup_questions = event.signupquestion_set.all() react_props = { 'questions': [ serializers.signup_question(question) for question in signup_questions ], 'question_types': dict(SignupQuestion.QUESTION_TYPES) } print(request.FILES) form = EventForm(request.POST or None, request.FILES or None, instance=event) users = [ recruitment_application.user for recruitment_application in RecruitmentApplication.objects.filter( status='accepted', recruitment_period__fair=event.fair).order_by( 'user__first_name', 'user__last_name') ] form.fields['contact_person'].choices = [('', '---------')] + [ (user.pk, user.get_full_name()) for user in users if user.has_perm('companies.base') ] if request.POST and form.is_valid(): form.save() questions_data = json.loads(request.POST['questions']) save_questions(questions_data, event) return HttpResponse(status=204) return render( request, 'events/event_edit.html', { 'fair': fair, 'event': event, 'participants': participants, 'questions': signup_questions, 'form': form, 'react_props': json.dumps(react_props) })
def edit_event(id): event = Event.query.filter_by(id=id).first() print(event) form = EventForm(obj=event) if form.validate_on_submit(): event.title = form.title.data event.description = form.description.data event.date_start = form.date_start.data event.time_start = form.time_start.data event.date_end = form.date_end.data event.time_end = form.time_end.data db.session.commit() return redirect(url_for('show_all_events')) return render_template("edit_event.html", form=form, event=event)
def create(request): """ Renders a form for creating a new ``Event`` instance, validates against that form, and creates the new instances. """ form = EventForm(request.POST or None) if form.is_valid(): event = form.save(commit=False) event.creator = request.user guessed_date = None # Ransack the description for possible datetime objects. If we find one # then we set start_date as that found datetime. for word in event.description.split(): try: guessed_date = parse(word) break except ValueError: continue event.start_date = guessed_date event.save() if 'next' in request.POST: next = request.POST['next'] else: next = reverse('ev_tonight') if request.is_ajax(): # If the request is AJAX, then render the created event and don't # create messages for the user. try: Attendance.objects.get(event=event, user=request.user) attending = True except Attendance.DoesNotExist: attending = False return render_to_response('events/event.html', {'event': event, 'request': request, 'attending': attending, 'authenticated': True, 'event_num': 1, 'next': next}) else: # If the request is not AJAX, then create messages for the user and # redirect them to the next page. request.user.message_set.create( message=_('Your event was posted.')) return HttpResponseRedirect(next) if request.is_ajax(): raise Http404 return render_to_response( 'events/create.html', {'form': form}, context_instance = RequestContext(request) )
def edit_event(request, pk: int): qs = Event.objects.filter(owner__email=request.user.email).prefetch_related('participants') event: Event = get_object_or_404(qs, pk=pk) context = { "title": f"Editing {event.name}", "email_formset_helper": EmailFormSetHelper() } if request.method == 'POST': email_formset = EmailFormSet(data=request.POST, prefix='emails') event_form = EventForm(instance=event, data=request.POST) if email_formset.is_valid() and event_form.is_valid(): updated_emails = [form["email"] for form in email_formset.cleaned_data if form and form["email"]] updated_participants = CustomUser.objects.all().filter(email__in=updated_emails) current_participants = event.participants.all() for participant in current_participants: if participant not in updated_participants: event.participants.remove(participant) for participant in updated_participants: if participant not in current_participants: event.participants.add(participant) event.save() return redirect('view_event', pk=pk) else: context["email_formset"] = email_formset context["event_form"] = event_form return render(request, 'events/edit_event.html', context=context) else: if event.status == Event.EventStatus.INACTIVE: event_form = EventForm(instance=event) emails = [user.email for user in event.participants.all()] initial = [{"email": email} for email in emails] email_form = EmailFormSet(initial=initial, prefix='emails') context["event_form"] = event_form context["email_formset"] = email_form return render(request, 'events/edit_event.html', context=context) else: return redirect('view_event', pk=pk)
def show_profile(request): form1 = AddSubCategory() form2 = AddCategory() edit_form1 = EditCategory() user = request.user print("is auth? {}".format(user.is_authenticated())) categories = Category.objects.all() allevents = Event.objects.all() if user.is_superuser: return render(request, 'admin_profile.html', {'user': user, 'profile_user': user, 'categories': categories, 'form1': form1, 'form2': form2, 'edit_form1': edit_form1, 'allevents': allevents}) try: customer = user.userinfo.customer orders = Order.objects.filter(customer=customer).all() return render(request, 'customer_profile.html', {'user': user, 'profile_user': customer, 'orders': orders, 'categories': categories}) except Customer.DoesNotExist: try: dealer = user.userinfo.dealer print("is auth dealer? {}".format(user.is_authenticated())) eventform = EventForm() return render(request, 'dealer_profile.html', {'user': user, 'profile_user': dealer, 'categories': categories, 'eventform': eventform, 'allevents': allevents}) except Dealer.DoesNotExist: print('no cases {}'.format(user))
def edit(request, id): instance = get(Event, pk=id) after_add = request.GET.get('after_add', None) pricing = instance.pricing_set.all() if request.method == 'POST': form = EventForm(request.POST, instance = instance) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('events')) else: form = EventForm(instance = instance) return render_to_response('event_edit.html', locals())
def add(request): if not request.user.is_staff: return HttpResponseForbidden() if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): # create and save new model event = form.save() return HttpResponseRedirect('/') else: form = EventForm() return render(request, 'events/add.html', { 'form': form, })
def index(request): if not request.user.is_authenticated: messages.error(request, 'Unauthorized. Must be logged in') return redirect('login') events = Event.objects.all().filter(is_hidden=False, user_id=request.user.id) events_data = [] json_events = serializers.serialize('python', events) for eventModel in json_events: eventModel['fields']['id'] = eventModel['pk'] eventModel['fields']['start_time'] = eventModel['fields'][ 'start_time'].strftime("%H:%M") eventModel['fields']['end_time'] = eventModel['fields'][ 'end_time'].strftime("%H:%M") eventModel['fields']['start_date'] = eventModel['fields'][ 'start_date'].strftime("%m/%d/%Y") if eventModel['fields']['end_date'] != None: eventModel['fields']['end_date'] = eventModel['fields'][ 'end_date'].strftime("%m/%d/%Y") events_data.append(eventModel['fields']) context = { 'events': events_data, 'form': EventForm(), } # Disable date field context['form'].fields['start_date'].widget.attrs['disabled'] = True context['form'].fields['end_date'].widget.attrs['disabled'] = True reminders.main(request.user.id) return render(request, 'calendar/calendar.html', context)
def events_new(request): if request.is_ajax(): render_target = '_form.html' else: render_target = 'new.html' if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): event = form.save(commit=False) event.host = request.user event.save() return redirect(event) else: form = EventForm(initial=request.GET.dict()) return render_to_response('events/%s' % render_target, {'form': form, 'editing': False}, context_instance=RequestContext(request))
def event_form(request, id=None): if id: instance = get_object_or_404(Event, id=id) else: instance = None if request.method == 'POST': form = EventForm(data=request.POST, instance=instance) if form.is_valid(): event = form.save(commit=False) event.user = request.user event.save() return HttpResponseRedirect(reverse('event_index')) else: form = EventForm(instance=instance) return render_to_response('events/form.html', {'form': form}, context_instance=RequestContext(request))
def add(request): if request.method == "GET": form = EventForm() elif request.method == "POST": form = EventForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('events.views.index')) c = RequestContext(request) c.update({ 'form': form, }) t = loader.get_template('events/add.html') return HttpResponse(t.render(c))
def add(request, app_label, model_name, id): ''' Tag an event to another model object ''' try: ct = ContentType.objects.get(\ app_label = app_label, model = model_name) obj = ct.get_object_for_this_type( id=id ) except: return HttpResponseNotFound() # visibility check if not helpers.is_visible(request.user, obj): return render_to_response('denied.html', context_instance=RequestContext(request)) if request.method == 'POST': #request.POST.update( { 'owner':request.user.id, 'object_id':id, # 'content_type':ct.id, 'content_obj': obj, } ) form = EventForm(request.POST) if form.is_valid(): ev = form.save(commit=False) ev.owner = request.user ev.object_id = obj.id ev.content_type = ct ev.save() #AFK edits #create and link ChampInfo object if one doesn't already exist if form.cleaned_data["champable"]: print "CHAMPCHAMPCHAMPCHAMPCHAMPCHAMPCHAMPCHAMPCHAMPCHAMPCHAMPable" if ChampInfo.objects.exists_by_event(event=ev) == False: ChampInfo.new(ev) #create a new ChampInfo object linked to an empty values owner print "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" return HttpResponseRedirect(ev.get_absolute_url()) else: form = EventForm() context = { 'form':form, 'object':obj, 'content_type':ct, } context.update(locals()) return render_to_response('events/events_add.html', context,\ context_instance = RequestContext(request))
def events_instance_edit(request, pk): event = Event.objects.get(pk=pk) if request.is_ajax(): render_target = '_form.html' else: render_target = 'edit.html' if request.method == 'POST': form = EventForm(request.POST, instance=event) if form.is_valid(): form.save(commit=False) return redirect(event) else: form = EventForm(instance=event) return render_to_response('events/%s' % render_target, {'object': event, 'form': form, 'editing': True}, context_instance=RequestContext(request))
def list_events_view(request): ''' A list view of upcoming events. ''' page_name = "Upcoming Events" profile = UserProfile.objects.get(user=request.user) event_form = EventForm( request.POST if 'post_event' in request.POST else None, profile=profile, ) now = datetime.datetime.utcnow().replace(tzinfo=utc) if event_form.is_valid(): event_form.save() return HttpResponseRedirect(reverse('events:list')) # a pseudo-dictionary, actually a list with items of form (event, ongoing, # rsvpd, rsvp_form), where ongoing is a boolean of whether the event is # currently ongoing, rsvpd is a boolean of whether the user has rsvp'd to # the event events_dict = list() for event in Event.objects.filter(end_time__gte=now): rsvp_form = RsvpForm( request.POST if "rsvp-{0}".format(event.pk) in request.POST else None, instance=event, profile=profile, ) if rsvp_form.is_valid(): rsvpd = rsvp_form.save() if rsvpd: message = MESSAGES['RSVP_ADD'].format(event=event.title) else: message = MESSAGES['RSVP_REMOVE'].format(event=event.title) messages.add_message(request, messages.SUCCESS, message) return HttpResponseRedirect(reverse('events:list')) ongoing = ((event.start_time <= now) and (event.end_time >= now)) rsvpd = (profile in event.rsvps.all()) events_dict.append((event, ongoing, rsvpd, rsvp_form)) return render_to_response('list_events.html', { 'page_name': page_name, 'events_dict': events_dict, 'now': now, 'event_form': event_form, }, context_instance=RequestContext(request))
def edit(request, object_id): try: event = Event.objects.get(pk=object_id) except Event.DoesNotExist: raise Http404() if request.method == "GET": form = EventForm(instance=event) elif request.method == "POST": form = EventForm(request.POST, instance=event) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('events.views.index')) c = RequestContext(request) c.update({ 'form': form, }) return render_to_response('events/add.html', context_instance=c)
def create(request): form = EventForm(request.POST or None) if form.is_valid(): event = form.save(commit=False) event.creator = request.user guessed_date = None for word in event.description.split(): try: guessed_date = parse(word) break except ValueError: continue event.start_date = guessed_date event.save() request.user.message_set.create(message="Your event has posted.") if "next" in request.POST: next = request.POST["next"] else: next = reverse("ev_tonight") return HttpResponseRedirect(next) return render_to_response("events/create.html", {"form": form}, context_instance=RequestContext(request))
def create_event(request, course_id): if request.method == 'POST': variables = _course_context(request, course_id) c = Course.objects.get(id=course_id) e = Event() e.creator = request.user form = EventForm(request.POST, request.FILES, instance=e) if form.is_valid(): e = form.save() c.add_event(e) e.join_event(request.user.id) c.save() wallPost = ConversationPost(creator=request.user, wall=c.wall, message="", post_type='E', event=e) wallPost.save() notifyCreateEvent(course=c, event=e) return redirect(course_events, course_id) else: variables['form'] = form variables.update(csrf(request)) return course(request, course_id, "Invalid event creation fields!!") return redirect(index)
def post(self, request, **kwargs): event_id = kwargs.get('event_id') obj = 'create' errors = {} status_code = 201 obj = 'edit' if event_id is not None: try: event = get_object_or_404(Event, pk=event_id) form = EventForm(request.POST, instance=event) event_data = form.instance.to_dict() except Http404: event_data = {} status_code = 404 errors = {'message': 'could not find event', 'code': status_code} return JsonResponse({ 'object': obj, 'url': request.get_full_path(), 'data': [event_data], 'errors': [errors], }, status=status_code) else: obj = 'create' form = EventForm(request.POST) if form.is_valid(): form.save() event_data = form.instance.to_dict() else: errors = form.errors.as_json() status_code = 400 return JsonResponse({ 'object': obj, 'url': request.get_full_path(), 'data': [event_data], 'errors': [errors], }, status=status_code)
def change(request, id): # visibility check event = get_object_or_404(Event, pk=id) parent = helpers.get_obj(ct=event.content_type, id=event.object_id) if not helpers.is_visible(request.user, parent): return render_to_response('denied.html', context_instance=RequestContext(request)) if request.method == 'POST': #request.POST.update( { 'owner':request.user.id, 'object_id':id, # 'content_type':ct.id, 'content_obj': obj, } ) form = EventForm(request.POST, instance=event) if form.is_valid(): ev = form.save() return HttpResponseRedirect(ev.get_absolute_url()) else: form = EventForm(instance=event) context = { 'form':form, 'object':parent, 'content_type':event.content_type } context.update(locals()) return render_to_response('events/events_add.html', context,\ context_instance = RequestContext(request))
def post(self, request, event_id): event = self.get_event(event_id) base_ticket = self.get_base_ticket(event_id) event_form = EventForm(request.POST, instance=event) base_ticket_price_form = BaseTicketPriceForm(request.POST, instance=base_ticket) upload_form = UploadBaseTicketEdit(request.POST, request.FILES) if not(event_form.is_valid() and base_ticket_price_form.is_valid() and upload_form.is_valid()): return render(request, self.template_name, {'upload_form': upload_form, 'event_form': event_form, 'base_ticket_price_form': base_ticket_price_form, 'base_ticket': base_ticket, 'event_id': event.id, 'pdf_exists': self.pdf_exists(event_id)}) # if forms are valid: pdf_file = self.get_pdf_file_or_None(request.FILES) if pdf_file: pdf_object = ProcessBaseTicket(pdf_file) if not pdf_object.successful: messages.add_message(request, messages.ERROR, pdf_object.message) return render(request, self.template_name, {'upload_form': upload_form, 'event_form': event_form, 'base_ticket_price_form': base_ticket_price_form, 'base_ticket': base_ticket, 'event_id': event.id, 'pdf_exists': self.pdf_exists(event_id)}) else: base_ticket.link = SavePDF.save_base_ticket_return_filepath(pdf_object, event_id) base_ticket.price = request.POST.get('price') base_ticket.save() event = event_form.save() messages.add_message(request, messages.SUCCESS, message_text.event_update_successful) return redirect('buy_ticket:available_tickets', event.id)