コード例 #1
0
def edit_idea(connection, slug, short_summary, long_summary):
    error = ""
    if not short_summary or len(short_summary) == 0:
        return (False, "Short summary is blank.")

    if not long_summary or len(long_summary) == 0:
        return (False, "Long summary is blank.")

    user = get_user()['user']

    if not user:
        return (False, "User not logged in.")

    key = _get_summary_str(slug)
    summary = connection.get(key)

    if not summary:
        return (False, "A post with that slug does not exist.")

    if summary['created_by'] != user['username'] and user['admin'] != True:
        return (False, "This isn't your post to edit.")

    summary['short_summary'] = short_summary
    summary['long_summary'] = long_summary

    connection.set(key, summary)

    return (True, summary)
コード例 #2
0
ファイル: utils.py プロジェクト: kyleterry/metaforcefeed
def edit_idea(connection, slug, short_summary, long_summary):
    error = ""
    if not short_summary or len(short_summary) == 0:
        return (False, "Short summary is blank.")

    if not long_summary or len(long_summary) == 0:
        return (False, "Long summary is blank.")

    user = get_user()['user']

    if not user:
        return (False, "User not logged in.")

    key = _get_summary_str(slug)
    summary = connection.get(key)

    if not summary:
        return (False, "A post with that slug does not exist.")

    if summary['created_by'] != user['username'] and user['admin'] != True:
        return (False, "This isn't your post to edit.")

    summary['short_summary'] = short_summary
    summary['long_summary'] = long_summary

    connection.set(key, summary)

    return (True, summary)
コード例 #3
0
ファイル: utils.py プロジェクト: qpfiffer/metaforcefeed
def submit_event(connection, day, from_time, to_time, name, description):
    from datetime import datetime
    error = ""
    if not day or len(day) == 0:
        return (False, "Day is blank.")

    if not name or len(name) == 0:
        return (False, "Name is blank.")

    user = get_user()["user"]

    if not user:
        return (False, "User not logged in.")

    converted_date = None
    try:
        converted_date = datetime.strptime(day, "%Y-%m-%d")
    except ValueError:
        return (False, "Date invalid. Should be of the form 'YYYY-MM-DD'.")

    slug = slugify(name)[:SLUG_SIZE]
    stamp = timegm(converted_date.timetuple())
    key = _get_event_str(slug, stamp)

    exists = connection.has_key(key)
    if exists:
        return (False, "An event with that name on that day already exists.")

    event = {
        "slug": slug,
        "day": stamp,
        "from_time": from_time,
        "to_time": to_time,
        "name": name,
        "description": description,
        "api_version": SCHEMA_VERSION,
        "created_by": user["username"],
        "cancelled": False,
        "comments": [],
        "ACKs": [],
        "DEACKs": [],
    }

    connection.set(key, event)

    # TODO: Refactor this when we have compare-and-set
    all_events = connection.get(ALL_EVENTS_LIST)
    if all_events:
        all_events.append(key)
    else:
        all_events = [key]
    connection.set(ALL_EVENTS_LIST, all_events)

    return (True, event)
コード例 #4
0
def submit_event(connection, day, from_time, to_time, name, description):
    from datetime import datetime
    error = ""
    if not day or len(day) == 0:
        return (False, "Day is blank.")

    if not name or len(name) == 0:
        return (False, "Name is blank.")

    user = get_user()["user"]

    if not user:
        return (False, "User not logged in.")

    converted_date = None
    try:
        converted_date = datetime.strptime(day, "%Y-%m-%d")
    except ValueError:
        return (False, "Date invalid. Should be of the form 'YYYY-MM-DD'.")

    slug = slugify(name)[:SLUG_SIZE]
    stamp = timegm(converted_date.timetuple())
    key = _get_event_str(slug, stamp)

    exists = connection.has_key(key)
    if exists:
        return (False, "An event with that name on that day already exists.")

    event = {
        "slug": slug,
        "day": stamp,
        "from_time": from_time,
        "to_time": to_time,
        "name": name,
        "description": description,
        "api_version": SCHEMA_VERSION,
        "created_by": user["username"],
        "cancelled": False,
        "comments": [],
        "ACKs": [],
        "DEACKs": [],
    }

    connection.set(key, event)

    # TODO: Refactor this when we have compare-and-set
    all_events = connection.get(ALL_EVENTS_LIST)
    if all_events:
        all_events.append(key)
    else:
        all_events = [key]
    connection.set(ALL_EVENTS_LIST, all_events)

    return (True, event)
