Beispiel #1
0
def delete_campaign(id):
    (engine, session) = _start_session(CAMPAIGN_DB)

    try:
        campaign = session.query(Campaign).filter(Campaign.id == id).one()
    except NoResultFound:
        _end_session(engine, session)
        raise CampaignNotFoundError(id)

    db_to_del = campaign.db_name
    session.delete(campaign)
    session.flush()

    # Remove the campaign's page db
    db_full_path = ROOT_DIR + DB_DIR + db_to_del
    if os.path.isfile(db_full_path):
        os.remove(db_full_path)

    # Purge rtfs
    _purge_rtfs(db_to_del)

    # Clean up the campaign's rtf directory
    rtf_dir = get_rtf_fullpath(db_to_del, '')
    if os.path.isdir(rtf_dir):
        os.rmdir(rtf_dir)

    session.commit()
    _end_session(engine, session)
Beispiel #2
0
def insert_campaign(name, **kwargs):
    (engine, session) = _start_session(CAMPAIGN_DB)

    try:
        new_campaign = Campaign.new(name, **kwargs)
        session.add(new_campaign)
        session.flush()
    except IntegrityError:
        _end_session(engine, session)
        raise NameUnavailableError(name)

    # create the campaign's db
    p_db_path = DB_PREFIX + ROOT_DIR + DB_DIR + new_campaign.db_name
    p_engine = create_engine(p_db_path)

    p_table = Base.metadata.tables[PAGE_TABLE_NAME]
    Base.metadata.create_all(p_engine, tables=[p_table])
    p_engine.dispose()

    # create the campaign's rtf directory
    rtf_full_dir = get_rtf_fullpath(new_campaign.db_name, '')
    if not os.path.isdir(rtf_full_dir):
        os.mkdir(rtf_full_dir)

    new_id = new_campaign.id
    session.commit()
    _end_session(engine, session)

    return new_id
Beispiel #3
0
def apply_rtf(db_name, form, from_save=False):
    if 'rtf' in form:
        rtf_content = form['rtf'].value
    else:
        rtf_content = ''

    save_error = False

    if 'path' in form:
        page_path = form['path'].value
        try:
            page = query_page(db_name, page_path)
            rtf_fullpath = get_rtf_fullpath(db_name, page.rtf)
            _overwrite_rtf(rtf_fullpath, rtf_content)
            redirect_path = page_path
        except PageNotFoundError:
            redirect_path = PATH_ERROR + '?error=' + GETVAR_PAGE_NOT_FOUND
            save_error = True
    else:
        redirect_path = PATH_ERROR + '?error=' + GETVAR_NO_PATH
        save_error = True
    
    if from_save:
        return (redirect_path, save_error)
    else:
        return redirect_path
Beispiel #4
0
def _touch_rtf(db_name, rtf):
    rtf_full_path = get_rtf_fullpath(db_name, rtf)
    open(rtf_full_path, 'a').close()
Beispiel #5
0
def _purge_rtfs(db_name):
    rtf_dir = get_rtf_fullpath(db_name, '')
    rtf_list = os.listdir(rtf_dir)
    for rtf in rtf_list:
        _delete_rtf(db_name, rtf)
Beispiel #6
0
def _empty_rtf(db_name, rtf):
    rtf_full_path = get_rtf_fullpath(db_name, rtf)
    if os.path.isfile(rtf_full_path):
        open(rtf_full_path, 'w').close()
Beispiel #7
0
def _delete_rtf(db_name, rtf):
    rtf_full_path = get_rtf_fullpath(db_name, rtf)
    if os.path.isfile(rtf_full_path):
        os.remove(rtf_full_path)