當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Company類代碼示例

本文整理匯總了Python中models.Company的典型用法代碼示例。如果您正苦於以下問題:Python Company類的具體用法?Python Company怎麽用?Python Company使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Company類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _create_new_company

def _create_new_company(company_name):
    """
    Adds a new record for the given company name to our database.

    The plan is to use the crunchbase/glassdoor API to query for the given
    company name.
    If the calls return info on the company, happily add it
    to our database. If not, we'll assume the given company name is
    faulty, and return an appropriate message to the user.
    """
    crunchbase = CrunchbaseAPI()
    response = crunchbase.get_company_info(company_name)
    if response['exists']:
        # Create the company using the name returned by crunchbase
        # TODO: We should add our own checks.. so a search for '*' doesn't give
        # back 'Google'
        # Or maybe we shouldn't let crunchbase spellcheck?
        company_name = response['name'].lower()

        try:
            # If company already exists, redirect to it
            company = Company.objects.get(name=company_name)
            redirect('/companies/{}'.format(new_company.id))
        except Company.DoesNotExist:
            new_company = Company(name=company_name)
            new_company.save()

            logger.info('New company created: {}'.format(company_name))
            return redirect('/companies/{}'.format(new_company.id))
    else:
        return redirect('/')
開發者ID:njdup,項目名稱:shesays,代碼行數:31,代碼來源:views.py

示例2: test_f_expression_update_attribute

    def test_f_expression_update_attribute(self):
        # F expressions can be used to update attributes on single objects
        test_gmbh = Company.objects.get(name='Test GmbH')
        self.assertEqual(test_gmbh.num_employees, 32)
        test_gmbh.num_employees = F('num_employees') + 4
        test_gmbh.save()
        test_gmbh = Company.objects.get(pk=test_gmbh.pk)
        self.assertEqual(test_gmbh.num_employees, 36)
        
        # F expressions cannot be used to update attributes which are
        # foreign keys, or attributes which involve joins.
        test_gmbh.point_of_contact = None
        test_gmbh.save()
        self.assertEqual(test_gmbh.point_of_contact, None)
        self.assertRaises(ValueError,
                          setattr,
                          test_gmbh, 'point_of_contact', F('ceo'))

        test_gmbh.point_of_contact = test_gmbh.ceo
        test_gmbh.save()
        test_gmbh.name = F('ceo__last_name')
        self.assertRaises(FieldError,
                          test_gmbh.save)
        
        # F expressions cannot be used to update attributes on objects
        # which do not yet exist in the database
        acme = Company(name='The Acme Widget Co.', num_employees=12, 
                       num_chairs=5, ceo=test_gmbh.ceo)
        acme.num_employees = F('num_employees') + 16
        self.assertRaises(TypeError,
                          acme.save)
開發者ID:Leveofan,項目名稱:django-old,代碼行數:31,代碼來源:tests.py

示例3: test_callingGetEmployeesReturnsListOfDicts

	def test_callingGetEmployeesReturnsListOfDicts(self):
		Employee.objects.filter = mock.MagicMock()
		company = Company()
		company.pk = 98
		employee_one = Employee()
		employee_one.pk = 12
		employee_one.user = User()
		employee_one.user.first_name = 'Fornavn'
		employee_one.user.last_name = 'Efternavn'
		employee_one.company = company
		employee_two = Employee()
		employee_two.pk = 13
		employee_two.user = User()
		employee_two.user.first_name = 'Fornavn'
		employee_two.user.last_name = 'Efternavn'
		employee_two.company = company
		Employee.objects.filter.return_value = [employee_one, employee_two]
		employee_one.getMyEmployees = mock.MagicMock()
		employee_one.getMyEmployees.return_value = []
		employee_list = employee_one.getEmployees()
		self.assertEquals(2, len(employee_list))
		self.assertTrue(isinstance(employee_list[0], dict))
		self.assertTrue(isinstance(employee_list[0]['manager'], Employee))
		self.assertEquals(employee_list[0]['manager'].pk, 12)
		self.assertTrue(isinstance(employee_list[0]['employees'], list))
		self.assertEquals(employee_list[0]['manager'].user.first_name, 'Fornavn')
		self.assertEquals(employee_list[0]['manager'].user.last_name, 'Efternavn')
