Ejemplo n.º 1
0
def create_entities(name_to_info):
    """Create the entities from the list of names.
    Returns the dict to map names indices to the Mongo Entity ID
    Args:
    * name_to_info: dict {name:  {'id': index, 'image_url': image_url, 'twitter': <twitter_account>, ...}, ...}
    Returns:
    * index_to_id: dict {name_index: entity.id}
    """
    index_to_id = {}
    for name, attr in name_to_info.items():
        kwargs = {}
        # We may not have the image
        if 'image_url' in attr:
            kwargs['image_url'] = attr['image_url']
        # Social media accounts
        kwargs['accounts'] = {
            k: attr[k]
            for k in attr if k not in ['id', 'image_url']
        }
        ent = Entity(name=name, **kwargs)
        ent.save()
        # Store the indices to link the index from the timecode and the Mongo index
        index = attr['id']
        index_to_id[index] = ent.id
    return index_to_id
Ejemplo n.º 2
0
def index(request):
    try:
        companies = ['Abar Automation', 'ABB', 'Accuworx', 'Adept Technology', 'Advanced Coating Robotics', 'Advanced Robotic Technology', 'Aerotech', 'Aetnagroup SpA', 'AIDA Engineering (JP)', 'Alaark Robotics, Inc.', 'Alfa Automation Technology Ltd', 'Alpha Robotics', 'American Robot', 'American Robot Sales', 'Antenen Research', 'Apex Automation & Robotics', 'Applied Controls Technology', 'ARC Specialities, Inc.', 'Asic Robotics AG', 'Aspect Automation', 'ASS End of Arm Tooling', 'Atlas Copco AB', 'ATM Automation Ltd.', 'ATS Automation Tooling Systems', 'Aurotek Corp', 'Austong Intelligent Robot Technology (CN)', 'Automatted Motion', 'AVN Gruppen', 'AWL Techniek (NV)', 'Axium, Inc.', 'Baumann Automation', 'Bila A/S', 'BL Autotec, Ltd.', 'Bleichert, Inc.', 'Bosch', 'Braas Co', 'Brokk AB', 'Chad Industries', 'Chariot Robotics', 'CIM Systems, Inc.', 'Cimcorp Oy', 'Cloos Schweisstechnik Robotic', 'CMA Robotics', 'Columbia/Okura, LLC', 'Comau', 'Conair Group', 'Creative Automation', 'CT Pack Srl (IT)', 'Daewoo Shipbuilding & Marine Engr', 'Daihen Corp.', 'DanRob', 'Daum + Partner GmbH', 'Dematic GmbH', 'Denso-Wave Robotics', 'DiFacto Robotics & Automation', 'Dong-Hyun Systems (DHS)', 'Dongbu Robot (prev DasaRobot) (KR)', 'Dover Corp (DE-STA-CO)', 'Duepi Automazioni Industriali', 'Durr Systems', 'Dynamic Motion Technology', 'Dynax (JP)', 'Egemin Automation', 'Electroimpact Inc.', 'Electtric80 (IT)', 'Ellison Technologies Automation', 'ENGEL Austria GmbH', 'Erowa Technology', 'EWAB Engineering', 'Fanuc', 'Farr Automation, Inc.', 'Fatronik Technalia', 'FerRobotics GmbH', 'FIPA GmbH', 'FleetwoodGoldcoWyard', 'Flexilane (WIKA Systems) (Denmark)', 'FlexLink', 'Fronius IG', 'Fuji Yusoki Kogyou', 'Gema Switzerland GmbH', 'Gerhard Schubert GmbH', 'GHS Automation', 'Gibotech A/S', 'Glama Engineering', 'GM Global Tech Ops', 'Gotting KG', 'Gudel Robotics', 'H.A.P. GmbH', 'Harly Robotic-Arm Co., Ltd.', 'Harmo (JP)', 'Hitachi Kokusai Electric Inc.', 'Hon Hai Precision (Foxconn)', 'Honeywell', 'Huaxing Machinery Corp', 'Hyundai Heavy Industries (KR)', 'I&J Fisnar', 'IAI America', 'IGM Robotic Systems AG', 'IHI Group', 'Industrial Control Repair']
        for company in companies:
            entity = Entity(name=company)
            entity.save()

    except:
        pass
    context = RequestContext(request, {'categories': [i.category for i in CategoryOrder.objects.all().order_by('order')], 'companies': Entity.objects.all()}) 
    return render_to_response('market/index.html', context)
Ejemplo n.º 3
0
def entity_post(request):
    """
    Create a new Entity with optional predefined GUID.
    If Entity with given GUID already exists, it will be replaced with new data.
    Parameters can be separate parameters in request.POST or
    JSON encoded in a singe "data" parameter.
    Currently successful creation returns always 201 Created.
    """
    try:
        request_data = json.loads(request.POST.get('data', ''))
    except ValueError:
        request_data = {}
    if not request_data: # json data did not exist
        request_data['name'] = request.POST.get('name', '')
        try:
            lat = float(request.POST.get('lat'))
            lon = float(request.POST.get('lon'))
            request_data['geography'] = Point(lon, lat)
        except TypeError:
            data, message = {}, u'No "lat" or "lon" parameters found.'
            return False, data, message
    guid = request.POST.get('guid')
    if guid:
        request_data['guid'] = request.POST.get('guid')
    try: # to get existing Entity from the database
        ent = Entity.objects.get(guid=guid)
        ent.geography = request_data['geography'] # update location
        if 'name' in request_data and request_data['name']:
            ent.name = request_data['name']
    except Entity.DoesNotExist: # if it fails, create a new one
        ent = Entity(**request_data)
        #try:
        #   ent.validate_unique()
        #except ValidationError, e:
        #    data, message = {}, u'Entity with uid "%s" already exists.' % (ent.uid)
        #    return False, data, message
    ent.save()
    data, message = {'guid': ent.guid}, u'201 Created'
    return True, data, message