Skip to content

Commit 2ce927f

Browse files
committed
main files
0 parents  commit 2ce927f

91 files changed

Lines changed: 62625 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/__init__.py

Whitespace-only changes.

api/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

api/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ApiConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'api'

api/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

api/serializers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from rest_framework.serializers import ModelSerializer
2+
from rest_framework import serializers
3+
from items.models import Item, CPUType
4+
# , CPU, HDDType, Model, Image, Manufacturer
5+
from datetime import datetime
6+
7+
8+
class CPUTypeSerializer(ModelSerializer):
9+
10+
class Meta:
11+
model = CPUType
12+
exclude = ['name']
13+
14+
15+
class ItemSerializer(ModelSerializer):
16+
17+
class Meta:
18+
model = Item
19+
exclude = ['price', 'disc', 'screen_size', 'illuminated_keyboard',
20+
'original_windows', 'rotation', 'touch_screen']
21+
depth = 2

api/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

api/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls import path, re_path
2+
from . import views
3+
4+
urlpatterns = [
5+
re_path(
6+
r'^items/(?P<typee>(\d,?){0,30})/(?P<cpu>(\d,?){0,30})/(?P<cpu_type>(\d,?){0,30})/(?P<ram>(\d,?){0,30})/(?P<hdd>(\d,?){0,30})/(?P<gpu>(\d,?){0,30})/$', views.Items.as_view()),
7+
re_path(r'cputypes/(?P<id>(\d,?){0,30})/$', views.cpuTypes),
8+
]

api/views.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from items.models import Item, CPUType
2+
from rest_framework.decorators import api_view
3+
from rest_framework.response import Response
4+
from .serializers import ItemSerializer, CPUTypeSerializer
5+
from django.db.models import Q
6+
from backend.utility import proccessStrParams
7+
8+
from rest_framework import generics
9+
10+
11+
# @api_view(['GET'])
12+
# def items(req, typee, cpu, cpu_type, ram, hdd, gpu):
13+
# type_list, cpu_list, cpu_type_list, ram_list, hdd_list, gpu_list = proccessStrParams(
14+
# typee,
15+
# cpu,
16+
# cpu_type,
17+
# ram,
18+
# hdd,
19+
# gpu
20+
# )
21+
22+
# type_list = Q(model__typee__id__in=type_list) if type_list else Q(
23+
# model__typee__id__isnull=False)
24+
25+
# cpu_list = Q(cpu_type__name__id__in=cpu_list) if cpu_list else Q(
26+
# cpu_type__name__id__isnull=False)
27+
28+
# cpu_type_list = Q(cpu_type__id__in=cpu_type_list) if cpu_type_list else Q(
29+
# cpu_type__id__isnull=False)
30+
31+
# ram_list = Q(ram_type__id__in=ram_list) if ram_list else Q(
32+
# ram_type__id__isnull=False)
33+
34+
# hdd_list = Q(hdd_type__id__in=hdd_list) if hdd_list else Q(
35+
# cpu_type__id__isnull=False)
36+
37+
# gpu_list = Q(gpu__id__in=gpu_list) if gpu_list else Q(
38+
# gpu__id__isnull=False)
39+
40+
# items = Item.objects.filter(
41+
# type_list & cpu_list & cpu_type_list & ram_list & hdd_list & gpu_list)
42+
43+
# serializer = ItemSerializer(items, many=True)
44+
45+
# return Response(serializer.data)
46+
47+
48+
class Items(generics.ListAPIView):
49+
# queryset = Item.objects.all()
50+
serializer_class = ItemSerializer
51+
52+
def get_queryset(self):
53+
type_list, cpu_list, cpu_type_list, ram_list, hdd_list, gpu_list = proccessStrParams(
54+
self.kwargs['typee'],
55+
self.kwargs['cpu'],
56+
self.kwargs['cpu_type'],
57+
self.kwargs['ram'],
58+
self.kwargs['hdd'],
59+
self.kwargs['gpu']
60+
)
61+
62+
type_list = Q(model__typee__id__in=type_list) if type_list else Q(
63+
model__typee__id__isnull=False)
64+
65+
cpu_list = Q(cpu_type__name__id__in=cpu_list) if cpu_list else Q(
66+
cpu_type__name__id__isnull=False)
67+
68+
cpu_type_list = Q(cpu_type__id__in=cpu_type_list) if cpu_type_list else Q(
69+
cpu_type__id__isnull=False)
70+
71+
ram_list = Q(ram_type__id__in=ram_list) if ram_list else Q(
72+
ram_type__id__isnull=False)
73+
74+
hdd_list = Q(hdd_type__id__in=hdd_list) if hdd_list else Q(
75+
cpu_type__id__isnull=False)
76+
77+
gpu_list = Q(gpu__id__in=gpu_list) if gpu_list else Q(
78+
gpu__id__isnull=False)
79+
80+
queryset = Item.objects.filter(
81+
type_list & cpu_list & cpu_type_list & ram_list & hdd_list & gpu_list)
82+
83+
return queryset
84+
85+
86+
@api_view(['GET'])
87+
def cpuTypes(req, id):
88+
list, = proccessStrParams(id)
89+
90+
list = Q(name__id__in=list)
91+
92+
cpuTypes = CPUType.objects.filter(list)
93+
94+
serializer = CPUTypeSerializer(cpuTypes, many=True)
95+
96+
return Response(serializer.data)

authentication/__init__.py

Whitespace-only changes.

authentication/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
from .models import User
4+
5+
6+
admin.site.register(User)

0 commit comments

Comments
 (0)