開發者ID:crmtoolboxgit,項目名稱:nxtlvl,代碼行數:27,代碼來源:oldtests.py

示例4: Simulation

class Simulation(object):

    def __init__(self, aggregator, strategy, reserved_resources, sleep_time=0):


        self.aggregator = aggregator

        self.strategy = strategy
# 2 year warm up, and 10 year run
        self.stats = Stats(24, 120)
        self.company = Company(20, reserved_resources, self.strategy, self.stats)
        self.sleep_time = sleep_time
        self.reserved_resources = reserved_resources

        print(sim_to_key(self))

    def run(self):

        for t in range(self.stats.runs):

            self.stats.start_month()

            projects = [generate_project() for _ in range(sample.project_count())]
            self.company.decide_projects(projects)

            used_resources = self.company.workflow.work()

            self.stats.end_month(used_resources, self.company.workflow.average_workload())

            if self.sleep_time > 0:
                sleep(self.sleep_time)

            #print(self.stats.monthly_report())

        self.aggregator.add_result(self)
開發者ID:acrespo,項目名稱:Simulaciones,代碼行數:35,代碼來源:sim.py

示例5: update_company

    def update_company(self, company):
        self.logger.debug("update_company")

        self.logger.info("saving company to database")
        self.logger.debug("company: %s", company)
        Company.update(
                code=company.code, name=company.name, nif=company.nif,
                address=company.address, city=company.city,
                state=company.state, zip_code=company.zip_code,
                phone=company.phone, contact_person=company.contact_person,
                alternative_phone=company.alternative_phone,
                fax=company.fax, email=company.email, iban=company.iban,
                bank_name=company.bank_name, payment_type=company.payment_type,
                expiration_days=company.expiration_days,
                first_payment_day=company.first_payment_day,
                second_payment_day=company.second_payment_day,
                third_payment_day=company.third_payment_day
                ).execute()

        self.logger.info("updating company to model")
        tree_iter = self.get_iter_from_selected_row(company.code)
        self.companies_model.set(
                tree_iter,
                [self.CODE_COLUMN, self.NAME_COLUMN, self.NIF_COLUMN],
                [company.code, company.name, company.nif]
                )
開發者ID:rmunoz,項目名稱:sigg,代碼行數:26,代碼來源:companies_manager_window.py

示例6: create

    def create(self, request, **kwargs):
        serializer = CompanySerializer(data=request.data)
        if serializer.is_valid():
            user = save_user(request.data, UserPermissions.IS_COMPANY)
            city = City(**request.data["city"])
            company = Company(
                name=request.data["name"],
                type=UserType.COMPANY,
                address=request.data["address"],
                identityDoc=request.data["identityDoc"],
                phone=request.data["phone"],
                city=city,
                user=user,
            )

            company.save()
            return Response(
                {
                    "status": "SUCCESS",
                    "msg_status": "Estabecimiento creado satisfactoriamente. Puede ingresar con su nueva contrasena.",
                }
            )
        else:
            messages = []
            make_error(serializer.errors.values(), messages)
            return Response({"status": "FAILURE", "msg_status": messages})
開發者ID:emosquera,項目名稱:ticketIntelligence,代碼行數:26,代碼來源:viewsets.py

示例7: admin_add_company

def admin_add_company():
    data = json.loads(request.data)
    linkedin_id = data.get('linkedin_id')
    name = data.get('name')
    crunchbase_url = data.get('crunchbase_url')
    if not linkedin_id or linkedin_id == "":
        linkedin_id = gen_fake_linkedin_id()
    company = Company(linkedin_id, name)
    company.crunchbase_url = crunchbase_url
    db.session.add(company)
    db.session.commit()
    print ' adding new company for rescraping: ' + name.encode('utf8') + ' --> ' + linkedin_id
    print '              new company id = ' + str(company.id)
    if crunchbase_url and crunchbase_url != "":
        mode = FROM_URL_RESCRAPE_MODE
    else:
        mode = DEFAULT_RESCRAPE_MODE
    rescrape_companies_from_list([company], mode=mode)
    # TODO FUCK FUCK FUCK FUCK HEROKU for not allowing > 1 thread
    # WHAT IN THE FUCKING FUCK.....
    #times_left = 100
    #while not company.is_feed_ready and times_left >= 0:
    #    times_left -= 1 # this is to make sure this doesn't become an infinite for-loop
    #    time.sleep(5)
    #    db.session.commit() # Retarded way to start a new transaction because FUCK sqlalchemy...
    #    print '       ... waiting for scraper callback --> is_feed_ready ' + str(company.is_feed_ready)
    resp = json.dumps({'status': 'ok', 'company_id': company.id})
    return resp 
