Пример #1
0
def upload():
    # THIS USES THE NEW_NOTE CALL, so going to move that to en_lib
    if request.method=='POST':
        upload_file = request.files['file']
        if upload_file and lib.allowed_file(upload_file.filename, app.config['ALLOWED_EXTENSIONS']):
            filename = upload_file.filename
            content = upload_file.stream.getvalue()
            # CHECK IF THIS NOTE WAS EXPORTED BY THE DESKTOP CLIENT AND IF SO STRIP OUT COMPONENTS
            pattern = re.compile('(.*?!\[CDATA\[)(.*?<\/en-note>)(.*?\]\]><\/content>.*)', re.DOTALL)
            m = pattern.search(content)
            if m is not None and len(m.group(2)) > 0:
                content = m.group(2) 
            flash(new_note(content=content, title=upload_file.filename))
            with open(os.path.join(app.config['UPLOADED_FILE_DEST'], filename), 'w') as f:
                f.write(content)
        return redirect(url_for('index'))
    else:
        return render_template('upload.html') 
Пример #2
0
def upload():
    # THIS USES THE NEW_NOTE CALL, so going to move that to en_lib
    if request.method == 'POST':
        upload_file = request.files['file']
        if upload_file and lib.allowed_file(upload_file.filename,
                                            app.config['ALLOWED_EXTENSIONS']):
            filename = upload_file.filename
            content = upload_file.stream.getvalue()
            # CHECK IF THIS NOTE WAS EXPORTED BY THE DESKTOP CLIENT AND IF SO STRIP OUT COMPONENTS
            pattern = re.compile(
                '(.*?!\[CDATA\[)(.*?<\/en-note>)(.*?\]\]><\/content>.*)',
                re.DOTALL)
            m = pattern.search(content)
            if m is not None and len(m.group(2)) > 0:
                content = m.group(2)
            flash(new_note(content=content, title=upload_file.filename))
            with open(os.path.join(app.config['UPLOADED_FILE_DEST'], filename),
                      'w') as f:
                f.write(content)
        return redirect(url_for('index'))
    else:
        return render_template('upload.html')
Пример #3
0
def index():
    error_list = None
    # CHECK IF THE USER IS LOGGED IN, OTHERWISE REDIRECT
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    # GET THE USER INFO, REDIRECT IF NOTHING IS RETURNED
    user = controls.get_user_info(session.get('username'))
    if not user:
        redirect(url_for('logout'))
    authorized_users = controls.get_authorized_users()
    # RETURNS A JSON ObJECT OF USERNAME, FIRST AND LAST
    lead = controls.get_lead(session.get('username'))
    if len(lead) == 0:
        lead = {'username': '', 'first_name': '', 'last_name': ''}
    else:
        lead = lead[0]
    notebooks = []
    if session.get('auth_token'):
        # CHECK AND SEE IF USER HAS SELECTED NOTEBOOKS
        if user['notebook_ids'] is not None and len(user['notebook_ids']) > 0:
            guid_list = user['notebook_ids'].split(',')
            flash("Getting Notebooks and Notes")
            notebooks = get_notebooks(session.get('auth_token'),
                                      session.get('shard_id'), guid_list)
        else:
            return redirect(url_for('configure', guid_list=None))
    # POST REQUESTS
    if request.method == 'POST':
        error_list = []
        note_list = request.form.getlist('note')
        # GET THE NOTE CONTENT FOR EACH NOTES GUID
        for value in note_list:
            try:
                title, guid = value.split(':')
                note = get_note(session.get('auth_token'),
                                session.get('shard_id'), guid)
            except Exception as e:
                error = "Error retrieving note using guid %s" % e
                return render_template('main.html', error=error)
            # ATTEMPT TO PARSE THE NOTE INTO A ENXML OBJECT
            # GET DOCTYPE FROM NOTE CONTENT
            rg = re.compile('(<!DOCTYPE .*?>)')
            m = rg.search(note)
            try:
                # CREATE EN OBJECT INITILIZING WITH NOTE AND DOCTYPE
                en = EN(note, doctype=m.group(1))
                # BREAK OUT TABLES
                en.break_out_tables()
                try:
                    en.set_activity_type('O')
                    en.set_activity_type('I')
                except:
                    error_list.append(
                        "Using an old Template, update your template in the future"
                    )
                    error_list.append(
                        "Unable to set Issues and Activities within the note")
                flash(
                    update_note(session.get('auth_token'),
                                session.get('shard_id'),
                                en.tostring(),
                                guid=guid,
                                title=title))
                # IF EMAIL IS SET
                if user['use_email'] == 1:
                    lib.send_email(en, app.config['EMAIL_SERVER'],
                                   user['email_address'])
                    flash("Note sent as email to %s" % user['email_address'])
                # IF LEAD IS SET
                if request.form['lead'] != 'None':
                    # GET LEAD AUTH_TOKEN
                    lead = controls.get_user_info(request.form['lead'])
                    flash(
                        new_note(shard_id=lead['shard_id'],
                                 content=en.tostring(),
                                 title=title,
                                 auth_token=lead['auth_token']))
                    flash("Sent note to lead: %s" % request.form['lead'])
                    controls.set_lead(session.get('username'),
                                      request.form['lead'])
                # CHANGE THE USERS LEAD ID TO THAT USED
                else:
                    controls.delete_lead(session.get('username'))
                    lead = {'username': '', 'first_name': '', 'last_name': ''}
                flash("Bug Time: %s" % en.times['B'])
                flash("Setup Time: %s" % en.times['S'])
                flash("Test Time: %s" % en.times['T'])
                flash("Session Length: %s" % en.session_length)
                en.export_xml(app.config['UPLOADED_FILE_DEST'],
                              "%s.xml" % title)
            except Exception as e:
                error_list.append(
                    "ERROR parsing out data from note %s. Exception: [%s]" %
                    (title, e))
    return render_template('main.html',
                           notebooks=notebooks,
                           error=error_list,
                           authorized_users=authorized_users,
                           lead=lead)