コード例 #5
0
ファイル: routes.py プロジェクト: dequis/metaforcefeed
def ping(slug):
    to_return = { 'success': True, 'error': "" }
    user = get_user()['user']

    if not user:
        return abort(503)

    if not slug:
        return abort(404)

    gmtime = time.gmtime()
    seconds = int(calendar.timegm(gmtime))
    expiration = seconds + (60 * 60 * 24) #24 hours later

    ping_obj = {
        'pinged': slug,
        'when': seconds
    }
    pings = user.get('pings', None)
    def _handle_creation():
        # Inline because f**k a scope
        created, obj = ping_summary(g.db, slug, expiration)
        if created:
            user['pings'][slug] = ping_obj
            set_user(g.db, user)
            to_return['ping_obj'] = obj
            return Response(json.dumps(to_return), mimetype="application/json")
        else:
            to_return['error'] = obj
            return Response(json.dumps(to_return), mimetype="application/json")

    if not pings:
        user['pings'] = { slug: ping_obj }
        set_user(g.db, user)
        return _handle_creation()
    else:
        last_ping = pings.get(slug, None)
        if not last_ping:
            return _handle_creation()

        if seconds > (last_ping['when'] + (60 * 60 * 24)):
            return _handle_creation()

        to_return['success'] = False
        to_return['error'] = "You need to wait 24 hours to ping again."

    return Response(json.dumps(to_return), mimetype="application/json")
コード例 #6
0
def ping(slug):
    to_return = {'success': True, 'error': ""}
    user = get_user()['user']

    if not user:
        return abort(503)

    if not slug:
        return abort(404)

    gmtime = time.gmtime()
    seconds = int(calendar.timegm(gmtime))
    expiration = seconds + (60 * 60 * 24)  #24 hours later

    ping_obj = {'pinged': slug, 'when': seconds}
    pings = user.get('pings', None)

    def _handle_creation():
        # Inline because f**k a scope
        created, obj = ping_summary(g.db, slug, expiration)
        if created:
            user['pings'][slug] = ping_obj
            set_user(g.db, user)
            to_return['ping_obj'] = obj
            return Response(json.dumps(to_return), mimetype="application/json")
        else:
            to_return['error'] = obj
            return Response(json.dumps(to_return), mimetype="application/json")

    if not pings:
        user['pings'] = {slug: ping_obj}
        set_user(g.db, user)
        return _handle_creation()
    else:
        last_ping = pings.get(slug, None)
        if not last_ping:
            return _handle_creation()

        if seconds > (last_ping['when'] + (60 * 60 * 24)):
            return _handle_creation()

        to_return['success'] = False
        to_return['error'] = "You need to wait 24 hours to ping again."

    return Response(json.dumps(to_return), mimetype="application/json")
コード例 #7
0
def submit_idea(connection, short_summary, long_summary):
    error = ""
    if not short_summary or len(short_summary) == 0:
        return (False, "Short summary is blank.")

    if not long_summary or len(long_summary) == 0:
        return (False, "Long summary is blank.")

    user = get_user()["user"]

    if not user:
        return (False, "User not logged in.")

    slug = slugify(short_summary)[:SLUG_SIZE]
    summary = {
        "slug": slug,
        "api_version": SCHEMA_VERSION,
        "created_by": user["username"],
        "comments": [],
        "short_summary": short_summary,
        "long_summary": long_summary,
        "pings": 0
    }

    key = _get_summary_str(slug)
    exists = connection.has_key(key)

    if exists:
        return (False, "A post with that idea already exists.")

    connection.set(key, summary)

    # TODO: Refactor this when we have compare-and-set
    all_items = connection.get(ALL_ITEMS_LIST)
    if all_items:
        all_items.append(key)
    else:
        all_items = [key]
    connection.set(ALL_ITEMS_LIST, all_items)

    return (True, summary)
