-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp_code.py
230 lines (208 loc) Β· 11.7 KB
/
temp_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
''' 'userProfile':[
{'uuid':temp_profile.uuid,
'gender':temp_profile.gender,
'role':temp_profile.role,}
],
'userDoc':[
{'address':temp_doc.address,
'zipCode':temp_doc.zipCode,
'citizen':temp_doc.citizen,
'citizen_Num':temp_doc.citizen_Num,
'personalCode':temp_doc.personalCode,
'nationalCode':temp_doc.nationalCode,
'nationalCardPhoto':str(temp_doc.nationalCardPhoto),
'date_of_birth':temp_doc.date_of_birth,
'place_of_birth':temp_doc.place_of_birth,
'father_name':temp_doc.father_name,
'father_nationalCode':temp_doc.father_nationalCode,
'father_pNum':temp_doc.father_pNum,
'mother_name':temp_doc.mother_name,
'userPhoto':str(temp_doc.userPhoto),}
],'''
""" temp_profile = userProfile.objects.get(user_id = item.id)
temp_doc = userDoc.objects.get(user_id = item.id) """
"""
# new user created
new_user = User()
new_user.username = username
new_user.email = email
new_user.first_name = first_name
new_user.last_name = last_name
new_user.set_password(password)
new_user.save()
# new profile created for new user
new_profile = userProfile()
new_profile.user = new_user
new_profile.role = role
new_profile.save()
# new doc created for new user
new_doc = userDoc()
new_doc.user = new_user
new_doc.gender = gender
new_doc.section = section
new_doc.address = address
new_doc.personalCode = personal_code
new_doc.nationalCode = national_code
new_doc.father_name = father_name
new_doc.father_nationalCode = father_national_code
new_doc.userPhoto = user_photo
new_doc.nationalCardPhoto = national_card_photo
new_doc.mother_name = mother_name
new_doc.citizen = citizen
new_doc.citizen_Num = citizen_num
new_doc.zipCode = zipcode
new_doc.date_of_birth = date_birth
new_doc.place_of_birth = place_birth
new_doc.save()
"""
""" json_data = []
for item in temp_news:
json_data.append({
'auther_id':item.author_id,
'auther_username':item.author.username,
'post_id':item.id,
'title':item.title,
'contact':item.content,
'release_date':item.release_date,
}) """
""" news_id = request.data['news_id']
title = request.data['title']
content = request.data['content']
release_date = datetime.now()
news_pic = request.FILES['news_pic']
News.objects.all().filter(id = news_id).update(title = title,content = content,release_date = release_date,news_pic = news_pic)
"""
"""
temp_news = News.objects.get(id = news_id)
temp_news.title = news_title
temp_news.content = news_content
temp_news.pic = news_pic
temp_news.release_date = news_release_data
temp_news.save()
"""
""" News.objects.all().filter(id = news_id).update(title = news_title
,content = news_content,release_date = news_release_data,pic = news_pic) """
"""
class addNews(APIView):
permission_classes=(IsAuthenticated,)
def post(self, request):
try:
serilized_data = serializers.addNewsSerializer(data=request.data)
if serilized_data.is_valid():
news_title = serilized_data.data.get('title')
news_content = serilized_data.data.get('content')
news_author_id = serilized_data.data.get('author_id')
news_pic = request.FILES['pic']
news_release_data = datetime.now()
news_author = User.objects.get(id = news_author_id)
else:
message = serilized_data.errors
return Response({"status_code":"400" , "error":message,"data":"","message":""},)
#make instance from news
new_news = News()
new_news.title = news_title
new_news.content = news_content
new_news.release_date = news_release_data
new_news.pic = news_pic
new_news.author = news_author
new_news.save()
return Response({"status_code":"200" , "error":"", "data": "" , "message":"News Added Success"},status.HTTP_200_OK)
except Exception as e:
trace_back = traceback.format_exc()
message = str(e) + ' ' + str(trace_back)
return Response({"status_code":"500" , "error": message,"data":"","message":""},)
class deleteNews(APIView):
permission_classes=(IsAuthenticated,)
def post(self, request):
try:
serializer = serializers.deleteNewsSerializer(data=request.data)
if serializer.is_valid():
news_id = serializer.data.get('news_id')
if News.objects.all().filter(id = news_id).exists():
News.objects.all().filter(id = news_id).delete()
else :
return Response({"status_code":"500" , "error": "object isn,t exists","data":"","message":""},)
else:
message = serializer.errors
return Response({"status_code":"400" , "error":message,"data":"","message":""},)
return Response({"status_code":"200" , "error":"", "data": "" , "message":"News Deleted Success"},status.HTTP_200_OK)
except:
trace_back = traceback.format_exc()
message = str(e) + ' ' + str(trace_back)
return Response({"status_code":"500" , "error":message,"data":"","message":""},)
class editNews(APIView):
permission_classes=(IsAuthenticated,)
def post(self, request):
try:
serializer = serializers.editNewsSerializer(data=request.data)
if serializer.is_valid():
news_id = serializer.data.get('id')
news_title = serializer.data.get('title')
news_content = serializer.data.get('content')
news_release_data = datetime.now()
news_pic = request.FILES['pic']
else:
message = serializer.errors
return Response({"status_code":"400" , "error":message,"data":"","message":""},)
# update object in db
if News.objects.all().filter(id = news_id).exists():
temp_news = News.objects.get(id = news_id)
temp_news.title = news_title
temp_news.content = news_content
temp_news.pic = news_pic
temp_news.release_date = news_release_data
temp_news.save()
else:
return Response({"status_code":"500" , "error": "object isn,t exists","data":"","message":""},)
return Response({"status_code":"200" , "error":"", "data": "" , "message":"News Updated"},status.HTTP_200_OK)
except Exception as e:
trace_back = traceback.format_exc()
message = str(e) + ' ' + str(trace_back)
return Response({"status_code":"500" , "error": message,"data":"","message":""},)
class allNews(APIView):
permission_classes=(IsAuthenticated,)
def get(self, request):
try:
temp_news = News.objects.all()
serilized_data = serializers.allNewsSerializer(temp_news, many=True)
json_data = serilized_data.data
return Response({"status_code":"200" , "error":"", "data": json_data , "message":"" },status.HTTP_200_OK)
except Exception as e:
trace_back = traceback.format_exc()
message = str(e) + ' ' + str(trace_back)
return Response({"status_code":"500" , "error": message,"data":"","message":""},)
"""
"""
user_id = serializers.CharField(read_only=True)
uuid = serializers.UUIDField(read_only=True)
religion = serializers.CharField(max_length=100,allow_blank=False,allow_null=False)
userPhoto = serializers.CharField(max_length=250,allow_blank=True,allow_null=True)
userNationalCardPhoto = serializers.CharField(max_length=250,allow_blank=True,allow_null=True)
userIdCardPhoto = serializers.CharField(max_length=250,allow_blank=True,allow_null=True)
user_pNum = serializers.CharField(max_length=11,allow_blank=False,allow_null=False)
home_pNum = serializers.CharField(max_length=11,allow_blank=False,allow_null=False)
address = serializers.CharField(max_length=250,allow_null=True,allow_blank=False)
zipCode = serializers.CharField(max_length=10,allow_blank=False,allow_null=False)
personalCode = serializers.CharField(max_length=10,allow_null=False,allow_blank=False)
nationalCode = serializers.CharField(max_length=10,allow_blank=False,allow_null=False)
father_nationalCode = serializers.CharField(max_length=10,allow_blank=True,allow_null=True)
father_name = serializers.CharField(max_length=40,allow_blank=True,allow_null=True)
father_pNum = serializers.CharField(max_length=11,allow_blank=True,allow_null=True)
father_jobName = serializers.CharField(max_length=50,allow_blank=True,allow_null=True)
father_jobAddress = serializers.CharField(max_length=250,allow_null=True,allow_blank=True)
father_job_pNum = serializers.CharField(max_length=11,allow_blank=True,allow_null=True)
father_job_postalCode = serializers.CharField(max_length=10,allow_blank=True,allow_null=True)
mother_nationalCode = serializers.CharField(max_length=10,allow_blank=True,allow_null=True)
mother_name = serializers.CharField(max_length=40,allow_blank=True,allow_null=True)
mother_pNum = serializers.CharField(max_length=11,allow_blank=True,allow_null=True)
mother_jobName = serializers.CharField(max_length=50,allow_blank=True,allow_null=True)
mother_jobAddress = serializers.CharField(max_length=250,allow_null=True,allow_blank=True)
mother_job_pNum = serializers.CharField(max_length=11,allow_blank=True,allow_null=True)
mother_job_postalCode = serializers.CharField(max_length=10,allow_blank=True,allow_null=True)
citizen_Num = serializers.CharField(max_length=11,allow_blank=True,allow_null=True)
date_of_birth = serializers.CharField(max_length=50,allow_blank=False,allow_null=False)
place_of_birth = serializers.CharField(max_length=50,allow_blank=False,allow_null=False)
citizen = serializers.CharField(max_length=1,allow_blank=False,allow_null=False)
gender = serializers.CharField(max_length=1,allow_blank=False,allow_null=False)
section = serializers.CharField(max_length=2,allow_blank=False,allow_null=False)
"""