Skip to content

Commit

Permalink
my fistcommit
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin064 committed Apr 29, 2019
0 parents commit 360aa84
Show file tree
Hide file tree
Showing 64 changed files with 1,312 additions and 0 deletions.
Empty file added app/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AppConfig(AppConfig):
name = 'app'
4 changes: 4 additions & 0 deletions app/cors.py
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 added app/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions app/views.py
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 added clasifiedapp/__init__.py
Empty file.
Binary file added clasifiedapp/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedapp/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedapp/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedapp/__pycache__/serializers.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedapp/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedapp/__pycache__/views.cpython-36.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions clasifiedapp/admin.py
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)
5 changes: 5 additions & 0 deletions clasifiedapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ClasifiedappConfig(AppConfig):
name = 'clasifiedapp'
28 changes: 28 additions & 0 deletions clasifiedapp/migrations/0001_initial.py
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)),
],
),
]
18 changes: 18 additions & 0 deletions clasifiedapp/migrations/0002_auto_20190428_2001.py
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/'),
),
]
18 changes: 18 additions & 0 deletions clasifiedapp/migrations/0003_auto_20190429_1101.py
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 not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions clasifiedapp/models.py
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
12 changes: 12 additions & 0 deletions clasifiedapp/serializers.py
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')
3 changes: 3 additions & 0 deletions clasifiedapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
21 changes: 21 additions & 0 deletions clasifiedapp/urls.py
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'))
]
104 changes: 104 additions & 0 deletions clasifiedapp/views.py
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 added clasifiedpro/__init__.py
Empty file.
Binary file added clasifiedpro/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedpro/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedpro/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added clasifiedpro/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
Loading

0 comments on commit 360aa84

Please sign in to comment.