Esempio n. 1
0
def add_employee_xrequest():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    # add employee request to database
    # declare the Request Form
    form = RequestForm(request.form)
    form.stock_item.choices = [(x.id, x) for x in Stock.query.all()]
    msg = None
    # check if both http method is POST and form is valid on submit
    if form.validate_on_submit():
        # assign form data to variables
        stock_item = request.form.get('stock_item', '', type=int)
        quantity = request.form.get('quantity', '', type=int)
        # see if request already exists
        # TODO: filter by datecreated as well
        # request = Request.query.filter_by(user_id=current_user.id, product_id=stock_item, quantity = quantity).first()
        xrequest = Request(current_user.id, stock_item, 1, quantity, 1)
        # check if request is in bounds
        stock = Stock.query.filter_by(id=stock_item).first()
        if quantity <= stock.stocklevel:
            xrequest.save()
            flash('Request successfully created!')
        else:
            flash(
                f'I am sorry but we have only {stock.quantity} {stock} available'
            )
    else:
        flash('I am sorry but the details you entered cannot be saved :(')
    return redirect('/psalm2vs8/employee-requests')
Esempio n. 2
0
 def test_create_request_with_details(self):
     author = User(username='******')
     author.save()
     title = "hello world"
     description = "hello world"
     request = Request(title=title, description=description, requested_by=author)
     request.save()
Esempio n. 3
0
def request_process(request):
    account = request.POST['requested_by']
    instructor = request.POST['instructor']
    reason = request.POST['reason']
    room = request.POST['room']
    date_needed = datetime.strptime(request.POST['date-needed'], "%Y-%m-%d")
    time_in = request.POST['time-in']
    time_out = request.POST['time-out']
    devices = request.POST.getlist('device[]')
    request_number = request.POST['request-number']
    print(devices)

    req = Request()

    req.requested_by = Account.objects.get(name=account)
    req.instructor_in_charge = Instructor.objects.get(name=instructor)
    req.reason = reason
    req.room = room
    req.request_number = request_number
    req.date_needed = date_needed
    req.date_borrowed = datetime.strftime(date.today(), '%Y-%m-%d')
    req.time_in = time_in
    req.time_out = time_out
    req.returned = False
    req.approved = False
    req.save()

    for device in devices:
        req.device.add(Device.objects.get(name=device))

    req.save()

    return redirect('/request-success/' + request_number)
Esempio n. 4
0
def importTrainlineInfo():
    trainlineRESTApi = RESTApi(name='TrainlineRESTApi',
                               BaseUrl='https://www.trainline.eu/api/v5_1/',
                               APIKey='A8fQLJDF94cPUKEu3Vpi')
    trainlineRESTApi.save()
    paramsgetStation = {
        'q': 'Place',
    }
    getStationInformation = Request(
        name='getStationInformationTrainline',
        description='Get information about a station',
        PartToaddToBaseUrl='stations?context=search',
        funcToExtractDataFromJsonName='getStationInformation',
        ParamsOrDataDictStructure=paramsgetStation,
        typeRequests='GET',
        RApi=trainlineRESTApi)

    dataFindTrip = {
        "local_currency": "EUR",
        "search": {
            "passenger_ids": ["314892886"],
            "card_ids": ["14127110"],
            "departure_station_id": 33349,
            "arrival_station_id": 6627,
            "departure_date": "2021-03-29T00:00:00+01:00",
            "systems": []
        }
    }

    headersTrainline = {
        'Accept':
        'application/json',
        'User-Agent':
        'CaptainTrain/5221(d109181b0) (iPhone8,4; iOS 13.1.2; Scale/2.00)',
        'Accept-Language':
        'es',
        'Content-Type':
        'application/json; charset=UTF-8',
        'Host':
        'www.trainline.eu',
        'authorization':
        'Token token="{token}"'.format(token=trainlineRESTApi.APIKey),
    }

    getbustrainTripsInformation = Request(
        name='getbustrainTripsInformationTrainline',
        description='Get trips information by train or bus',
        PartToaddToBaseUrl='search',
        funcToExtractDataFromJsonName='findbustrainTrips',
        ParamsOrDataDictStructure=dataFindTrip,
        typeRequests='POST',
        headers=headersTrainline,
        RApi=trainlineRESTApi)
    getStationInformation.save()
    getbustrainTripsInformation.save()
Esempio n. 5
0
    def insert_one(self, request):
        """Insert a New Request"""
        request = Request(
            uri=request["uri"],
            method=request["method"],
            headers=request["headers"],
            body=request["body"],
            status=request["status"],
            endpoint=Endpoint.objects.get(pk=request["endpoint_id"]))

        request.save()
        return False if request.pk is None else request
Esempio n. 6
0
 def test_create_request_rapidly(self):
     author = User(username='******')
     author.save()
     title = "hello world"
     request = Request(title=title, created_by=author)
     request.save()
     all_requests = Request.objects.all()
     self.assertEquals(len(all_requests), 1)  # assert there is only one request
     self.assertEquals(request, all_requests[0])  # assert this is the first request
     self.assertEquals(request.title, title)  # assert title
     self.assertEquals(request.slug, slugify(title))  # assert slug
     self.assertEquals(request.created_by, author)  # assert author
     self.assertEquals(request.status, 100)  # default status is opened STATUS_OPENED=100
     self.assertEquals(request.created.day, timezone.now().day)  # posted today
     self.assertEquals(request.publish, True)  # default is published
     self.assertSequenceEqual(request.collaborators.all(), [])  # assert there are no collaborators
     self.assertSequenceEqual(request.skills.all(), [])  # assert skills are empty
     self.assertEquals(request.type, None)  # assert type in not specified
