Exemple #1
0
 def get(self, tech_id):
     conn = sqlite3.connect('lbg.db')
     cursor = conn.cursor()
     appl = cursor.execute(
         '''select * from applications where userSolverId="%s"''' %
         (tech_id))
     for u in appl:
         result = Application(u)
     print(result.getFullInfo())
     return jsonify(result.getFullInfo())
Exemple #2
0
 def put(self, id):
     """Update an application."""
     application = Application.query.filter_by(id=id).first_or_404()
     app.logger.info('Update application: %s' % id)
     target = Application.from_json(request.data)
     application.merge(target)
     db.session.commit()
     return application.to_json()
Exemple #3
0
 def post(self, id):
     """Create an application, expecting a json content."""
     application = Application.from_json(request.data)
     app.logger.info('Creating new application: %s' % request.data)
     db.session.add(application)
     try:
         db.session.commit()
     except IntegrityError, error:
         app.logger.warning(error)
         abort(409)
Exemple #4
0
def random_items():
    data = request.get_json()
    app_uuid = data["app_uuid"]
    if not Application.is_valid(app_uuid):
        abort(401)
    random_query = Text().select().order_by(fn.Random())
    text = random_query.get()

    item = {}
    item["id"] = text.uuid
    item["text"] = text.text

    app.logger.info("serving item {0}".format(item["id"]))
    return jsonify({"item": item})
def new_application():
    # company attributes
    company_name = request.form.get('company_name')
    website = request.form.get('website')
    # job attributes
    title = request.form.get('title')
    link = request.form.get('link')
    source = request.form.get('source')
    # application status attributes
    status = request.form.get('status')

    application = Application()
    db.session.add(application)

    company = db.session.query(Company) \
        .filter((Company.company_name==company_name) & (Company.website==website)) \
        .first()
    if not company:
        company = Company(company_name=company_name,
            website=website)
        db.session.add(company)
        db.session.commit()
    
    job = db.session \
        .query(Job) \
        .filter(Job.title==title, Job.link==link, Job.source==source, Job.company==company) \
        .first()
    if not job:
        job = Job(title=title, link=link, source=source)
        db.session.add(job)
        company.jobs.append(job)
        db.session.commit()
    
    application_status = ApplicationStatus(status=status)
    db.session.add(application_status)

    current_user.applications.append(application)
    job.applications.append(application)
    application.application_statuses.append(application_status)
    db.session.commit()
    # TODO: point entry for new application

    return jsonify({
        'application_id': application.application_id,
        'title': job.title,
        'company_name': company.company_name,
        'status': application_status.status,
    })
Exemple #6
0
def validate():
    data = request.get_json()
    app_uuid = data["app_uuid"]
    #user_id = data["user_id"]

    if not Application.is_valid(app_uuid):
        abort(401)

    text_uuid, data_score = data["id"], data["score"]
    Tag.create(
        application_uuid=app_uuid,
        user_id=0,  #reserved for this front
        text_uuid=text_uuid,
        score=data_score,
        validated=True)
    return random_items()
Exemple #7
0
def seed1():
    datetime_applied, datetime_created = datetime.now(), datetime.now()

    user = User(email='*****@*****.**', 
                password='******', 
                first_name='First', 
                last_name='Last', 
                datetime_created=datetime_created)
    db.session.add(user)

    company = Company(company_name='My Company', 
                        website='www.mycompany.com', 
                        datetime_created=datetime_created)
    db.session.add(company)
    db.session.commit()

    job = Job(company_id=company.company_id,
                title='Software Engineer',
                link='www.linkedin.com/mycompany/software-engineer',
                source='LinkedIn',
                datetime_created=datetime_created
                )
    db.session.add(job)
    db.session.commit()

    application = Application(user_id=user.user_id,
                                job_id=job.job_id,
                                datetime_applied=datetime_applied, 
                                referred_by="Anjelica", 
                                datetime_created=datetime_created)
    db.session.add(application)
    db.session.commit()

    application_status = ApplicationStatus(application_id=application.application_id,
                                            status='Applied',
                                            experience_rating='positive',
                                            datetime_created=datetime_created)
    db.session.add(application_status)

    journal_entry = JournalEntry(application_id=application.application_id,
                            entry='This is a journal entry.',
                            datetime_created=datetime_created)

    db.session.add(journal_entry)
    db.session.commit()
