Esempio n. 1
0
def postreview():
    if 'email' not in session:
        return render_template('forms/login.html', form=LoginForm())

    if request.method == 'POST':
        company_name = request.form['company'].lower()
        content = request.form['experience']
        aSchema = AnalyticsSchema()
        cSchema = CompanySchema()
        rSchema = ReviewSchema()

        email = session['email']
        #sentJson = reqData['review']

        id = ""
        if not getCompany(company_name):
            print "compnay not found, creating.."
            cJson = constructCompany(company_name.lower())
            com = cSchema.load(cJson, session=db_session).data
            id = com.id
            db_session.add(com)
            review_count = 1
            sentJson = constructNewAnalytics(id, content)

        else:
            print "company found"
            comJson = getReviewCountForCompany(company_name.lower())
            id = comJson['id']
            count =comJson['r_cnt']
            name = comJson['name']
            existing_ana = getExistingAnalyticsForCompany(str(id))
            sentJson = constructRunningAnalytics(existing_ana, count, content)
            sentJson['id'] = str(existing_ana['id'])
            count +=1
            cJson = updateCompany(id, name, count)
            com = cSchema.load(cJson, session=db_session).data
            db_session.merge(com)


        rJson = constructReview(email,id, content)
        rev = rSchema.load(rJson, session=db_session).data
        rev.company_id = rJson['company_id']
        rev.user_id = rJson['user_id']
        rev.date = str(datetime.datetime.now())
        db_session.add(rev)

        #print sentJson

        ana = aSchema.load(sentJson, session=db_session).data
        ana.company_id = id
        db_session.merge(ana)
        db_session.commit()

    return render_template('pages/placeholder.post.html', form=PostReviewForm())
Esempio n. 2
0
    def create(cls, **kwargs):
        log = kwargs['log']
        if kwargs['log_type'] == 'info':
            log.info(kwargs['description'])
        elif kwargs['log_type'] == 'debug':
            log.debug(kwargs['description'])
        elif kwargs['log_type'] == 'warning':
            log.warning(kwargs['description'])
            kwargs['fail'] = True
        del kwargs['log']

        obj = cls(**kwargs)
        session.add(obj)
        session.commit()
Esempio n. 3
0
def setting_view_update():
    if request.method == 'POST':
        _type = request.form['type']
        slug = request.form['slug']
        value = request.form['value']
        if _type.lower() == 'update':
            SettingValue.query.filter_by(slug=slug).update({'value': value})
            db_session.commit()
        elif _type.lower() == 'create':
            new_setting = SettingValue(slug=slug, value=value)
            db_session.add(new_setting)
            db_session.commit()
        elif _type.lower() == 'delete':
            SettingValue.query.filter_by(slug=slug).delete()
            db_session.commit()
        return redirect(url_for('admin.setting_view'))
Esempio n. 4
0
def register():
    if request.method == 'POST':
        u = {}
        uSchema = UserSchema()
        username = request.form['name']
        password = request.form['password']
        email = request.form['email']
        u['id'] = str(uuid.uuid4())
        u['name'] = username
        u['email'] = email
        u['password'] = password
        user = uSchema.load(u, session=db_session).data
        db_session.add(user)
        db_session.commit()
        session["email"] = email
        return render_template('pages/placeholder.home.html')
    else:
        form = RegisterForm(request.form)
        return render_template('forms/register.html', form=form)
Esempio n. 5
0
def pairs_view_update():
    def get_request_data():
        to_bool = ['active', 'use_stop_loss']
        to_int = ['id', 'spend_sum']
        to_float = ['profit_markup', 'stop_loss']
        data = {}
        for i in request.form:
            if request.form[i] != '':
                data[i] = request.form[i]
                if i in to_bool:
                    data[i] = bool(request.form[i])
                elif i in to_int:
                    data[i] = int(request.form[i])
                elif i in to_float:
                    data[i] = float(request.form[i])
                else:
                    data[i] = request.form[i]
        if 'type' in data:
            del data['type']
        return data

    if request.method == 'POST':
        if request.form['type'] == 'update':
            data = get_request_data()
            pk = int(request.form['id'])
            PairSetting.query.filter_by(id=pk).update(data)
            db_session.commit()
        elif request.form['type'] == 'create':
            data = get_request_data()
            pair = PairSetting(**data)
            db_session.add(pair)
            db_session.commit()
        elif request.form['type'] == 'delete':
            pk = int(request.form['id'])
            PairSetting.query.filter_by(id=pk).delete()
            db_session.commit()
        return redirect(url_for('admin.pairs_view'))
Esempio n. 6
0
 def save_to_db(self):
     db_session.add(self)
     db_session.commit()
Esempio n. 7
0
 def create(cls, slug, value):
     obj = cls(slug=slug, value=value)
     session.add(obj)
     session.commit()
Esempio n. 8
0
 def create(cls, name, password, is_admin):
     obj = cls(name=name,
               password=generate_password_hash(password),
               is_admin=is_admin)
     session.add(obj)
     session.commit()