Esempio n. 7
0
def get_pedido(request, id_loja):
    try:
        req = Request.objects.get(id=request.session['pedido'])
        try:
            cliente = request.user.cliente
        except:
            cliente = None
        req.cliente = cliente
        req.save()
        return req
    except (Exception, ):
        estabelecimento = Estabelecimento.objects.get(id=id_loja)
        try:
            cliente = request.user.cliente
        except:
            cliente = None
        pedido = Request(cliente=cliente, estabelecimento=estabelecimento)
        pedido.save()
        request.session['pedido'] = pedido.id
        return pedido
Esempio n. 8
0
def project_create(request):
    # todo there is no validation here and... BETTER TO POST DATA WITH POST REQUEST FOLLOWING THE REST CONVENTION
    if request.POST:
        if request.is_ajax():
            title = request.POST.get('title')
            category_name = request.POST.get('category')
            description = request.POST.get('description')
            skills = request.POST.getlist('skills[]')

            category = None
            request_instance = None
            if category_name:
                category = get_object_or_404(RequestCategory, slug=category_name)

            if title and category:
                request_instance = Request(title=title, created_by=request.user)
                request_instance.save()
                request_instance.type = category
                request_instance.save()
            if skills and request_instance:
                for id in skills:
                    tag = SkillTag.objects.get(pk=id)
                    if tag:
                        request_instance.skills.add(tag)
            if description and request_instance:
                request_instance.description = description

            if request_instance:
                request_instance.save()
                return JsonResponse({'status': 'success'})
            else:
                return JsonResponse({'status': 'error'})

    else:
        return HttpResponseRedirect("/dashboard/")
Esempio n. 9
0
def importBlablacarInfo():
    blablaCarRESTApi = RESTApi(name='BlablaCarRESTApi',
                               BaseUrl='https://public-api.blablacar.com',
                               APIKey='UIbM2vkhEdrrTLiLnrQkBqgPxrv7S4mI')
    blablaCarRESTApi.save()
    paramsblabla = {
        'key': 'example',
        'from_coordinate': '41.3887900,2.1589900',
        'to_coordinate': '40.416775,-3.703791',
        'currency': 'EUR',
        'start_date_local': '2021-05-05T00:00:00',
        'end_date_local': '2021-05-06T00:00:00'
    }

    findBlablaTrips = Request(
        name='getBlablaCarTrips',
        description='Find blablacar´s trips with dates and coordinates',
        PartToaddToBaseUrl='/api/v3/trips',
        funcToExtractDataFromJsonName='findBlablaTrips',
        ParamsOrDataDictStructure=paramsblabla,
        typeRequests='GET',
        RApi=blablaCarRESTApi)

    findBlablaTrips.save()
Esempio n. 10
0
 def process_request(self, request):
     req = Request(request=request)
     if request.user.is_authenticated():
         req.priority = 1
     req.save()
     return None
Esempio n. 11
0
def importSkyscannerInfo():

    skyscannerRESTApi = RESTApi(
        name='SkyscannerRESTApi',
        BaseUrl='https://partners.api.skyscanner.net/apiservices/',
        APIKey='prtl6749387986743898559646983194')
    skyscannerRESTApi.save()
    paramsGetSkyscToken = {
        'apiKey': 'example',
    }

    datagetSessionKey = {
        'cabinclass': 'Economy',
        'country': 'ES',
        'currency': 'EUR',
        'locale': 'es-ES',
        'locationSchema': 'iata',
        'originplace': 'origin',
        'destinationplace': 'destination',
        'outbounddate': 'outbounddate',
        'adults': '1',
        'children': '0',
        'infants': '0',
        'apikey': 'example'
    }

    getFlightInformationparams = {
        'stops': 0,  #Sólo busco vuelos directos
        'apiKey': 'token',
    }

    getGeoCatalogparams = {
        'apiKey': 'token',
    }

    getToken = Request(name='getTokenSkyscanner',
                       description='Get a token with the API-key',
                       PartToaddToBaseUrl='token/v2/gettoken',
                       funcToExtractDataFromJsonName='getTokenOrFlightData',
                       ParamsOrDataDictStructure=paramsGetSkyscToken,
                       typeRequests='GET',
                       RApi=skyscannerRESTApi)

    getSessionKey = Request(
        name='getSessionKeySkyscanner',
        description='Get the session key',
        PartToaddToBaseUrl='pricing/v1.0',
        funcToExtractDataFromJsonName='getSessionKey',
        ParamsOrDataDictStructure=datagetSessionKey,
        typeRequests='POST',
        headers={'Content-Type': 'application/x-www-form-urlencoded'},
        RApi=skyscannerRESTApi)

    getFlightsInformation = Request(
        name='getFlightsInformationSkyscanner',
        description='Get information about flights',
        PartToaddToBaseUrl='pricing/v1.0/',
        funcToExtractDataFromJsonName='getFlightInformation',
        ParamsOrDataDictStructure=getFlightInformationparams,
        typeRequests='GET',
        RApi=skyscannerRESTApi)  ##

    getGeoCatalogInformation = Request(
        name='getSkyscannerGeocatalog',
        description='Get information about airports',
        PartToaddToBaseUrl='geo/v1.0',
        funcToExtractDataFromJsonName='getAirportsData',
        ParamsOrDataDictStructure=getGeoCatalogparams,
        typeRequests='GET',
        RApi=skyscannerRESTApi)

    getToken.save()
    getSessionKey.save()
    getFlightsInformation.save()
    getGeoCatalogInformation.save()