@app.route('/place/add/', methods=['GET', 'POST'])
@app.route('/place/<int:event_id>/update/', methods=['GET', 'POST'], endpoint='event_update')
@auth.login_required
def event_create(event_id=0):
  if event_id == 0:
    event_db = model.Event(user_key=auth.current_user_key())
  else:
    event_db = model.Event.get_by_id(event_id)

  if not event_db or event_db.user_key != auth.current_user_key():
    return flask.abort(404)

  form = EventUpdateForm(obj=event_db)
  today = datetime.utcnow().date()
  today = datetime(today.year, today.month, today.day)
  form.year.choices = sorted([(str(y), y) for y in range(1900, today.year + 1)], reverse=True)

  if form.validate_on_submit():
    form.year.data = int(form.year.data)
    form.month.data = int(form.month.data)
    try:
      form.day.data = int(form.day.data)
    except:
      form.day.data = 1

    success = False

    if not form.year.data:
      form.timestamp.errors.append(_('You should at least enter a year'))
    else:
      month = 1
      day = 1

      if form.month.data and form.day.data:
        month = form.month.data
        day = form.day.data
      elif form.month.data:
        month = form.month.data
        day = 1
      else:
        month = 1
        day = 1

      hour = int(form.hour.data) or 0
      try:
        form.timestamp.data = datetime(form.year.data, month, day, hour)
        success = True
      except:
        form.timestamp.errors.append(_('Enter a valid date'))
        success = False

    if success:
      form.populate_obj(event_db)

      if form.month.data and form.day.data:
        event_db.accuracy = 'day'
      elif form.month.data:
        event_db.accuracy = 'month'
      else:
        event_db.accuracy = 'year'
      event_db.geo_pt = ndb.GeoPt(form.lat.data, form.lng.data)
      event_db.put()
      if event_id:
        flask.flash('"%s" is updated!' % event_db.address, category='success')
      else:
        flask.flash(event_db.address % '"%s" is added!', category='success')

      if form.add_more.data:
        timestamp = event_db.timestamp.strftime('%Y%H')
        if event_db.accuracy == 'month':
          timestamp = event_db.timestamp.strftime('%Y%m%H')
        if event_db.accuracy == 'day':
          timestamp = event_db.timestamp.strftime('%Y%m%d%H')

        return flask.redirect(flask.url_for('event_create', timestamp=timestamp))
      return flask.redirect('%s#%d' % (flask.url_for('trips'), event_db.key.id()))

  if not form.errors:
    form.add_more.data = event_id == 0
    form.lat.data = '0'
    form.lng.data = '0'

    if event_db.geo_pt:
      form.lat.data = event_db.geo_pt.lat
      form.lng.data = event_db.geo_pt.lon
    elif flask.request.city_lat_lng:
      form.lat.data = flask.request.city_lat_lng.split(',')[0]
      form.lng.data = flask.request.city_lat_lng.split(',')[1]

    try:
      if event_id == 0:
        timestamp = util.param('timestamp')
        form.year.data = timestamp[:4].lstrip('0')
        form.hour.data = timestamp[-2:].lstrip('0')
        if len(timestamp) == 8:
          form.month.data = timestamp[4:-2].lstrip('0')
        if len(timestamp) == 10:
          form.month.data = timestamp[4:-4].lstrip('0')
          form.day.data = timestamp[6:-2].lstrip('0')
      else:
        form.year.data = str(event_db.timestamp.year)
        if event_db.accuracy == 'month':
          form.month.data = str(event_db.timestamp.month)
        elif event_db.accuracy == 'day':
          form.month.data = str(event_db.timestamp.month)
          form.day.data = str(event_db.timestamp.day)
        form.hour.data = str(event_db.timestamp.hour)
    except:
      pass

  return flask.render_template(
      'event/event_update.html',
      html_class='event-update',
      title=u'%s' % (_('Add Place') if event_id == 0 else '%s, %s' % (event_db.place, event_db.country)),
      form=form,
      today=today,
      event_db=event_db,
    )
dataset/ETHPy150Open lipis/life-line/main/control/event.py/event_create/swapped operands of `%`