Пример #4
0
def index():
    error_list = None
    # CHECK IF THE USER IS LOGGED IN, OTHERWISE REDIRECT
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    # GET THE USER INFO, REDIRECT IF NOTHING IS RETURNED
    user = controls.get_user_info(session.get('username'))
    if not user:
        redirect(url_for('logout'))
    authorized_users = controls.get_authorized_users()
    # RETURNS A JSON ObJECT OF USERNAME, FIRST AND LAST 
    lead = controls.get_lead(session.get('username'))
    if len(lead) == 0:
        lead = {'username':'', 'first_name':'', 'last_name':''}
    else:
        lead = lead[0]
    notebooks = []
    if session.get('auth_token'):
        # CHECK AND SEE IF USER HAS SELECTED NOTEBOOKS
        if user['notebook_ids'] is not None and len(user['notebook_ids']) > 0:
            guid_list = user['notebook_ids'].split(',')
            flash("Getting Notebooks and Notes")
            notebooks = get_notebooks(session.get('auth_token'), 
                                      session.get('shard_id'),
                                      guid_list) 
        else:
            return redirect(url_for('configure', guid_list=None))         
    # POST REQUESTS
    if request.method=='POST':
        error_list = []
        note_list = request.form.getlist('note')
        # GET THE NOTE CONTENT FOR EACH NOTES GUID
        for value in note_list:
            try:
                title, guid = value.split(':')
                note = get_note(session.get('auth_token'), 
                                session.get('shard_id'),
                                guid)
            except Exception as e:
                error = "Error retrieving note using guid %s" %e
                return render_template('main.html', 
                                       error=error)
            # ATTEMPT TO PARSE THE NOTE INTO A ENXML OBJECT
            # GET DOCTYPE FROM NOTE CONTENT
            rg = re.compile('(<!DOCTYPE .*?>)')
            m = rg.search(note)
            try:
                # CREATE EN OBJECT INITILIZING WITH NOTE AND DOCTYPE
                en = EN(note, doctype=m.group(1))
                # BREAK OUT TABLES
                en.break_out_tables()
                try:
                    en.set_activity_type('O')
                    en.set_activity_type('I')
                except:
                    error_list.append("Using an old Template, update your template in the future")
                    error_list.append("Unable to set Issues and Activities within the note")
                flash(update_note(session.get('auth_token'),
                                  session.get('shard_id'),
                                  en.tostring(), 
                                  guid=guid, 
                                  title=title))
                # IF EMAIL IS SET
                if user['use_email'] == 1:
                    lib.send_email(en, app.config['EMAIL_SERVER'], user['email_address'])
                    flash("Note sent as email to %s" %user['email_address'])
                # IF LEAD IS SET
                if request.form['lead'] != 'None':
                    # GET LEAD AUTH_TOKEN
                    lead = controls.get_user_info(request.form['lead'])
                    flash(new_note(shard_id=lead['shard_id'],
                                   content=en.tostring(), 
                                   title=title, 
                                   auth_token=lead['auth_token']))
                    flash("Sent note to lead: %s" %request.form['lead'])
                    controls.set_lead(session.get('username'), request.form['lead'])
                # CHANGE THE USERS LEAD ID TO THAT USED
                else: 
                    controls.delete_lead(session.get('username'))
                    lead = {'username':'', 'first_name':'', 'last_name':''}
                flash("Bug Time: %s" %en.times['B'])
                flash("Setup Time: %s" %en.times['S'])
                flash("Test Time: %s" %en.times['T'])
                flash("Session Length: %s" %en.session_length)
                en.export_xml(app.config['UPLOADED_FILE_DEST'], "%s.xml" %title)
            except Exception as e:
                error_list.append("ERROR parsing out data from note %s. Exception: [%s]" %(title, e))
    return render_template('main.html',
                            notebooks=notebooks, 
                            error=error_list,
                            authorized_users=authorized_users,
                            lead=lead)