-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 360aa84
Showing
64 changed files
with
1,312 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AppConfig(AppConfig): | ||
name = 'app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class CorsMiddleware(object): | ||
def process_response(self, req, resp): | ||
response["Access-Control-Allow-Origin"] = "*" | ||
return response |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Users | ||
|
||
# Register your models here. | ||
admin.site.register(Users) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ClasifiedappConfig(AppConfig): | ||
name = 'clasifiedapp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 2.2 on 2019-04-27 09:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Users', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('firstname', models.CharField(blank=True, max_length=215, null=True)), | ||
('lastname', models.CharField(blank=True, max_length=512, null=True)), | ||
('username', models.CharField(blank=True, max_length=215, null=True)), | ||
('email', models.EmailField(max_length=215, unique=True)), | ||
('password', models.CharField(max_length=512)), | ||
('photo', models.ImageField(default='Phots/None/No-img.jpg', upload_to='Photos/')), | ||
('modefied_at', models.DateTimeField(auto_now=True, null=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2 on 2019-04-28 14:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('clasifiedapp', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='users', | ||
name='photo', | ||
field=models.ImageField(blank=True, null=True, upload_to='Photos/'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2 on 2019-04-29 05:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('clasifiedapp', '0002_auto_20190428_2001'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='users', | ||
name='password', | ||
field=models.CharField(blank=True, max_length=512, null=True), | ||
), | ||
] |
Empty file.
Binary file not shown.
Binary file added
BIN
+597 Bytes
clasifiedapp/migrations/__pycache__/0002_auto_20190428_2001.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+607 Bytes
clasifiedapp/migrations/__pycache__/0003_auto_20190429_1101.cpython-36.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.db import models | ||
|
||
|
||
# Create your models here. | ||
|
||
|
||
class Users(models.Model): | ||
firstname = models.CharField(max_length=215,null=True,blank=True) | ||
lastname = models.CharField(max_length=512,null=True,blank=True) | ||
username = models.CharField(max_length=215,null=True,blank=True) | ||
email = models.EmailField(max_length=215,unique=True,null=False,blank=False) | ||
password = models.CharField(max_length=512,null=True,blank=True) | ||
photo = models.ImageField(upload_to='Photos/', null=True, blank=True) | ||
modefied_at = models.DateTimeField(auto_now=True,null=True,blank=True) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
|
||
|
||
def __str__(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from .models import Users | ||
from rest_framework import serializers | ||
|
||
|
||
class Userserializer(serializers.ModelSerializer): | ||
|
||
photo = serializers.ImageField(max_length=None,use_url=True) | ||
|
||
|
||
class Meta: | ||
model = Users | ||
fields = ('id','fistname','lastname','email','password','photo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.urls import path, include | ||
from django.conf.urls import url | ||
|
||
from .views import register_view, login_view,UserDetail,postman | ||
|
||
|
||
|
||
urlpatterns = [ | ||
path('register/',register_view), | ||
path('login/', login_view), | ||
path('post/',postman), | ||
|
||
|
||
# path('home/', home_view), | ||
url(r'^userget/(?P<id>\d+)/$', UserDetail.as_view()), | ||
url(r'^userdelite/(?P<id>\d+)/$', UserDetail.as_view()), | ||
url(r'^userupdate/(?P<id>\d+)/$', UserDetail.as_view()), | ||
url(r'^auth/', include('social_django.urls')), | ||
|
||
# url(r'^auth/', include('rest_framework_social_oauth2.urls')) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
|
||
from django.shortcuts import render, redirect | ||
from django.http import HttpResponse, Http404 | ||
from rest_framework.response import Response | ||
from .serializers import Userserializer | ||
|
||
from .models import Users | ||
from rest_framework.views import APIView | ||
from rest_framework.decorators import api_view | ||
from clasifiedpro.settings import MEDIA_ROOT | ||
|
||
|
||
@api_view(['POST','GET']) | ||
def register_view(request): | ||
if request.method == 'POST': | ||
try: | ||
email = request.data.get('email') | ||
user = Users.objects.get(email=email) | ||
photo_path = str(user.photo.file) | ||
firstname = user.firstname | ||
lastname = user.lastname | ||
context = { | ||
"first_name": firstname, | ||
"last_name": lastname, | ||
"photo": photo_path | ||
} | ||
if user is not None: | ||
return Response({'exist':context, 'message':'user already exists'}) | ||
except Exception as e: | ||
first_name = request.data.get('first_name') | ||
user_name = request.data.get('user_name') | ||
last_name = request.data.get('last_name') | ||
password = request.data.get('password') | ||
photo = request.data.get('photo') | ||
context = { | ||
"firstname": first_name, | ||
"lastname": last_name, | ||
"username":user_name, | ||
"email": email, | ||
"password": password, | ||
"photo": photo, | ||
} | ||
r = Users(**context) | ||
r.save() | ||
return Response({"message": "Registered sucesfully"}) | ||
else: | ||
return Response({"status":"fail","message":"pagenot found"}) | ||
|
||
|
||
class UserDetail(APIView): | ||
def get_object(self, id): | ||
try: | ||
return Users.objects.get(id=id) | ||
except Users.DoesNotExist: | ||
raise Http404 | ||
|
||
def get(self, request, id): | ||
try: | ||
Users = self.get_object(id) | ||
serializer = Userserializer(Users) | ||
return Response(serializer.data) | ||
except Exception as e: | ||
return Response({'status':'Fail', 'statuscode':'400', 'message':'user not found'}) | ||
|
||
def delete(self, request, id): | ||
try: | ||
users = self.get_object(id) | ||
users.delete() | ||
return Response({'status':'success','statuscode':'204','messsage':'useredeleted successfully'}) | ||
except Exception as e: | ||
return Response({'status':'fail','statuscode':'400','messsage':'user not found'}) | ||
|
||
def put(self, request, id,): | ||
update = self.get_object(id) | ||
serializer = Userserializer(update, data=request.data) | ||
try: | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data) | ||
else: | ||
return Response({'status':'success','statuscode':'204','message':'Data updatefailed'}) | ||
except Exception as e: | ||
return Response({'status':'success','statuscode':'204','message':'invalid data'}) | ||
|
||
|
||
@api_view(['GET','POST']) | ||
def login_view(request): | ||
try: | ||
if request.method == 'POST': | ||
email = request.data.get('email') | ||
password = request.data.get('password') | ||
r = Users.objects.get(email=email) | ||
if r.password == password: | ||
return Response({"messsage":"login sucesfully"}) | ||
else: | ||
return Response({"message":"invalid password"}) | ||
except Exception as e: | ||
return Response({"message":" wrong email id or entered the reqired fields"}) | ||
|
||
|
||
@api_view(['GET','POST']) | ||
def postman(request): | ||
if request.method == 'GET': | ||
return Response({"message":"hii helllo"}) |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.