File size: 2,002 Bytes
7c53168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from django.shortcuts import render
from django.http import JsonResponse, HttpResponse
import requests
import json
import base64

authToken = 'fab57498544244e38bfc2741880f8d61:ed9628295b0642e1b38308795c9cdadd58012df4ceb84a3b9d441c017a1eeac0'

def home(request):
    message = "Welcome at home!"
    return JsonResponse({'message': message})


def establishment_List(request):
    global authToken
    url = "https://101smokeshop-uat.revelup.com/enterprise/Establishment/?order_by=id&limit=10&offset=0"
    headers = {
        'API-AUTHENTICATION': authToken
    }
    response = requests.request("GET", url, headers=headers)
    data = response.json()["objects"]
    urlBase = "https://101smokeshop-uat.revelup.com"
    for i in range(len(data)):
        try:
            imgData = requests.request("GET", urlBase+data[i]["logo_img"], headers=headers).json()
            print(imgData)
            data[i]["logo_img"] = imgData["image_url"]
        except:
            pass
        try:
            data[i]["address"] = requests.request("GET", urlBase+data[i]["address"], headers=headers).json()
        except:
            pass
    return JsonResponse({"data": data})


def resources_forward(request, resource_name,image_id):
    url = "https://101smokeshop-uat.revelup.com/resources/"+resource_name+"/"+image_id
    headers = {
        'API-AUTHENTICATION': authToken
    }
    response = requests.request("GET", url, headers=headers)
    imageUrl = response.json()["image_url"]
    response = requests.request("GET", imageUrl)
    return HttpResponse(response.content, content_type=response.headers['Content-Type']) 

def product_category(request):
    global authToken
    url = "https://101smokeshop-uat.revelup.com/products/ProductCategory/"
    headers = {
        'API-AUTHENTICATION': authToken
    }
    response = requests.request("GET", url, headers=headers)
    data = response.json()["objects"]
    return JsonResponse({"data": data})