Ejemplo n.º 1
0
def get_busy(service, calendars):
  app.logger.debug("Entering list_busy")
  Set_range = model.calendar_event(flask.session['begin_date'], flask.session['end_date'])

  items = []
  keys = []

  body = {
      "timeMin": flask.session["begin_date"],
      "timeMax": flask.session["end_date"],
  }

  for calendar in calendars:
    if calendar['selected']:
      items.append({"id": calendar['id']})
      keys.append(calendar['id'])

  body["items"] = items
  
  app.logger.debug("Body is like " + str(body))

  busy_list = service.freebusy().query(body=body).execute()["calendars"]

  flask.flash("Showing busy time from %s to %s during the period of time." %(flask.session['begin_time'], flask.session['end_time']))
  results = []
  for key in keys:
    flash_result = Cal_id_2_summary[key] + ":{"
    for chunk in busy_list[key]['busy']:
      tmp_event = model.calendar_event(chunk['start'], chunk['end'])
      if tmp_event.compare_to(Set_range) == model.event_compare_result.within:
        flash_result += str(tmp_event)
    flash_result += '}'
    flask.flash(flash_result)
    results.append(busy_list[key]['busy'])
  return results
Ejemplo n.º 2
0
def get_busy(service, calendars):
    Set_range = get_range()
    DB.set_collection(flask.session["userid"])
    items = []
    keys = []

    body = {
        "timeMin": flask.session["begin_date"],
        "timeMax": flask.session["end_date"],
    }

    for calendar in calendars:
        if calendar['selected']:
            items.append({"id": calendar['id']})
            keys.append(calendar['id'])

    body["items"] = items

    app.logger.debug("Body is like " + str(body))

    busy_list = service.freebusy().query(body=body).execute()["calendars"]

    results = []
    for key in keys:
        for chunk in busy_list[key]['busy']:
            tmp_event = model.calendar_event(chunk['start'], chunk['end'])
            if tmp_event.compare_to(
                    Set_range) == model.event_compare_result.within:
                DB.insert(
                    model.record(chunk['start'], chunk['end'], None, None))
        results.append(busy_list[key]['busy'])

    return results
Ejemplo n.º 3
0
def test_without():

    test_case_start = now.shift(days=-1)
    test_case_end = test_case_start.shift(seconds=1)
    test_case = model.calendar_event(test_case_start, test_case_end)
    assert test_case.compare_to(RANGE) == model.event_compare_result.without

    test_case_start = now.shift(hours=-3)
    test_case_end = test_case_start.shift(hours=2)
    test_case = model.calendar_event(test_case_start, test_case_end)
    assert test_case.compare_to(RANGE) == model.event_compare_result.without

    test_case_start = then.shift(days=1)
    test_case_end = test_case_start.shift(hours=3)
    test_case = model.calendar_event(test_case_start, test_case_end)
    assert test_case.compare_to(RANGE) == model.event_compare_result.without

    for i in range(1000):
        test_case_start = now.shift(days=random.randrange(range_day))
        test_case_start = test_case_start.shift(
            hours=random.randrange(-(24 - range_hour), -1))
        test_case_end = test_case_start.shift(hours=1)

        test_case = model.calendar_event(test_case_start, test_case_end)
        logging.info(str(test_case))
        assert test_case.compare_to(
            RANGE) == model.event_compare_result.without
        logging.info("Passed.")

        test_case_start = then.shift(days=random.randrange(-range_day, 0))
        test_case_start = test_case_end.shift(
            hours=random.randrange(1, (24 - range_hour)))
        test_case_end = test_case_start.shift(hours=1)

        logging.info(str(test_case))
        assert test_case.compare_to(
            RANGE) == model.event_compare_result.without
        logging.info("Passed.")
Ejemplo n.º 4
0
def get_result():
    user_flash_result = "Checking free time among users: "
    Set_range = get_range()
    flask.g.users = []
    user_has_selected_or_default = flask.session.get("Checked_users", None)

    for collection in DB.all_user_collection():
        if "MeetingUser" in collection:
            flask.g.users.append(collection)
            if user_has_selected_or_default == None or collection in flask.session[
                    "Checked_users"]:
                user_flash_result += (collection + " ")
                DB.set_collection(collection)
                for event in DB.get_all():
                    test_record = model.record(None, None, event)
                    test_event = model.calendar_event(test_record.start,
                                                      test_record.end)
                    Set_range.blockage.append(test_event)

    flask.flash(user_flash_result)
    Set_range.subtract_blockage()
    flask.flash(str(Set_range))
Ejemplo n.º 5
0
def setrange():
  """
  User chose a date range with the bootstrap daterange
  widget.
  """
  app.logger.debug("Entering setrange")
  daterange = request.form.get('daterange')
  flask.session['daterange'] = daterange
  daterange_parts = daterange.split()

  begin_date = daterange_parts[0] + " " + flask.session['begin_time']
  end_date = daterange_parts[2] + " " + flask.session['end_time']

  flask.session['begin_date'] = interpret_date(begin_date)
  flask.session['end_date'] = interpret_date(end_date)
  Set_range = model.calendar_event(flask.session['begin_date'], flask.session['end_date'])

  app.logger.debug("Setrange parsed {} - {}  dates as {} - {}".format(
      begin_date, end_date,
      flask.session['begin_date'], flask.session['end_date']))

  return flask.redirect(flask.url_for("choose"))
Ejemplo n.º 6
0
import nose
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.WARNING)
log = logging.getLogger(__name__)

range_day = 7
range_hour = 8

now = arrow.now()

now_min = now.format("mm")
now_hour = int(now.format('HH'))
then = now.shift(days=range_day, hours=range_hour)

then_min = then.format("mm")
RANGE = model.calendar_event(now.isoformat(), then.isoformat())


def test_without():

    test_case_start = now.shift(days=-1)
    test_case_end = test_case_start.shift(seconds=1)
    test_case = model.calendar_event(test_case_start, test_case_end)
    assert test_case.compare_to(RANGE) == model.event_compare_result.without

    test_case_start = now.shift(hours=-3)
    test_case_end = test_case_start.shift(hours=2)
    test_case = model.calendar_event(test_case_start, test_case_end)
    assert test_case.compare_to(RANGE) == model.event_compare_result.without

    test_case_start = then.shift(days=1)