Ejemplo n.º 1
0
def company_registration(request):

    if request.method == 'GET':
        form = CompanyForm()
        return render(request, 'company/company_registration.html', {
            'title': 'Company registration',
            'form': form
        })

    if request.method == 'POST':
        form = CompanyForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            Company.objects.create(email=data['email'],
                                   telephone=data['telephone'],
                                   name=data['name'],
                                   address=data['address'])
            User.objects.create_user(username=data['name'],
                                     password=data['password'],
                                     email=data['email'])
            send_validation_email(data['email'], request)
            return success_happened(
                request, 'Company {company} successfuly created'.format(
                    company=data['name']))
        return render(request, 'company/company_registration.html', {
            'title': 'Company registration',
            'form': form
        })

    return Http404()
Ejemplo n.º 2
0
def add_company():
    form = CompanyForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            company = Company(
                company_name=form.company_name.data,
                company_address=form.company_address.data,
                company_city=form.company_city.data,
                company_state=form.company_state.data,
                company_zipcode=form.company_zipcode.data,
                company_website=form.company_website.data,
                company_phone_number=form.company_phone_number.data,
                company_email=form.company_email.data,
                author=current_user)
        else:
            company = Company(
                company_name=form.company_name.data,
                company_address=form.company_address.data,
                company_city=form.company_city.data,
                company_state=form.company_state.data,
                company_zipcode=form.company_zipcode.data,
                company_website=form.company_website.data,
                company_phone_number=form.company_phone_number.data,
                company_email=form.company_email.data)
        db.session.add(company)
        db.session.commit()

        flash('Thank you, the company has been added!')
        return redirect(url_for('index'))
    return render_template('report.html', title='Report', form2=form)
Ejemplo n.º 3
0
    def post(self):
        """ Creates new company """

        form = CompanyForm(obj=Company(), params=request.get_json())
        if form.submit():
            return {'company': single_schema.dump(form.object).data}, 200
        else:
            return {'errors': form.errors}, 400
Ejemplo n.º 4
0
    def put(self, company_id):
        """ Update existing company """

        company = get_object_or_404(Company, company_id)
        form = CompanyForm(obj=company, params=request.get_json())
        if form.submit():
            return { 'company': single_schema.dump(company).data }, 200
        else:
            return { 'errors': form.errors }, 400
Ejemplo n.º 5
0
def route():
    form = CompanyForm()
    if form.validate_on_submit():
        comp = [form.company_a.data, form.company_b.data]
        close_compA = getCompanyClose(comp[0])
        close_compB = getCompanyClose(comp[1])
        graph = graphStockData(close_compA, close_compB, comp)
        return render_template('test.html', title="Closing Price", url=graph)
    return render_template('enter_co.html', title="Company Entry", form=form)
Ejemplo n.º 6
0
def add_company():
    form = CompanyForm()
    if form.validate_on_submit():
        company = Company(company_name=form.name.data,
                          description=form.description.data)
        db.session.add(company)
        db.session.commit()
        flash('Successfully added company')
        return redirect(url_for('home'))
    return render_template('add_company.html', form=form)
Ejemplo n.º 7
0
 def test_company_registration_correct_phone_format(self):
     form_data = {
         'email': '*****@*****.**',
         'telephone': '123abc',
         'name': 'testcompany',
         'address': '123 6th St. Melbourne',
         'password': '******'
     }
     form = CompanyForm(data=form_data)
     self.assertFalse(form.is_valid())
Ejemplo n.º 8
0
 def test_company_registration_incorrect_email_format(self):
     form_data = {
         'email': 'bad_email_format',
         'telephone': '12345678',
         'name': 'testcompany',
         'address': '123 6th St. Melbourne',
         'password': '******'
     }
     form = CompanyForm(data=form_data)
     self.assertFalse(form.is_valid())
Ejemplo n.º 9
0
 def test_company_registration_required_fields_empty(self):
     form_data = {
         'email': '',
         'telephone': '',
         'name': '',
         'address': '',
         'password': ''
     }
     form = CompanyForm(data=form_data)
     self.assertFalse(form.is_valid())
Ejemplo n.º 10
0
def index():
    form = CompanyForm()
    if form.validate_on_submit():
        current_user.length = form.space_length.data
        current_user.width = form.space_width.data
        current_user.username = form.company_name.data
        current_user.number_of_employees = form.number_of_employees.data
        db.session.commit()
        return redirect(url_for('departments'))
    #performance_test_start()
    return render_template('index.html', title='Company information', form=form)
Ejemplo n.º 11
0
def addCompany(id):
    form = CompanyForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        newCompany = Company(
            userId_fk=id,
            companyName=form.data['companyName'],
        )
        db.session.add(newCompany)
        db.session.commit()
        return newCompany.to_dict()
    return { 'errors': validation_errors_to_error_messages(form.errors)}
Ejemplo n.º 12
0
 def test_company_registration_requires_unique_username(self):
     self.company = Company.objects.create(name='testcompany',
                                           email='*****@*****.**',
                                           telephone='2761234')
     form_data = {
         'email': '*****@*****.**',
         'telephone': '12345678',
         'name': 'testcompany',
         'address': '123 6th St. Melbourne',
         'password': '******'
     }
     form = CompanyForm(data=form_data)
     self.assertFalse(form.is_valid())
Ejemplo n.º 13
0
def CompanyFormView(request, name):
    if request.method == "GET":
        comp = Company.objects.filter(name=name)
        if not comp:
            form = CompanyForm()
            return render(request, 'app/company_create.html', {'form': form})

        return render(request, 'app/company_profile.html',
                      {'companies': comp.first()})

    elif request.method == "POST":
        form = CompanyForm(request.POST)
        try:
            if form.is_valid():
                update_company_questionwidth(form.save(request.user),
                                             request.POST['questions'])
                return redirect('/company/' + request.user.username)
        except Exception as e:
            form = CompanyForm(e)
    return render(request, 'app/company_create.html', {'form': form})
Ejemplo n.º 14
0
def index():
    form = CompanyForm()
    if form.validate_on_submit():
        return redirect('/search/' + form.company_name.data)
    return render_template('index.html', title='Home', form=form)