示例#1
0
 def to_company(self, company: Company):
     """Create a transaction to company"""
     if self._has_enough_money_to_transfer():
         self.from_company.balance -= self.amount
         company.balance += self.amount
         self.from_company.save()
         company.save()
示例#2
0
    def handle(self, *args, **options):
        print('Importing.')
        Company.objects.all().delete()
        Person.objects.filter(source='flagma.kz').delete()
        Person2Company.objects.all().delete()
        urls = []
        for cnt in range(1, 1000):
            urls.append('https://flagma.kz/kompanii-k-%s.html' % cnt)

        for url in urls:
            print("Importing %s" % url)
            time.sleep(1)
            i = Import()
            i.url = url
            i.save()
            rez = requests.get(url)
            soup = bs4.BeautifulSoup(rez.text, 'html.parser')
            items = soup.findAll('div', {"class": "page-list-item-info"})
            for i in items:
                name = i.find('a').text
                location = i.find('span', {"itemprop": "location"}).text
                boss = i.find('span', {"itemprop": "employee"}).text
                arrboss = boss.split(',')
                c = Company()
                c.name_ru = name
                c.name_kz = name
                c.faunders_text = boss
                c.city_text = location
                c.save()
                parse_company(c)
                print('Saving.....%s' % name)
示例#3
0
    def test_can_retrieve_a_company_with_founders(self):
        demo = Company(
            name=data1['name'],
            website=data1['website'],
            bio=data1['bio'],
        )
        demo.save()

        # Add founders into the database
        # with reference to the newly created company
        company_id = Company.query.first().id

        auth_token = self.get_auth_token(staff=True)

        for founder in data1['founders']:
            Founder(company_id=company_id,
                    name=founder['name'],
                    email=founder['email'],
                    role=founder['role']).save()

        # GET request
        response = self.client.get(
            f'/companies/{company_id}',
            headers=self.get_authorized_header(auth_token))
        self.assertEqual(response.status_code, 200)
        response_ = json.loads(response.data.decode())
        self.assertIn('founders', response_)
        self.assertIn('role', str(response_['founders']))
        self.assertIn('@demo.com', str(response_['founders']))
示例#4
0
 def save(self, user, commit=True):
     try:
         company = Company()
         company.threshold = self.cleaned_data['threshold']
         company.name = user.username
         try:
             list = json.loads(self.data["questions"])
             company.num_of_questions = len(list)
         except:
             company.num_of_questions = 10
         company.user = User.objects.get(pk=user.pk)
         if commit:
             company.save()
         return company
     except:
         raise AttributeError("invalid Parameters")
示例#5
0
def stock_add(request):
    from app.remote.stocks import StockHistoryClient
    from app.forms import StockWizardForm
    from app.models import Company, Stock

    if request.method == "POST":
        form = StockWizardForm(request.POST)
        pprint(form.is_valid())
        if form.is_valid():
            # save
            company = Company()
            company.name = form.cleaned_data['company_name']
            company.country = form.cleaned_data['company_country']
            company.save()

            stock = Stock()
            stock.company = company
            stock.name = form.cleaned_data['name']
            stock.wkn = form.cleaned_data['wkn']
            stock.isin = form.cleaned_data['isin']
            stock.symbol = form.cleaned_data['symbol']
            stock.type = form.cleaned_data['type']
            stock.default_stock_exchange = form.cleaned_data['default_stock_exchange']
            stock.save()

            return HttpResponseRedirect(reverse('stock', args=(stock.symbol,)))
        else:
            pprint(form.errors)
    else:
        data = None
        if 'wkn_or_isin' in request.GET:
            shc = StockHistoryClient()
            data = shc.get_basics_by_wkn_or_isin(wkn_or_isin=request.GET['wkn_or_isin'])

            data['company_country'] = data['country']
            data['company_name'] = data['name']

        form = StockWizardForm(initial=data)

    return render_to_response(
        'stock_wizard_add.html',
        {
            'form': form
        },
        context_instance=RequestContext(request)
    )
