def create_event(): event = EventModel() event.fk_userid = request.form.get('fk_userid') event.event_name = request.form.get('name') event.event_date = request.form.get('date') event.event_place = request.form.get('place') event.event_detail = request.form.get('detail') event.event_category = request.form.get('category') event.event_talent = request.form.get('talent') event.event_quota = request.form.get('quota') if 'file' not in request.files: flash('No File Part') return redirect(request.url) f = request.files['file'] if f.filename == '': flash('No selected file') if f: filename = secure_filename(f.filename) f.save(os.path.abspath("../image/" + filename)) event.event_image = request.host_url + 'image/' + filename event.save() ser_data = event_schema.dump(event).data return custom_response({'messages': 'success', 'event': ser_data}, 200)
def upload_file(): print(request.form) event = EventModel() event.fk_userid = request.form.get('fk_userid') event.event_name = request.form.get('name') event.event_date = request.form.get('date') event.event_place = request.form.get('place') event.event_detail = request.form.get('detail') event.event_category = request.form.get('category') event.event_talent = request.form.get('talent') event.event_quota = request.form.get('quota') if 'file' not in request.files: flash('No File Part') return redirect(request.url) f = request.files['file'] if f.filename == '': flash('No selected file') if f: filename = secure_filename(f.filename) f.save(filename) event.event_image = filename event.save() return 'susccess'
def addevent(): """ Adds a new event """ params = request.args or request.form try: geolocator = Nominatim(user_agent="confinapp-api") location = geolocator.geocode(params["address"]) try: longitude = location.longitude latitude = location.latitude except: return "{} is not valid adress.".format(params["address"]) event = EventModel(params["place"], params["address"], params["price"], params["date"], params["description"], params["typeid"], longitude, latitude, params["link"] if "link" in params else "NULL", params["number"] if "number" in params else "NULL", params["inside"] if "inside" in params else 1, params["available"] if "available" in params else 1, params["handicap"] if "handicap" in params else 1) event.save() return "New event saved." except: return "Error: one or more required parameters (place, address, price, date, description, typeid) were missing."
def post(self): data = request.get_json() if data == None: return {"success": "false"} for i in ['lat', 'lon', 'input_type']: if i not in data: return {'success': False} if 'image' in data: context = data['image'] score = get_image_score(context) if data['input_type'] == 'panic': score = 2 s = Poi.search() res = {"success": False} if score > 0.0: new_data = { 'location': str(data['lat']) + ',' + str(data['lon']), 'input_type': data['input_type'] } if 'image' in data: new_data['image'] = data['image'] event = EventModel(**new_data, created_at=datetime.now(), updated_at=datetime.now(), status="active") new_score = event.get_score_for_ifra() score = (score + new_score) / 2 event.score = score event.save() res = event.to_dict() res = {'id': event.meta.id} print(res) return res
def insert_event(): try: event = EventModel() posted_event = request.get_json() event.event_name = posted_event["event_name"] event.event_description = posted_event["event_description"] event.event_date = datetime.strptime(posted_event["event_date"][:10], "%Y-%m-%d") event.event_state = posted_event["event_state"] event.event_city = posted_event["event_city"] event.event_img = posted_event["event_img"] event.save() return jsonify(status="success") except Exception as e: traceback.print_exc() return jsonify(status="error", msg="Unknown error.")
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)
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)