def post(request): # Like before, get the request's context. context = RequestContext(request) user=request.user # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. posted = False if request.method == 'POST': event = Events() event.title = request.POST['title'] event.brief_intro = request.POST['brief_intro'] event.organizer = request.POST['organizer'] event.contact_email = request.POST['contact_email'] event.contact_phonenumber = request.POST['contact_phonenumber'] event.capacity = request.POST['capacity'] event.age_limit = request.POST['age_limit'] event.ticket = request.POST['ticket'] event.description = request.POST['description'] event.starttime = request.POST['starttime'] event.endtime = request.POST['endtime'] event.music = bool(request.POST.get('isMusic')) event.sports = bool(request.POST.get('isSport')) event.food = bool(request.POST.get('isFood')) event.party = bool(request.POST.get('isParty')) event.arts = bool(request.POST.get('isArts')) event.busniess = bool(request.POST.get('isBusniess')) if 'poster' in request.FILES: event.poster = request.FILES['poster'] event.pubdate= timezone.now() event.updatedate= timezone.now() event.street_number = request.POST['street_number_'] event.street_name = request.POST['street_name_'] event.city_name = request.POST['city_name_'] event.province_name = request.POST['province_name_'] event.postal_code = request.POST['postal_code_'] event.country_name = request.POST['country_name_'] event.latitude = request.POST['latitude_'] event.longitude = request.POST['longitude_'] event.location = request.POST['location_'] event.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # Thi s delays saving the model until we're ready to avoid integrity problems. #user = get_object_or_404(UserProfile, pk=user.user_id) EventsCreater.objects.create(events=event,creater=user, createdate=timezone.now()) # Update our variable to tell the template registration was successful. posted = True from_zone = tz.gettz('UTC') to_zone = tz.gettz('America/Vancouver') _event = get_object_or_404(Events, pk=event.id) _starttime = _event.starttime #_starttime = datetime.datetime.strptime(_starttime, '%Y-%m-%dT%H:%M') #_starttime = _starttime.replace(tzinfo=from_zone) _localtime = _starttime.astimezone(to_zone) _endtime = _event.endtime #_endtime = datetime.datetime.strptime(_endtime, '%Y-%m-%dT%H:%M') _localtime2 = _endtime.astimezone(to_zone) subject = '[QuickActivity - Do Not Reply] You Have Posted an Activity!' message = 'Hi ' + user.username + ',\n\n' + 'You have successfully posted the activity ' + event.title +'. The starting time is ' + unicode(_localtime) + ', ending time is ' + unicode(_localtime2) + ', and the location is ' + event.location + '.\n\nYours,\nQuickActivity Team\n' try: send_mail(subject, message, '*****@*****.**', [user.email], fail_silently=True) except BadHeaderError: return HttpResponse('Invalid header found.') # Invalid form or forms - mistakes or somethi ng else? # Print problems to the terminal. # They'll also be shown to the user. #else: # print events_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. # Render the template depending on the context. return render_to_response( 'events/post.html', {'posted': posted}, context)
def post(request): # Like before, get the request's context. context = RequestContext(request) user = request.user # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. posted = False if request.method == 'POST': event = Events() event.title = request.POST['title'] event.brief_intro = request.POST['brief_intro'] event.organizer = request.POST['organizer'] event.contact_email = request.POST['contact_email'] event.contact_phonenumber = request.POST['contact_phonenumber'] event.capacity = request.POST['capacity'] event.age_limit = request.POST['age_limit'] event.ticket = request.POST['ticket'] event.description = request.POST['description'] event.starttime = request.POST['starttime'] event.endtime = request.POST['endtime'] event.music = bool(request.POST.get('isMusic')) event.sports = bool(request.POST.get('isSport')) event.food = bool(request.POST.get('isFood')) event.party = bool(request.POST.get('isParty')) event.arts = bool(request.POST.get('isArts')) event.busniess = bool(request.POST.get('isBusniess')) if 'poster' in request.FILES: event.poster = request.FILES['poster'] event.pubdate = timezone.now() event.updatedate = timezone.now() event.street_number = request.POST['street_number_'] event.street_name = request.POST['street_name_'] event.city_name = request.POST['city_name_'] event.province_name = request.POST['province_name_'] event.postal_code = request.POST['postal_code_'] event.country_name = request.POST['country_name_'] event.latitude = request.POST['latitude_'] event.longitude = request.POST['longitude_'] event.location = request.POST['location_'] event.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # Thi s delays saving the model until we're ready to avoid integrity problems. #user = get_object_or_404(UserProfile, pk=user.user_id) EventsCreater.objects.create(events=event, creater=user, createdate=timezone.now()) # Update our variable to tell the template registration was successful. posted = True from_zone = tz.gettz('UTC') to_zone = tz.gettz('America/Vancouver') _event = get_object_or_404(Events, pk=event.id) _starttime = _event.starttime #_starttime = datetime.datetime.strptime(_starttime, '%Y-%m-%dT%H:%M') #_starttime = _starttime.replace(tzinfo=from_zone) _localtime = _starttime.astimezone(to_zone) _endtime = _event.endtime #_endtime = datetime.datetime.strptime(_endtime, '%Y-%m-%dT%H:%M') _localtime2 = _endtime.astimezone(to_zone) subject = '[QuickActivity - Do Not Reply] You Have Posted an Activity!' message = 'Hi ' + user.username + ',\n\n' + 'You have successfully posted the activity ' + event.title + '. The starting time is ' + unicode( _localtime ) + ', ending time is ' + unicode( _localtime2 ) + ', and the location is ' + event.location + '.\n\nYours,\nQuickActivity Team\n' try: send_mail(subject, message, '*****@*****.**', [user.email], fail_silently=True) except BadHeaderError: return HttpResponse('Invalid header found.') # Invalid form or forms - mistakes or somethi ng else? # Print problems to the terminal. # They'll also be shown to the user. #else: # print events_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. # Render the template depending on the context. return render_to_response('events/post.html', {'posted': posted}, context)