示例#6
0
def stock_add(request):
    from app.remote.stocks import StockHistoryClient
    from app.forms import StockWizardForm
    from app.models import Company, Stock

    if request.method == "POST":
        form = StockWizardForm(request.POST)
        pprint(form.is_valid())
        if form.is_valid():
            # save
            company = Company()
            company.name = form.cleaned_data['company_name']
            company.country = form.cleaned_data['company_country']
            company.save()

            stock = Stock()
            stock.company = company
            stock.name = form.cleaned_data['name']
            stock.wkn = form.cleaned_data['wkn']
            stock.isin = form.cleaned_data['isin']
            stock.symbol = form.cleaned_data['symbol']
            stock.type = form.cleaned_data['type']
            stock.default_stock_exchange = form.cleaned_data[
                'default_stock_exchange']
            stock.save()

            return HttpResponseRedirect(reverse('stock',
                                                args=(stock.symbol, )))
        else:
            pprint(form.errors)
    else:
        data = None
        if 'wkn_or_isin' in request.GET:
            shc = StockHistoryClient()
            data = shc.get_basics_by_wkn_or_isin(
                wkn_or_isin=request.GET['wkn_or_isin'])

            data['company_country'] = data['country']
            data['company_name'] = data['name']

        form = StockWizardForm(initial=data)

    return render_to_response('stock_wizard_add.html', {'form': form},
                              context_instance=RequestContext(request))
示例#7
0
    def test_can_retrieve_a_company_without_founders(self):
        demo = Company(
            name=data1['name'],
            website=data1['website'],
            bio=data1['bio'],
        )
        demo.save()
        company_id = Company.query.first().id

        auth_token = self.get_auth_token(staff=True)

        # GET request
        response = self.client.get(
            f'/companies/{company_id}',
            headers=self.get_authorized_header(auth_token))
        self.assertEqual(response.status_code, 200)
        response_ = json.loads(response.data.decode())
        self.assertEqual(response_['name'], data1['name'])
        self.assertEqual(response_['website'], data1['website'])
        self.assertEqual(response_['bio'], data1['bio'])
示例#8
0
def populate():
    """Populate some data"""
    db.drop_all()
    db.create_all()
    staff = User(name="Staff",
                 password="******",
                 email="*****@*****.**",
                 staff=True)

    staff.save()

    for company in companies:
        new_company = Company(name=company['name'],
                              website=company['website'],
                              bio=company['bio'])

        print('Saving company', new_company)

        new_company.save()

        if not is_production:
            # We only add dummy data points
            # if not in production mode
            # Saving random metrics
            for _ in range(10):
                for metric in KPI:
                    KPI[metric](company_id=new_company.id,
                                value=random.randint(0, 100)).save()

        for founder in company['founders']:
            new_founder = Founder(name=founder['name'],
                                  email=founder['email'],
                                  role=founder['role'],
                                  company_id=new_company.id)

            print('Saving founder', founder)

            new_founder.save()

    db.session.commit()
