def follow(request): # get current profile qs = Profile.objects.all() ps = qs.filter(owner=request.user) myprofile = ps[0] # end id = request.data['id'] test = json.loads(request.data['test']) profile = Profile.objects.get(pk=id) if(profile): queryset = Follower.objects.all() followers = queryset.filter(profile=profile) exist = followers.filter(username=request.user.username) # queryset = queryset.filter(Q(profile=profile) & Q(username=request.user.username)) if exist.count() == 0 and test == False: follower = Follower(profile=profile, username=request.user.username) follower.save() # new notification notif = Notification(profile=profile, profileId=myprofile.id, type='newfollower') notif.save() # test email if profile.confReceiveMails == True: send_html_mail('Follower', 'You have a new follower', profile.email) # end test if exist.count() == 0 and test == True: return Response({'response': 'yes'}) if exist.count() > 0 and test == True: return Response({'response': 'not'}) return Response({'response': 'good'}) return Response({'response': 'bad'})
def clap_profile(request): id = request.data['id'] test = json.loads(request.data['test']) profile = Profile.objects.get(pk=id) if(profile): queryset = Clap.objects.all() claps = queryset.filter(profile=profile) exist = claps.filter(username=request.user.username) # queryset = queryset.filter(Q(profile=profile) & Q(username=request.user.username)) if exist.count() == 0 and test == False: clap = Clap(profile=profile, username=request.user.username) clap.save() profile.score = claps.count() profile.save() # test email if profile.confReceiveMails == True: send_html_mail('Claps', 'Your DirStuff profile received a new clap', profile.email) # end test if exist.count() == 0 and test == True: return Response({'response': 'yes'}) if exist.count() > 0 and test == True: return Response({'response': 'not'}) return Response({'response': profile.score}) return Response({'response': 'bad'})
def change_profile_config(request): confVisible = json.loads(request.data['visible']) confEmailVisible = json.loads(request.data['emailVisible']) confReceiveMails = json.loads(request.data['receiveMails']) # print('change_profile_config') # print(confVisible) # print(confEmailVisible) # print(confReceiveMails) queryset = Profile.objects.all() queryset = queryset.filter(owner=request.user) profile = queryset[0] if (profile): profile.confVisible = confVisible profile.confEmailVisible = confEmailVisible profile.confReceiveMails = confReceiveMails profile.save() #test email if profile.confReceiveMails == True: send_html_mail('Update Profile', 'Your DirStuff profile config have been updated', profile.email) #end test return Response({'response': 'ok'}) return Response({'response': 'bad'})
def update_profile(request): id = request.data['id'] info = request.data['info'] rating = request.data['rating'] score = request.data['score'] fullname = request.data['fullname'] email = request.data['email'] phone = request.data['phone'] profile = Profile.objects.get(pk=id) if (profile): profile.info = info profile.rating = rating profile.score = score profile.fullname = fullname profile.email = email profile.phone = phone profile.save() #test email if profile.confReceiveMails == True: send_html_mail('Update Profile', 'Your DirStuff profile have been updated', profile.email) #end test return Response({'response': 'ok'}) return Response({'response': 'bad'})
def create_user(request): print("create_user") pin = request.data['pin'] queryset = Stock.objects.all() queryset = queryset.filter(pin=pin) print(len(queryset)) if(len(queryset) == 1): stock = queryset[0] print(stock.pin) serialized = UserSerializer(data=request.data) if serialized.is_valid(): serialized.save() user = auth.authenticate(username=request.data['username'], password=request.data['password']); if user is not None: tshirt = TShirt(owner=user, message="", color=stock.color, size=stock.size, code=stock.code) profile = Profile(owner=user, email=request.data['email'], fullname=request.data['username']) banner = MediaFile(owner=user) tshirt.save() profile.save() banner.save() stock.delete() #test email if profile.confReceiveMails == True: send_html_mail('Welcome to DirStuff', 'Welcome to DIRSTUFF', profile.email) #end test return Response({'response': 'ok'}) else: return Response({'response': 'bad'}) else: serialized = UserSerializer(data=request.data) if serialized.is_valid(): serialized.save() user = auth.authenticate(username=request.data['username'], password=request.data['password']); if user is not None: profile = Profile(owner=user, email=request.data['email'], fullname=request.data['username']) banner = MediaFile(owner=user) profile.save() banner.save() #test email if profile.confReceiveMails == True: send_html_mail('Welcome to DirStuff', 'Welcome to DIRSTUFF', profile.email) #end test return Response({'response': 'ok'}) else: return Response({'response': 'bad'})
def update_user(request): user = request.user user.set_password(request.data['password']) user.save() update_session_auth_hash(request, request.user) #email test queryset = Profile.objects.all() queryset = queryset.filter(owner=user) profile = queryset[0] if profile.confReceiveMails == True: send_html_mail('Password changed', 'Your DirStuff password have been changed', profile.email) #end test return Response({'response': 'ok'})