Exemple #8
0
def seed2():
    datetime_applied, datetime_created = datetime.now(), datetime.now()

    user = User.query.first()

    company = db.session.query(Company).filter(Company.company_name.like('%Another Company%')).first()
    if not company:
        company = Company(company_name='Another Company', 
                            website='www.anothercompany.com', 
                            datetime_created=datetime_created)
    db.session.add(company)
    db.session.commit()

    job = db.session.query(Job).filter(Job.company_id==company.company_id, Job.title.like('%Software Engineer%')).first()
    if not job:
        job = Job(company_id=company.company_id,
                    title='Software Engineer',
                    link='www.linkedin.com/anothercompany/software-engineer',
                    source='Glassdoor',
                    datetime_created=datetime_created)
    db.session.add(job)
    db.session.commit()

    application = Application(user_id=user.user_id,
                                job_id=job.job_id,
                                datetime_applied=datetime_applied, 
                                referred_by="Anjelica", 
                                datetime_created=datetime_created)
    db.session.add(application)
    db.session.commit()

    application_status = ApplicationStatus(application_id=application.application_id,
                                            status='Applied',
                                            experience_rating='positive',
                                            datetime_created=datetime_created)
    db.session.add(application_status)

    journal_entry = JournalEntry(application_id=application.application_id,
                            entry='Another journal entry.',
                            datetime_created=datetime_created)

    db.session.add(journal_entry)
    db.session.commit()
def application(application_name):
    if application_name != g.account.name:
        raise APIError('Application specified not allowed for provided API '
                       'credentials')
    try:

        if g.account.application is not None:
            db.session.\
                query(Application).\
                filter(Application.id==g.account.application.id).\
                delete()

        application = Application()
        # first check the upload is not over any account limit
        # size limits are to be determined after base64 decoding, so those are
        # handled further into this API call
        data = json.loads(request.data)

        max_static_size = 0
        total_app_size = 0

        # fresh resources
        content_resources = {}
        template_sources = {}
        for category in ('content', 'static', 'templates'):
            values = data.get(category, {})
            for resource_key, rawdata in values.iteritems():
                extension = os.path.splitext(resource_key)[1]
                binary_data = base64.b64decode(rawdata)
                total_app_size += len(binary_data)

                # precompiling data files into python dicts
                if category == 'content':
                    resource = ApplicationStaticContent()
                    resource.resource_key = resource_key
                    if extension == '.yaml':
                        native_data = yaml.load(binary_data)
                    elif extension == '.json':
                        native_data = json.loads(binary_data)
                    else:
                        native_data = {}
                    resource.data = json.dumps(native_data)
                    application.static_contents.append(resource)
                    content_resources[resource_key] = resource

                # static data is just a blob
                elif category == 'static':
                    # SCSS "sassy css"
                    if resource_key.startswith('css/') and \
                       resource_key.endswith('.scss'):
                        _scss = scss.Scss()
                        css_data = _scss.compile(binary_data)
                        static_data = css_data

                    # stylus
                    elif resource_key.startswith('css/') and \
                       resource_key.endswith('.styl'):
                        static_data = service.compile_stylus(binary_data)

                    # less 
                    elif resource_key.startswith('css/') and \
                       resource_key.endswith('.less'):
                        static_data = service.compile_less(binary_data)

                    # coffee script
                    elif resource_key.startswith('js/') and \
                       resource_key.endswith('.coffee'):
                        js_data = service.compile_coffeescript(binary_data)
                        static_data = js_data

                    else:
                        static_data = binary_data

                    max_static_size = max(max_static_size, len(static_data))
                    resource = ApplicationStaticFile()
                    resource.resource_key = resource_key
                    resource.data = static_data
                    application.static_files.append(resource)

                # template processing
                elif category == 'templates':

                    # markdown to straight HTML
                    if resource_key.endswith('.md'):
                        jinja2 = markdown.markdown(binary_data)

                    # everything else for jinja2
                    else:
                        jinja2 = service.preprocess_jade(
                            binary_data, resource_key)

                    template = ApplicationTemplate()
                    template.key = resource_key
                    template.jinja2 = jinja2
                    application.templates.append(template)

        # fresh routes
        app_yaml = base64.b64decode(data.get('application_config', ''))
        total_app_size += len(app_yaml)
        app_data = yaml.load(app_yaml)
        routes = app_data.get('routes', [])
        for route in routes:
            app_route = ApplicationRoute()
            app_route.rule = route['rule']
            app_route.template_name = route['template']
            app_route.static_contents = []
            if 'content' in route:
                if isinstance(route['content'], str):
                    route_content = [route['content']]
                else:
                    route_content = route['content']

                for data_resource in route_content:
                    app_route.static_contents.append(content_resources[data_resource])
            application.routes.append(app_route)

        application.account = g.account
        db.session.commit()
    except SQLAlchemyError as e:
        current_app.logger.error(e)
        db.session.rollback()
        raise
    except Exception as e:
        current_app.logger.error(e)
        db.session.rollback()
        raise APIError(e)
    return {'name': g.account.name}