示例#9
0
    def test_saving_and_retrieving_models(self):
        company = Company()
        company.name = 'PSL'
        company.email = '*****@*****.**'
        company.telephone = 7777777
        company.save()

        first_room = Room()
        first_room.name = 'Peter Santamaria'
        first_room.company = company
        first_room.security_level = 2
        first_room.description = 'Conference room'
        first_room.id = 'r00m1'
        first_room.save()

        second_room = Room()
        second_room.name = '201'
        second_room.company = company
        second_room.security_level = 1
        second_room.description = 'Class room'
        second_room.id = 'r00m2'
        second_room.save()

        third_room = Room()
        third_room.name = 'rest'
        third_room.company = company
        third_room.security_level = 1
        third_room.description = 'Rest room'
        third_room.id = 'r00m3'
        third_room.save()

        event = Event()
        event.name = 'My event'
        event.company = company
        event.start_date = datetime(2017, 3, 16)
        event.end_date = datetime(2017, 3, 21)
        event.event_id = '3v3nt'
        event.rooms.add(first_room)
        event.rooms.add(second_room)
        event.rooms.add(third_room)
        event.save()

        enduser = EndUser()
        enduser.id = 'u53r'
        enduser.name = 'Sebastian'
        enduser.last_name = 'Villegas'
        enduser.email = '*****@*****.**'
        enduser.save()

        first_permission = Permission()
        first_permission.user_id = enduser
        first_permission.event = event
        first_permission.id = '93rm151'
        first_permission.save()

        second_permission = Permission()
        second_permission.user_id = enduser
        second_permission.event = event
        second_permission.id = '93rm152'
        second_permission.save()

        saved_company = Company.objects.first()
        self.assertEqual(saved_company, company)

        saved_rooms = Room.objects.all()
        self.assertEqual(saved_rooms.count(), 3)
        self.assertEqual(saved_rooms[0], first_room)
        self.assertEqual(saved_rooms[1], second_room)
        self.assertEqual(saved_rooms[2], third_room)

        saved_event = Event.objects.first()
        self.assertEqual(saved_event, event)

        saved_enduser = EndUser.objects.first()
        self.assertEqual(saved_enduser, enduser)

        saved_permissions = Permission.objects.all()
        self.assertEqual(saved_permissions.count(), 2)
        self.assertEqual(saved_permissions[0], first_permission)
        self.assertEqual(saved_permissions[1], second_permission)
示例#10
0
def sign_up():
    if current_user.is_authenticated:
        return redirect(url_for("public.index"))

    customer_form = CustomerSignUpForm(form_type="customer")
    company_form = CompanySignUpForm(form_type="company")
    error = None
    form_type = None

    if request.method == "POST":
        form_type = request.form["form_type"]

    if form_type == "customer" and customer_form.validate_on_submit():
        username = customer_form.username.data
        password = customer_form.password.data
        nif = customer_form.nif.data
        user = User.get_by_username(username)
        customer = Customer.get_by_nif(nif)
        if user is not None:
            error = f"El nombre de usuario '{username}' ya está siendo utilizado por otro usuario"
        elif customer is not None:
            error = f"El NIF '{nif}' ya ha sido registrado"
        else:
            user = User(username=username, user_type=1)
            user.set_password(password)
            user.save()
            customer = Customer(nif=customer_form.nif.data,
                                name=customer_form.name.data,
                                surname=customer_form.surname.data,
                                email=customer_form.email.data,
                                user_id=user.id)
            customer.save()
            login_user(user, remember=True)
            next_page = request.args.get('next', None)
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('public.index')
            return redirect(next_page)
    if form_type == "company" and company_form.validate_on_submit():
        username = company_form.username.data
        password = company_form.password.data
        cif = company_form.cif.data
        user = User.get_by_username(username)
        company = Company.get_by_cif(cif)
        if user is not None:
            error = f"El nombre de usuario '{username}' ya está siendo utilizado por otro usuario"
        elif company is not None:
            error = f"El CIF '{cif}' ya ha sido registrado"
        else:
            user = User(username=username, user_type=0)
            user.set_password(password)
            user.save()
            company = Company(cif=company_form.cif.data,
                              name=company_form.name.data,
                              address=company_form.address.data,
                              url=company_form.url.data,
                              email=company_form.email.data,
                              company_type=company_form.company_type.data,
                              phone=company_form.phone.data,
                              user_id=user.id)
            company.save()
            login_user(user, remember=True)
            next_page = request.args.get('next', None)
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('public.index')
            return redirect(next_page)
    return render_template("sign_up.html",
                           customer_form=customer_form,
                           company_form=company_form,
                           form_type=form_type,
                           error=error)
示例#11
0
 def add_company(self, code):
     company = Company.objects.filter(code=code)
     if not company:
         save_company = Company(code=code, name="")
         save_company.save()