Commit cf4b79cc authored by Luis García's avatar Luis García
Browse files

Add address support

parent 932c3d36
......@@ -8,6 +8,14 @@ class Profile(models.Model):
gender = models.CharField(verbose_name='Gender', max_length=20, choices=GENDER_CHOICES, default='x')
age = models.PositiveIntegerField(verbose_name='Age')
location = models.PointField(verbose_name='Location', blank=True, null=True)
#Address fields
country = models.CharField(max_length=150, default='')
state = models.CharField(max_length=150, default='')
city = models.CharField(max_length=150, default='')
suburb = models.CharField(max_length=150, default='')
postal_code = models.CharField(max_length=15, default='')
address1 = models.CharField(max_length=300, default='')
address2 = models.CharField(max_length=300, blank=True, default='')
class Meta():
verbose_name = 'Profile'
......@@ -21,3 +29,22 @@ class Map(models.Model):
file = models.FileField(upload_to='mbtiles/')
created = models.DateTimeField(auto_now_add=True, verbose_name='Create date')
updated = models.DateTimeField(auto_now=True, verbose_name='Update date')
class Country(models.Model):
name = models.CharField(max_length=150)
visible = models.BooleanField(verbose_name='visible', default=True)
class State(models.Model):
name = models.CharField(max_length=150)
country = models.ForeignKey(Country, on_delete=models.PROTECT, related_name='states')
visible = models.BooleanField(verbose_name='visible', default=True)
class City(models.Model):
name = models.CharField(max_length=150)
state = models.ForeignKey(State, on_delete=models.PROTECT, related_name='cities')
visible = models.BooleanField(verbose_name='visible', default=True)
class Suburb(models.Model):
name = models.CharField(max_length=150)
city = models.ForeignKey(City, on_delete=models.PROTECT, related_name='suburbs')
visible = models.BooleanField(verbose_name='visible', default=True)
\ No newline at end of file
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
from core.forms import PasswordResetForm
from django.contrib.gis.geos import Polygon
from django.conf import settings
from django.utils.translation import gettext as _
from rest_framework import serializers
from rest_framework.serializers import SerializerMethodField
from drf_extra_fields.geo_fields import PointField
from core.models import Profile, Map
from core.models import Profile, Map, Country, State, City, Suburb
from core.forms import PasswordResetForm
import json
from django.contrib.gis.geos import Polygon
from rest_framework.serializers import SerializerMethodField
from pymbtiles import MBtiles
class UserSerializer(serializers.ModelSerializer):
......@@ -113,4 +113,24 @@ class PasswordResetSerializer(serializers.Serializer):
'request': request,
}
self.reset_form.save(**opts)
\ No newline at end of file
self.reset_form.save(**opts)
class CountrySerializer(serializers.ModelSerializer):
class Meta:
model = Country
fields = ('id', 'name')
class StateSerializer(serializers.ModelSerializer):
class Meta:
model = State
fields = ('id', 'name', 'country')
class CitySerializer(serializers.ModelSerializer):
class Meta:
model = City
fields = ('id', 'name', 'state')
class SuburbSerializer(serializers.ModelSerializer):
class Meta:
model = Suburb
fields = ('id', 'name', 'city')
\ No newline at end of file
from django.urls import path
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter
from .views import ContactView, LiveView, ProfileViewSet, UsersViewSet, MapsViewSet
from .views import ContactView, LiveView, ProfileViewSet, UsersViewSet, MapsViewSet, CountryViewSet, StateViewSet, CityViewSet, SuburbViewSet
urlpatterns = ([
path('contact/', ContactView.as_view(), name='contact'),
......@@ -13,4 +13,8 @@ router = DefaultRouter()
router.register(r'profile', ProfileViewSet, basename='profile')
router.register(r'users', UsersViewSet, basename='users')
router.register(r'maps', MapsViewSet, basename='maps')
core_api_patterns = router.urls
router.register(r'countries', CountryViewSet, basename='countries')
router.register(r'states', StateViewSet, basename='states')
router.register(r'cities', CityViewSet, basename='cities')
router.register(r'suburbs', SuburbViewSet, basename='suburbs')
core_api_patterns = router.urls
\ No newline at end of file
from .aplication import ContactView, LiveView
from .api import ProfileViewSet, UsersViewSet, MapsViewSet
\ No newline at end of file
from .api import ProfileViewSet, UsersViewSet, MapsViewSet, CountryViewSet, StateViewSet, CityViewSet, SuburbViewSet
\ No newline at end of file
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import status
from rest_framework.viewsets import ModelViewSet
from rest_framework import viewsets, mixins
from rest_framework.response import Response
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.permissions import IsAdminUser
from core.models import Profile, Map
from core.serializers import UserExtendSerializer, ProfileSerializer, MapSerializer
from api.permissions import ProfilePermission
from core.models import Profile, Map, Country, State, City, Suburb
from core.serializers import UserExtendSerializer, ProfileSerializer, MapSerializer, CountrySerializer, StateSerializer, CitySerializer, SuburbSerializer
from api.permissions import ProfilePermission, IsStaffOrReadOnly
from api.mixins import DestroyToInvisibleMixin
############################################################
#REST API for User
......@@ -51,3 +52,47 @@ class MapsViewSet(ModelViewSet):
permission_classes = (IsAdminUser,)
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('name', )
############################################################
#Rest api for Country
#This viewset only allow list actions
############################################################
class CountryViewSet(DestroyToInvisibleMixin, ModelViewSet):
queryset = Country.objects.filter(visible=True)
serializer_class = CountrySerializer
permission_classes = (IsStaffOrReadOnly,)
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('name', )
############################################################
#Rest api for State
#This viewset only allow list actions
############################################################
class StateViewSet(DestroyToInvisibleMixin, ModelViewSet):
queryset = State.objects.filter(visible=True)
serializer_class = StateSerializer
permission_classes = (IsStaffOrReadOnly,)
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('name', 'country')
############################################################
#Rest api for City
#This viewset only allow list actions
############################################################
class CityViewSet(DestroyToInvisibleMixin, ModelViewSet):
queryset = City.objects.filter(visible=True)
serializer_class = CitySerializer
permission_classes = (IsStaffOrReadOnly,)
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('name', 'state')
############################################################
#Rest api for Suburb
#This viewset only allow list actions
############################################################
class SuburbViewSet(DestroyToInvisibleMixin, ModelViewSet):
queryset = Suburb.objects.filter(visible=True)
serializer_class = SuburbSerializer
permission_classes = (IsStaffOrReadOnly,)
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('name', 'city')
\ No newline at end of file
......@@ -9,7 +9,7 @@ class Project(models.Model):
content = RichTextField(verbose_name='Content1')
content2 = RichTextField(verbose_name='Content2', blank=True, null=True)
privacy = RichTextField(verbose_name='Privacy')
image = models.ImageField(verbose_name="Image", upload_to='projects/')
image = models.ImageField(verbose_name="Image", blank=True, null=True, upload_to='projects/')
visible = models.BooleanField(verbose_name='visible', default=True)
class Meta():
......
......@@ -18,6 +18,15 @@ class ProjectViewSet(DestroyToInvisibleMixin, ModelViewSet):
queryset = Project.objects.filter(visible=True)
serializer_class = ProjectSerializer
@action(detail=True, methods=['post'], permission_classes=[IsSuperOrReadOnly])
def delete_image(self, request, pk=None):
instance = self.get_object()
data = {'image': None}
serializer = self.get_serializer(instance, data=data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Http_Response(serializer.data)
############################################################
#REST API for Institution
############################################################
......
......@@ -190,6 +190,15 @@ class SpatialInputViewSet(DestroyToInvisibleMixin, ModelViewSet):
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('description', 'answer', 'category')
@action(detail=True, methods=['post'], permission_classes=[IsOwner])
def delete_photo(self, request, pk=None):
instance = self.get_object()
data = {'photo': None}
serializer = self.get_serializer(instance, data=data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Http_Response(serializer.data)
############################################################
#REST API for answer with spatial inputs
############################################################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment