Ejemplo n.º 1
0
 def get(self):
     pw_hash = util.make_pw_hash(config.admin_username, config.admin_pw)
     admin = models.Admin(admin_username=config.admin_username,
                          admin_pw_hash=pw_hash,
                          key_name='admin_key_name')
     admin.put()
     self.redirect('/')
     return
Ejemplo n.º 2
0
 def post(self):
     data = request.get_json(force=True)
     try:
         new_user = models.Admin(data['username'], data['password'],
                                 data['ravello_username'],
                                 data['ravello_password'])
         if new_user.insert():
             return 'OK', 201
         return 'User Create Failed', 400
     except BaseException as e:
         print('Exception: ', str(e))
         return str(e), 400
Ejemplo n.º 3
0
def settings():
    form = fm.Settings_Search(fl.request.form)
    if fl.request.method == 'GET':
        return fl.render_template('settings.html', form=form)

    else:
        if form.validate_on_submit():
            update = ml.Admin()
            new_search_names = ml.Search_Names(name=form.search_name.data)
            update.search_names.append(new_search_names)
            db.db_session.add(update)
            db.db_session.commit()
            fl.flash("Search updated with " + form.search_name.data, "success")
            return fl.render_template('settings.html', form=form)
        else:
            fl.flash("Search not updated", "error")
            return fl.render_template("settings.html", form=form)
Ejemplo n.º 4
0
def resetdb():
    """Destroys and creates the database + tables."""

    metadata = sa.MetaData()
    metadata.reflect(engine)
    for tbl in reversed(metadata.sorted_tables):
        tbl.drop(engine)
    # if not database_exists(DB_URL):
    #     print('Creating database.')
    #     create_database(DB_URL)

    print('Creating tables.')
    # import the models used to describe the tables we're creating (using the
    # ORM). Link: http://flask-sqlalchemy.pocoo.org/2.3/models/
    import models
    Base.metadata.create_all(bind=engine)
    db_session.commit()
    print('Integrating models.')

    # create user object and then commit to db
    from passlib.hash import sha512_crypt
    pw_hashed = sha512_crypt.encrypt("admin")
    pw_hashed_an = sha512_crypt.encrypt("test")
    new_admin = models.User(fname="Johnny",
                            lname="Admin",
                            email="*****@*****.**",
                            language=False,
                            pw_hashed=pw_hashed,
                            admin=True,
                            confirmed=True)
    new_analyst = models.User(fname="Johny",
                              lname="Test",
                              email="*****@*****.**",
                              language=True,
                              pw_hashed=pw_hashed_an,
                              admin=False)
    db_session.add(new_admin)
    db_session.add(new_analyst)
    update = models.Admin()
    new_search_names = models.Search_Names(name="Factiva")
    update.search_names.append(new_search_names)
    db_session.add(update)
    db_session.commit()
    print("Creating an admin user.")
    print("Creating an test user.")
    print("Creating a new search type")
Ejemplo n.º 5
0
def create_tables():
    """Works the models into the db in using the ORM"""
    print('Creating tables.')
    # import the models used to describe the tables we're creating (using the
    # ORM). Link: http://flask-sqlalchemy.pocoo.org/2.3/models/
    import models
    Base.metadata.create_all(bind=engine)
    db_session.commit()
    print('Integrating models.')

    # create user object and then commit to db
    from passlib.hash import sha512_crypt
    pw_hashed = sha512_crypt.encrypt("admin")
    pw_hashed_an = sha512_crypt.encrypt("test")
    new_admin = models.User(fname="Johnny",
                            lname="Admin",
                            email="*****@*****.**",
                            language=False,
                            pw_hashed=pw_hashed,
                            admin=True,
                            confirmed=True)
    new_analyst = models.User(fname="Johny",
                              lname="Test",
                              email="*****@*****.**",
                              language=True,
                              pw_hashed=pw_hashed_an,
                              admin=False)
    db_session.add(new_admin)
    db_session.add(new_analyst)
    update = models.Admin()
    new_search_names = models.Search_Names(name="Factiva")
    update.search_names.append(new_search_names)
    db_session.add(update)
    print("Creating an admin user.")
    print("Creating an test user.")
    print("Creating a new search type")

    week = models.Frequencies()
    week.name = "Weekly"
    week.days_in_freq = 7
    db_session.add(week)
    print("Adding weekly frequency")

    db_session.commit()
Ejemplo n.º 6
0
    def action_dryrun(self, ids):
        try:
            query = tools.get_query_for_ids(self.get_query(), self.model, ids)
            count = 0
            for job in query:
                msg = models.Admin().rerun_task(job.task_id,
                                                job.etl_day,
                                                up_and_down=False,
                                                run_up=False,
                                                run_down=False,
                                                force=True)
                count += 1

            flash(
                ngettext('jobs was successfully dryrun.',
                         '%(count)s records were successfully dryrun.',
                         count,
                         count=count), 'success')
        except Exception as ex:
            if not self.handle_view_exception(ex):
                raise

            flash(gettext('Failed to rerun records. %(error)s', error=str(ex)),
                  'error')
Ejemplo n.º 7
0
 def get_admins(self):
     self.__execute("SELECT * FROM Admins")
     return [models.Admin(i[0]) for i in self.cursor.fetchall()]