Example #1
0
def create_sections_and_cell_for_workshop_three():
    workshop_three = WorkShop.objects.get(number=3)

    Section.objects.bulk_create([
        Section(workshop=workshop_three, name='Секция 3-1', number=1),
        Section(workshop=workshop_three, name='Секция 3-2', number=2),
        Section(workshop=workshop_three, name='Секция 3-3', number=3),
        Section(workshop=workshop_three, name='Секция 3-4', number=4),
        Section(workshop=workshop_three, name='Секция 3-5', number=5),
        Section(workshop=workshop_three, name='Секция 3-6', number=6),
    ])
    Location.objects.bulk_create([
        Location(section=section)
        for section in Section.objects.filter(workshop=workshop_three)
    ])

    for section in Section.objects.filter(workshop=workshop_three):
        SowAndPigletsCell.objects.bulk_create([
            SowAndPigletsCell(workshop=workshop_three,
                              section=section,
                              number=cellNumber)
            for cellNumber in range(1, 46)
        ])
        Location.objects.bulk_create([
            Location(sowAndPigletsCell=cell)
            for cell in SowAndPigletsCell.objects.filter(
                workshop=workshop_three, section=section)
        ])
Example #2
0
def addUser(request):
    form = UserForm(request.POST)

    if form.is_valid():
        try:
            with transaction.atomic():
                enterprise = Enterprise()
                enterprise.save()
                request.session['idEnterprise'] = enterprise.id

                location = Location(enterprise=enterprise,
                                    lat=0,
                                    lng=0,
                                    name='Main Office')
                location.save()

                user = User(location=location,
                            email=form.cleaned_data['email'],
                            password=form.cleaned_data['password'])
                user.save()
                request.session['idUser'] = user.id

                profile = Profile(user=user, role="Administrator")
                profile.save()

                return render(request, 'users/dashboard.html')

        except Exception as e:
            print(e)
            messages.error(request, 'Sorry, Internal Error')

    else:
        messages.error(request, 'Please fill the form')
        return HttpResponseRedirect('/signup')
Example #3
0
    def _get_loc(pc, coll):
        _new_loc = None
        _loc = coll.find_one({'postal code': pc})
        if _loc:
            district = ', %s' % _loc['admin name3'] if _loc[
                'admin name3'] else ''
            place_name = '%s%s' % ((_loc['place name'], district))
            place_name = place_name.replace(' Ward',
                                            '')  #.replace(' City', '')
            loc_type = POSTCODE if len(pc) > 4 else POSTCODEDISTRICT

            _new_loc = Location(
                id=_loc['postal code'].replace(' ', ''),
                postcode=_loc['postal code'],
                place_name=place_name,
                lat_lon=[float(_loc['latitude']),
                         float(_loc['longitude'])],
                loc_type=loc_type,
                accuracy=_loc['accuracy'],
                district=_loc['admin name3'],
                country_code=_loc['admin code1'])
            _new_loc.save()

        print _new_loc, _new_loc.loc_type
        return _new_loc
Example #4
0
def filter_national(locations):
    from locations.models import Location

    def is_national(location):
        if location.get('type') == 'National':
            return True
        else:
            return False

    national_data = list(filter(is_national, locations))
    if len(national_data) != 1:
        log_internal_error('loading national location',
                           'Expected to find 1 national location instead found %s' % len(national_data))
        return Location()
    else:
        return Location().set_values(national_data[0])
Example #5
0
 def get_locations(cls, auth_token):
     locations_data = request_handler.load_financial_report_locations(
         auth_token).json()["locations"]
     locations = []
     for location in locations_data:
         locations.append(Location().set_values(location))
     return locations
Example #6
0
    def test_no_state_unicode(self):
        locate = Location(
            city='Rome',
            country='Italy',
        )

        locate.save()

        self.assertEqual(locate.__str__(), 'Rome, Italy')
Example #7
0
def test_checkins(client, admin_client):
    url = reverse('webapp.checkins')
    user = User.objects.get(username='******')
    l = Location(user=user, name='Someplace', lat=100, lon=200,
                 address='Someplace St')
    l.save()

    resp = admin_client.get(url)
    assertTemplateUsed(resp, 'checkins.html')
    assert resp.context.get('locations')[0] == l
Example #8
0
    def test_state_unicode(self):
        locate = Location(
            city='Loveland',
            state='CO',
            country='USA',
        )

        locate.save()

        self.assertEqual(locate.__str__(), 'Loveland, CO')
Example #9
0
def create_sections_and_cell_for_workshop_two():
    workshop_two = WorkShop.objects.get(number=2)

    Section.objects.bulk_create([
        Section(workshop=workshop_two, name='Секция 2-1', number=1),
        Section(workshop=workshop_two, name='Секция 2-2', number=2)
    ])
    Location.objects.bulk_create([
        Location(section=section)
        for section in Section.objects.filter(workshop=workshop_two)
    ])
Example #10
0
    def test_geolocate(self):
        locate = Location(
            city='Loveland',
            state='CO',
            country='USA',
        )

        locate.save()

        self.assertEqual(locate.latitude, 40.3977612)
        self.assertEqual(locate.longitude, -105.0749801)
Example #11
0
def create_sections_and_cell_for_workshop_one():
    workshop_one = WorkShop.objects.get(number=1)

    Section.objects.bulk_create([
        Section(workshop=workshop_one, name='Змейка', number=1),
        Section(workshop=workshop_one, name='Ряд осеменения', number=2),
        Section(workshop=workshop_one, name='Групповые клетки', number=3)
    ])
    Location.objects.bulk_create([
        Location(section=section)
        for section in Section.objects.filter(workshop=workshop_one)
    ])
Example #12
0
def filter_sites(locations):
    from locations.models import Location

    def is_site(location):
        if location.get('type') == 'Site':
            return True
        else:
            return False

    site_data = filter(is_site, locations)
    sites = []
    for site in site_data:
        sites.append(Location().set_values(site))
    return sites