コード例 #8
0
ファイル: utils.py プロジェクト: kyleterry/metaforcefeed
def submit_idea(connection, short_summary, long_summary):
    error = ""
    if not short_summary or len(short_summary) == 0:
        return (False, "Short summary is blank.")

    if not long_summary or len(long_summary) == 0:
        return (False, "Long summary is blank.")

    user = get_user()["user"]

    if not user:
        return (False, "User not logged in.")

    slug = slugify(short_summary)[:SLUG_SIZE]
    summary = {
        "slug": slug,
        "api_version": SCHEMA_VERSION,
        "created_by": user["username"],
        "comments": [],
        "short_summary": short_summary,
        "long_summary": long_summary,
        "pings": 0
    }

    key = _get_summary_str(slug)
    exists = connection.has_key(key)

    if exists:
        return (False, "A post with that idea already exists.")

    connection.set(key, summary)

    # TODO: Refactor this when we have compare-and-set
    all_items = connection.get(ALL_ITEMS_LIST)
    if all_items:
        all_items.append(key)
    else:
        all_items = [key]
    connection.set(ALL_ITEMS_LIST, all_items)

    return (True, summary)
コード例 #9
0
ファイル: routes.py プロジェクト: qpfiffer/metaforcefeed
def calendar_event_de_ack(slug, stamp):
    to_return = { 'success': True, 'error': "" }
    user = get_user()['user']

    if not user:
        return abort(503)

    if not slug:
        return abort(404)

    from metaforcefeed.utils import de_ack_event, _get_event_str
    created, err = de_ack_event(g.db, slug, stamp, user)

    if not created:
        extra = err
    else:
        event = g.db.get(_get_event_str(slug, stamp))
        action_str = 'DE-ACK\'d "{}, {}".'.format(stamp, slug)
        log_action(g.db, action_str)

    return redirect(url_for('metaforcefeed.calendar_event', slug=slug, stamp=stamp))
コード例 #10
0
def calendar_event_de_ack(slug, stamp):
    to_return = {'success': True, 'error': ""}
    user = get_user()['user']

    if not user:
        return abort(503)

    if not slug:
        return abort(404)

    from metaforcefeed.utils import de_ack_event, _get_event_str
    created, err = de_ack_event(g.db, slug, stamp, user)

    if not created:
        extra = err
    else:
        event = g.db.get(_get_event_str(slug, stamp))
        action_str = 'DE-ACK\'d "{}, {}".'.format(stamp, slug)
        log_action(g.db, action_str)

    return redirect(
        url_for('metaforcefeed.calendar_event', slug=slug, stamp=stamp))
コード例 #11
0
def log_action(connection, action_str):
    user = get_user()['user']
    if not user:
        return (False, "User not logged in.")

    created_at = int(time.mktime(datetime.now().utctimetuple()))
    key = _get_action_str(user['username'], created_at)
    new_action = {
        'user': user['username'],
        'action_str': action_str,
        'created_at': created_at
    }
    connection.set(key, new_action)

    # TODO: Refactor this when we have compare-and-set
    all_actions = connection.get(ALL_ACTIONS_LIST)
    if all_actions:
        all_actions.append(key)
    else:
        all_actions = [key]
    connection.set(ALL_ACTIONS_LIST, all_actions)

    return True
コード例 #12
0
ファイル: utils.py プロジェクト: kyleterry/metaforcefeed
def log_action(connection, action_str):
    user = get_user()['user']
    if not user:
        return (False, "User not logged in.")

    created_at = int(time.mktime(datetime.now().utctimetuple()))
    key = _get_action_str(user['username'], created_at)
    new_action = {
        'user': user['username'],
        'action_str': action_str,
        'created_at': created_at
    }
    connection.set(key, new_action)

    # TODO: Refactor this when we have compare-and-set
    all_actions = connection.get(ALL_ACTIONS_LIST)
    if all_actions:
        all_actions.append(key)
    else:
        all_actions = [key]
    connection.set(ALL_ACTIONS_LIST, all_actions)

    return True