開發者ID:thejessma,項目名稱:startuplinx,代碼行數:28,代碼來源:endpoints.py

示例8: test_callingGetEmployeesCallsFilterOnEmployeeWithCompanyPkAsArgumentAndIsMangerEqualToTrue

	def test_callingGetEmployeesCallsFilterOnEmployeeWithCompanyPkAsArgumentAndIsMangerEqualToTrue(self):
		employee = Employee()
		company = Company()
		company.pk = 8
		employee.company = company
		with mock.patch.object(Employee, 'objects') as query_mock:
			employee.getEmployees()
			query_mock.filter.assert_called_with(company__pk=company.pk, is_manager=True)
開發者ID:crmtoolboxgit,項目名稱:nxtlvl,代碼行數:8,代碼來源:oldtests.py

示例9: create

 def create(self, validated_data):
     company = Company(
         name=validated_data['name'],
         alias=validated_data['name'].lower(),
         active=validated_data['active']
     )
     company.save()
     return company
開發者ID:JohnProg,項目名稱:agenda_services,代碼行數:8,代碼來源:serializers.py

示例10: createDB

def createDB():
	print "Creating the initial db"
	Company.create_table()
	NewsSource.create_table()
	News.create_table()
	Price.create_table()
	OpinionAPI.create_table()
	OpinionAPIResponse.create_table()
開發者ID:Aaronmyster,項目名稱:newtsocks,代碼行數:8,代碼來源:createDatabase.py

示例11: delete_company

    def delete_company(self, company):
        self.logger.debug("delete_company")

        self.logger.info("deleting company from database")
        Company.delete().where(Company.code == company.code).execute()

        self.logger.info("removing company from model")
        tree_iter = self.get_iter_from_selected_row(company.code)
        self.companies_model.remove(tree_iter)
開發者ID:rmunoz,項目名稱:sigg,代碼行數:9,代碼來源:companies_manager_window.py

示例12: company_insert

 def company_insert(self, request):
     
     if request.from_datastore:
         my_company = request
     else:
         my_company = Company(parent=main.PARENT_KEY, name=request.name, bio=request.bio, logo=request.logo,
                              jobs=request.jobs, majors=request.majors, table=request.table, website=request.website)
         
     my_company.put()
     return my_company
開發者ID:11samype,項目名稱:rose_career_fair,代碼行數:10,代碼來源:career_fair_api.py

示例13: setUp

    def setUp(self):
        self.region = Region(name="test_region")
        self.region.save()

        self.company = Company(code="1001", name="test_company", region=self.region)
        self.company.save()
        self.company2 = Company(code="1002", name="test_company_2", region=self.region)
        self.company2.save()

        self.store = Store(code="10011001", name="test_store", company=self.company)
        self.store.save()
開發者ID:xhacker5000,項目名稱:wandoujia-oem,代碼行數:11,代碼來源:tests.py

示例14: post

 def post(self):
    if(Company.exists(request.form['name'])):
       return jsonify(message='Company exists')
    else:
       company = Company()
       company.name = request.form['name']
       company.tin = request.form['tin']
       company.address = request.form['address']
       db.session.add(company)
       db.session.commit()
       return jsonify(company.serialize)
開發者ID:sephtiger,項目名稱:txmo-backend,代碼行數:11,代碼來源:application.py

示例15: input_companies

def input_companies():
  ''' Creates the company models for each S&P 500 company'''
  
  yahoo_data = yahooDataRetriever.get_dict_500_companies(name_file)
  
  for i in yahoo_data.keys():
    if len(Company.objects.filter(ticker = i)) > 0:
      continue
    c = Company()
    c.name = yahoo_data.get(i)
    c.ticker = i
    c.save()
    print "## Saved Company Object for: " + i
開發者ID:zinglax,項目名稱:cmsc424Site,代碼行數:13,代碼來源:dataloader.py


注:本文中的models.Company類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。