Exemple #10
0
def new_application():
    pjson = json.loads(request.data)
    app = Application(pjson.get('name'))
    app.save()
    return jsonify({'result': "Ok"})
Exemple #11
0
class testModel(unittest.TestCase):
    calculator = Application()

    def test_add(self):
        self.calculator.compute_box = 14
        self.calculator.add_button_fired()
        self.calculator.compute_box = 20
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 34)

        self.calculator.compute_box = 14.0
        self.calculator.add_button_fired()
        self.calculator.compute_box = 20
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 34.0)

        self.calculator.compute_box = 14.65
        self.calculator.add_button_fired()
        self.calculator.compute_box = 20.09
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 34.74)

    def test_sub(self):
        self.calculator.compute_box = 14
        self.calculator.subtract_button_fired()
        self.calculator.compute_box = 20
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, -6)

        self.calculator.compute_box = 14.0
        self.calculator.subtract_button_fired()
        self.calculator.compute_box = 10
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 4.0)

        self.calculator.compute_box = 14.65
        self.calculator.subtract_button_fired()
        self.calculator.compute_box = 20.09
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, -5.44)

    def test_div(self):
        self.calculator.compute_box = 14
        self.calculator.div_button_fired()
        self.calculator.compute_box = 20
        self.calculator.eval_expr()

        # fails because we do floor division for integers!
        self.assertEqual(self.calculator.compute_box, 0.7)

        self.calculator.compute_box = 14.0
        self.calculator.div_button_fired()
        self.calculator.compute_box = 10
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 1.40)

        self.calculator.compute_box = 1
        self.calculator.div_button_fired()
        self.calculator.compute_box = 20
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 0.05)

    def test_mul(self):
        self.calculator.compute_box = 14
        self.calculator.mul_button_fired()
        self.calculator.compute_box = 20
        self.calculator.eval_expr()

        # fails because we do floor division for integers!
        self.assertEqual(self.calculator.compute_box, 280)

        self.calculator.compute_box = 14.0
        self.calculator.mul_button_fired()
        self.calculator.compute_box = 10
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 140.0)

        self.calculator.compute_box = 1.1
        self.calculator.mul_button_fired()
        self.calculator.compute_box = 20.4
        self.calculator.eval_expr()

        self.assertEqual(self.calculator.compute_box, 22.44)
Exemple #12
0
def main():
    for fafafa in Application.select().dicts():
        print(fafafa)
    return render_template('index.html')