Skip to content
This repository has been archived by the owner on Sep 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #29 from superproyectos/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
superproyectos authored Dec 9, 2018
2 parents 5d72ed3 + 3b207c6 commit 1474647
Show file tree
Hide file tree
Showing 185 changed files with 8,420 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added api/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added api/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added api/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file added api/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file added api/__pycache__/views.cpython-35.pyc
Binary file not shown.
Binary file added api/migrations/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
path('', include('rest_auth.urls')),
path('registration/', include('rest_auth.registration.urls')),
path('collection_address/', include('collection_address.urls')),
path('delivery_address/', include('delivery_address.urls')),
path('collection_order/', include('collection_order.urls')),
path('package/', include('package.urls')),
path('v/logout/', logout, name = "logout"),
path('disable/', disable, name = "disable"),
]
Binary file not shown.
Binary file added collection_address/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added collection_address/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file not shown.
Binary file added collection_address/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions collection_address/migrations/0003_auto_20181206_1903.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.1.3 on 2018-12-06 23:03

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('collection_address', '0002_collectionaddress_user_id'),
]

operations = [
migrations.AlterField(
model_name='collectionaddress',
name='user_id',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='collection_address', to=settings.AUTH_USER_MODEL),
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions collection_address/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.db import models
from user.models import User
from django.contrib.auth import get_user_model


class CollectionAddress(models.Model):
collection_address_id = models.AutoField(primary_key = True)
user_id = models.ForeignKey(User, null = True, blank = False, on_delete = models.CASCADE)
user_id = models.ForeignKey(get_user_model(), null = True, blank = False,
on_delete = models.CASCADE, related_name = "collection_address")
line1 = models.CharField(max_length = 35, null = True)
line2 = models.CharField(max_length = 35, null = True)
zipCode = models.CharField(max_length = 35, null = True)
Expand Down
5 changes: 3 additions & 2 deletions collection_address/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
class CollectionAddressSerializer(ModelSerializer):
class Meta:
model = CollectionAddress
fields = ('collection_address_id', 'user_id', 'line1', 'line2', 'zipCode', 'city', 'country', 'user_id')
fields = ('collection_address_id', 'line1', 'line2', 'zipCode', 'city', 'country', 'user_id_id')


class UpdateCollectionAddress(ModelSerializer):
class Meta:
model = CollectionAddress
fields = ('user_id',)
fields = ('collection_address_id',)



4 changes: 3 additions & 1 deletion collection_address/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .views import CollectionAddressCreate, CollectionAddressRetrieve, CollectionAddressAdd
from user.views import RetrieveCollectionAddresses
from django.urls import path

urlpatterns = [
path('create', CollectionAddressCreate.as_view()),
path('create/', CollectionAddressCreate.as_view()),
path('add/<pk>', CollectionAddressAdd.as_view()),
path('view', CollectionAddressRetrieve.as_view()),
path('getAll', RetrieveCollectionAddresses.as_view()),
]
10 changes: 7 additions & 3 deletions collection_address/views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
from rest_framework import generics
from . import models
from . import serializers
from user.models import User
from collection_address.models import CollectionAddress
from rest_framework.response import Response


class CollectionAddressCreate(generics.ListCreateAPIView):
queryset = models.CollectionAddress.objects.all()
serializer_class = serializers.CollectionAddressSerializer

def create(self, request, *args, **kwargs):
request.data["collection_address_id"] = request.collection_address.collection_address_id
return super(generics.ListCreateAPIView, self).create(request, *args, **kwargs)


class CollectionAddressAdd(generics.UpdateAPIView):
queryset = User.objects.all()
queryset = CollectionAddress.objects.all()
serializer_class = serializers.UpdateCollectionAddress

def update(self, request, *args, **kwargs):
instance = self.get_object()
instance.user_id = request.data.get("user_id")
instance.collection_address_id = request.data.get("collection_address_id")
instance.save()
serializer = self.get_serializer(instance)
serializer.is_valid(raise_exception = True)
Expand Down
Binary file added collection_order/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added collection_order/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions collection_order/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.1.3 on 2018-12-06 23:24

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('collection_address', '0003_auto_20181206_1903'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('delivery_address', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='CollectionOrder',
fields=[
('collection_order_id', models.AutoField(primary_key=True, serialize=False)),
('recipientsName', models.CharField(max_length=35)),
('recipientsSurname', models.CharField(max_length=35)),
('collection_address_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='collection_address', to='collection_address.CollectionAddress')),
('delivery_address_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='delivery_address', to='delivery_address.DeliveryAddress')),
('user_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='user', to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
10 changes: 5 additions & 5 deletions collection_order/models.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from django.db import models
from user.models import User
from collection_address.models import CollectionAddress
from package.models import Package
from delivery_address.models import DeliveryAddress


# Create your models here.

class CollectionOrder(models.Model):
collection_order_id = models.AutoField(primary_key = True)
user_id = models.OneToOneField(User, on_delete = models.SET_NULL, null = True)
package_id = models.ForeignKey(Package, on_delete = models.CASCADE, null = False, blank = False)
collection_address_id = models.OneToOneField(CollectionAddress, on_delete = models.CASCADE, null = True)
delivery_address_id = models.OneToOneField(DeliveryAddress, on_delete = models.CASCADE, null = True)
user_id = models.ForeignKey(User, on_delete = models.SET_NULL, null = True, related_name = "user")
collection_address_id = models.ForeignKey(CollectionAddress, on_delete = models.CASCADE,
null = True, related_name = "collection_address")
delivery_address_id = models.ForeignKey(DeliveryAddress, on_delete = models.CASCADE,
null = True, related_name = "delivery_address")
recipientsName = models.CharField(max_length = 35)
recipientsSurname = models.CharField(max_length = 35)
25 changes: 25 additions & 0 deletions collection_order/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from rest_framework.serializers import ModelSerializer
from package.serializers import PackageSerializer
from delivery_address.serializers import DeliveryAddressSerializer
from collection_address.serializers import CollectionAddressSerializer
from .models import CollectionOrder


class CollectionOrderSerializer(ModelSerializer):
order = PackageSerializer(many = True, read_only = True)

class Meta:
model = CollectionOrder
fields = ('collection_order_id', 'user_id', 'collection_address_id', 'delivery_address_id',
'recipientsName', 'recipientsSurname', 'order',)


class CollectionOrderSerializerExtended(ModelSerializer):
order = PackageSerializer(many = True, read_only = True)
delivery_address_id = DeliveryAddressSerializer(many = False, read_only = True)
collection_address_id = CollectionAddressSerializer(many = False, read_only = True)

class Meta:
model = CollectionOrder
fields = ('collection_order_id', 'user_id', 'collection_address_id', 'delivery_address_id',
'recipientsName', 'recipientsSurname', 'order',)
9 changes: 9 additions & 0 deletions collection_order/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .views import CreateCollectionOrder,ViewAllCollectionOrders,RetrieveCollectionOrdersOfUser, RemoveCollectionOrder
from django.urls import path

urlpatterns = [
path('create', CreateCollectionOrder.as_view()),
path('view', ViewAllCollectionOrders.as_view()),
path('getAll', RetrieveCollectionOrdersOfUser.as_view()),
path('remove/<pk>', RemoveCollectionOrder.as_view()),
]
40 changes: 38 additions & 2 deletions collection_order/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
from django.shortcuts import render
from rest_framework import generics
from rest_framework.response import Response

# Create your views here.
from . import models
from . import serializers


class CreateCollectionOrder(generics.CreateAPIView):
serializer_class = serializers.CollectionOrderSerializer
queryset = models.CollectionOrder.objects.all()

def perform_create(self, serializer):
serializer.save(user_id = self.request.user)


class ViewAllCollectionOrders(generics.ListAPIView):
serializer_class = serializers.CollectionOrderSerializer
queryset = models.CollectionOrder.objects.all()


class RetrieveCollectionOrdersOfUser(generics.ListAPIView):
serializer_class = serializers.CollectionOrderSerializerExtended

def get_queryset(self):
user = self.request.user
return models.CollectionOrder.objects.filter(user_id = user.user_id)


class RemoveCollectionOrder(generics.DestroyAPIView):
serializer_class = serializers.CollectionOrderSerializer
queryset = models.CollectionOrder.objects.all()

def delete(self, request, *args, **kwargs):
instance = self.get_object()
# just the user can delete his own collection order
if instance.user_id == request.user.user_id:
return self.destroy(request, *args, **kwargs)
else:
return Response(data = "Error")
Binary file added delivery_address/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added delivery_address/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added delivery_address/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion delivery_address/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class DeliveryAddress(models.Model):
latitude = models.DecimalField(max_digits = 20, decimal_places = 12, null = True)

def __str__(self):
return self.description
return self.description
10 changes: 10 additions & 0 deletions delivery_address/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework.serializers import ModelSerializer
from .models import DeliveryAddress


class DeliveryAddressSerializer(ModelSerializer):
class Meta:
model = DeliveryAddress
fields = ('delivery_address_id', 'line1', 'line2', 'zipCode', 'city',
'country', 'description', 'latitude', 'longitude',)

7 changes: 7 additions & 0 deletions delivery_address/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .views import DeliveryAddressCreate, DeliveryAddressRetrieve
from django.urls import path

urlpatterns = [
path('create', DeliveryAddressCreate.as_view()),
path('view', DeliveryAddressRetrieve.as_view()),
]
18 changes: 17 additions & 1 deletion delivery_address/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from django.shortcuts import render
from rest_framework import generics
from . import models
from . import serializers


# Create your views here.

class DeliveryAddressCreate(generics.ListCreateAPIView):
queryset = models.DeliveryAddress.objects.all()
serializer_class = serializers.DeliveryAddressSerializer

def create(self, request, *args, **kwargs):
request.data["delivery_address_id"] = request.deliveryAddress.delivery_address_id
return super(generics.ListCreateAPIView, self).create(request, *args, **kwargs)


class DeliveryAddressRetrieve(generics.ListAPIView):
queryset = models.DeliveryAddress.objects.all()
serializer_class = serializers.DeliveryAddressSerializer
Binary file added mappy/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added mappy/__pycache__/settings.cpython-35.pyc
Binary file not shown.
Binary file added mappy/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file added mappy/__pycache__/wsgi.cpython-35.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion mappy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost']

DEBUG_PROPAGATE_EXCEPTIONS = True
# Application definition

INSTALLED_APPS = [
Expand Down
Binary file added package/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added package/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added package/__pycache__/models.cpython-35.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion package/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Generated by Django 2.1.3 on 2018-11-17 21:05
# Generated by Django 2.1.3 on 2018-12-06 23:24

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('collection_order', '0001_initial'),
]

operations = [
Expand All @@ -17,6 +19,7 @@ class Migration(migrations.Migration):
('package_id', models.AutoField(primary_key=True, serialize=False)),
('weight', models.DecimalField(decimal_places=12, max_digits=20, null=True)),
('description', models.CharField(max_length=35, null=True)),
('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='package', to='collection_order.CollectionOrder')),
],
),
]
19 changes: 19 additions & 0 deletions package/migrations/0002_auto_20181206_1937.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1.3 on 2018-12-06 23:37

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('package', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='package',
name='order',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='package', to='collection_order.CollectionOrder'),
),
]
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions package/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.db import models
from collection_order.models import CollectionOrder


# Create your models here.

class Package(models.Model):
package_id = models.AutoField(primary_key = True)
weight = models.DecimalField(max_digits = 20, decimal_places = 12, null = True)
description = models.CharField(max_length = 35, null = True)
order = models.ForeignKey(CollectionOrder, on_delete = models.CASCADE,
null = True, blank = True, related_name = "order")
9 changes: 9 additions & 0 deletions package/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework.serializers import ModelSerializer
from .models import Package


class PackageSerializer(ModelSerializer):
class Meta:
model = Package
fields = ('package_id', 'weight', 'description', 'order')

7 changes: 7 additions & 0 deletions package/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .views import PackageCreate, PackageViewAll
from django.urls import path

urlpatterns = [
path('create/', PackageCreate.as_view()),
path('view/', PackageViewAll.as_view()),
]
14 changes: 12 additions & 2 deletions package/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from django.shortcuts import render
from rest_framework import generics
from . import models
from . import serializers

# Create your views here.

class PackageCreate(generics.CreateAPIView):
queryset = models.Package.objects.all()
serializer_class = serializers.PackageSerializer


class PackageViewAll(generics.ListAPIView):
queryset = models.Package.objects.all()
serializer_class = serializers.PackageSerializer
Loading

0 comments on commit 1474647

Please sign in to comment.