def viewprofile(request, email): print("called viewprofile view func") e, u = check_user_exists(request, email) ae, user = check_user_exists(request, request.session["username"]) message = "" if request.method == "POST": x = abusive_detect_main(request.POST["discription"]) if int(x) in [3, 4]: message = "Your Challange Is Harmfull" else: f = FriendToFriend( user_id=user["id"], created_date=datetime.datetime.now(), name=request.POST["name"], discription=request.POST["discription"], ).save() profile1 = Profile.objects.get(id=u["profileid"]) profile1['accepted_chall'].append(f["id"]) notif = Notifications( user_id=u["id"], sender=str(user["email"]), message="Hey! You got a new freind to friend challange ", time=datetime.datetime.now(), ) notif.save() profile1.save() if e and ae and u["profile_created"] and user["profile_created"] and ( u["id"] != user["id"]): profile1 = Profile.objects.get(id=u["profileid"]) profile2 = Profile.objects.get(id=user["profileid"]) friends = 0 # print(profile1["pending_friend_requests"]) for f in profile1["friends"]: if profile2["user_id"] == f: friends = 2 for f in profile1["pending_friend_requests"]: if profile2["user_id"] == f: friends = 1 for f in profile2["pending_friend_requests"]: if profile1["user_id"] == f: friends = 3 # photo= profile1["photo"].toString('base64'); photo = profile1["photo"].read() my_string = base64.b64encode(photo) my_string = my_string.decode('utf-8') # for c in col: context = { "name": profile1["name"], "discription": profile1["discription"], "email": u["email"], "photo": my_string, "friends": friends, "message": message } return render(request, "user/viewprofile.html", context) return redirect("user:friends")
def findfriends(request): print("called findfriends view func") ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) content = list() for h in User.objects.all()[:16]: if h["id"] == user["id"] or h["id"] in profile["friends"]: continue f = h["id"] temp = dict() reqby = User.objects.get(id=f) reqbyprof = Profile.objects.get(user_id=f) temp["name"] = reqbyprof["name"] temp["discription"] = reqbyprof["discription"] try: temp["discription"] = temp["discription"][:40] + "....." except: pass temp["email"] = reqby["email"] photo = reqbyprof["photo"].read() my_string = base64.b64encode(photo) my_string = my_string.decode('utf-8') temp["photo"] = my_string content.append(temp) return render(request, "user/findfriends.html", {"content": content})
def returnSuggestedFriends(request): ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) content = list() for h in User.objects.all()[:8]: try: if h["id"] == user["id"] or h["id"] in profile["friends"]: continue f = h["id"] temp = dict() reqby = User.objects.get(id=f) reqbyprof = Profile.objects.get(user_id=f) temp["name"] = reqbyprof["name"] temp["discription"] = reqbyprof["discription"] try: temp["discription"] = temp["discription"][:40] + "....." except: pass temp["email"] = reqby["email"] photo = reqbyprof["photo"].read() my_string = base64.b64encode(photo) my_string = my_string.decode('utf-8') temp["photo"] = my_string content.append(temp) except: pass return content
def ftf(request, id): context = dict() ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) if request.method == "POST": if 'file' in request.FILES: f = FriendToFriend.objects.get(id=id) file = request.FILES['file'] content_type = 'video/mp4' post = Post( user_id=user["id"], created_date=datetime.datetime.now(), isimage=False, isvideo=True, text=f["discription"], ischallenge=True, challegetype="Friend to Friend Challange", challengeid=f["id"], ).save() post.content.put(file, content_type=content_type) post.save() addThisPost(request, post, user, profile) profile["accepted_chall"].remove(f["id"]) profile.save() return redirect('user:userhome') try: f = FriendToFriend.objects.get(id=id) if f["id"] in profile["accepted_chall"]: context["ftf"] = f return render(request, 'user/ftf.html', context) except: pass return redirect('user:userhome')
def add_clan_user(request, clan_id): ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) content = list() for h in User.objects.all()[:16]: if h["id"] == user["id"] or h["id"] not in profile["friends"]: continue print("*", h["id"], profile["friends"]) f = h["id"] temp = dict() reqby = User.objects.get(id=f) reqbyprof = Profile.objects.get(user_id=f) temp["name"] = reqbyprof["name"] temp["discription"] = reqbyprof["discription"] try: temp["discription"] = temp["discription"][:40] + "....." except: pass temp["email"] = reqby["email"] photo = reqbyprof["photo"].read() my_string = base64.b64encode(photo) temp["photo"] = my_string.decode('utf-8') content.append(temp) return render(request, 'clans/clan_add_user.html', { "content": content, "clan_id": clan_id })
def wsc(request): context = dict() ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) if request.method == "POST": if 'file' in request.FILES: file = request.FILES['file'] content_type = 'video/mp4' weekNumber = date.today().isocalendar()[1] Weekly_challange_t = reversed( WeeklyChallanges.objects.filter(posted_week=str(weekNumber))) weekly_challange = None for w in Weekly_challange_t: Weekly_challange = w break post = Post( user_id=user["id"], created_date=datetime.datetime.now(), isimage=False, isvideo=True, text=Weekly_challange["discription"], ischallenge=True, challegetype="Weekly Single Challange", challengeid=Weekly_challange["id"], ).save() post.content.put(file, content_type=content_type) post.save() addThisPost(request, post, user, profile) profile["completed"].append(Weekly_challange["id"]) profile.save() try: weekNumber = date.today().isocalendar()[1] Weekly_challange_t = reversed( WeeklyChallanges.objects.filter(posted_week=str(weekNumber))) weekly_challange = None for w in Weekly_challange_t: Weekly_challange = w break context['daily_challange'] = Weekly_challange context["completed"] = False if Weekly_challange["id"] in profile["completed"]: context["completed"] = True # print("-----------------",context["completed"],profile["completed"]) except: pass return render(request, 'user/wsc.html', context)
def lo(request, id): context = dict() ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) if request.method == "POST": if 'file' in request.FILES: f = Limited_Offer.objects.get(id=id) loc = Limited_Offer_Coupons.objects.get(id=f["coupons"][0]) file = request.FILES['file'] content_type = 'video/mp4' post = Post( user_id=user["id"], created_date=datetime.datetime.now(), isimage=False, isvideo=True, text=loc["discription"], ischallenge=True, challegetype="Limited Offer", challengeid=f["id"], ).save() post.content.put(file, content_type=content_type) post.save() addThisPost(request, post, user, profile) cupon = Cupon(offerid=f["id"], couponid=loc["id"]) cupon.save() profile["cupons"].append(cupon["id"]) profile.save() return redirect('user:userhome') try: context = dict() f = Limited_Offer.objects.get(id=id) loc = Limited_Offer_Coupons.objects.get(id=f["coupons"][0]) if datetime.datetime.now() < loc["expiry_date"]: context['offer'] = f context['cupon'] = loc completed = False for c in profile["cupons"]: cou = Cupon.objects.get(id=c) if f.id == cou.offerid: completed = True context["completed"] = completed return render(request, 'user/lo.html', context) except: pass return redirect('user:userhome')
def challanges(request): ae, user = check_user_exists(request, request.session["username"]) if ae: pe, profile = get_userprofile(request, user["id"]) if pe: context = dict() try: daily_challange = DailyChallanges.objects.get( posted_date=datetime.date.today()) context['daily_challange'] = daily_challange except: pass try: weekNumber = date.today().isocalendar()[1] Weekly_challange = reversed( WeeklyChallanges.objects.filter( posted_week=str(weekNumber))) for w in Weekly_challange: context['weekly_challange'] = w break except: pass try: ftf = profile["accepted_chall"] lis = [] for f in ftf: lis.append(FriendToFriend.objects.get(id=f)) context['ftf'] = lis except: pass try: lo = Limited_Offer.objects.all() lis = [] for l in lo: loc = Limited_Offer_Coupons.objects.get(id=l["coupons"][0]) if datetime.datetime.now() < loc["expiry_date"]: lis.append(l) context['Limited_Offer'] = lis except: pass return render(request, "user/challanges.html", context) return redirect("user_auth:loggedinhome")
def dsc(request): context = dict() ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) if request.method == "POST": if 'file' in request.FILES: file = request.FILES['file'] content_type = 'video/mp4' daily_challange = DailyChallanges.objects.get( posted_date=datetime.date.today()) post = Post( user_id=user["id"], created_date=datetime.datetime.now(), isimage=False, isvideo=True, text=daily_challange["discription"], ischallenge=True, challegetype="Daily Single Challange", challengeid=daily_challange["id"], ).save() post.content.put(file, content_type=content_type) post.save() addThisPost(request, post, user, profile) profile["completed"].append(daily_challange["id"]) profile.save() try: daily_challange = DailyChallanges.objects.get( posted_date=datetime.date.today()) context['daily_challange'] = daily_challange context["completed"] = False if daily_challange["id"] in profile["completed"]: context["completed"] = True # print("-----------------",context["completed"],profile["completed"]) except: pass return render(request, 'user/dsc.html', context)
def viewmyprofile(request): ae, user = check_user_exists(request, request.session["username"]) if ae: pe, profile = get_userprofile(request, user["id"]) if pe: temp = {"profile": profile, "email": user["email"]} photo = profile["photo"].read() my_string = base64.b64encode(photo) my_string = my_string.decode('utf-8') temp["photo"] = my_string temp["posts_count"] = len(profile["myposts"]) temp["friends"] = len(profile["friends"]) temp["sfriends"] = returnSuggestedFriends(request) cu = [] y = 0 try: x = [] for c in profile["cupons"][::-1]: print("--") t = dict() cupon = Cupon.objects.get(id=c) t["offer"] = Limited_Offer.objects.get(id=cupon.offerid) t["cupon"] = Limited_Offer_Coupons.objects.get( id=cupon.couponid) x.append(t) if y % 2 == 1: cu.append(x) x = [] y = y + 1 if x: cu.append(x) except: pass temp["cupons"] = cu return render(request, "user/viewmyprofile.html", temp) return redirect("user_auth:loggedinhome")
def friend_req_handle(request, email, test): print("called friend_req_handle view func") e, u = check_user_exists(request, email) ae, user = check_user_exists(request, request.session["username"]) if e and ae and u["profile_created"] and user["profile_created"] and ( u["id"] != user["id"]): profile1 = Profile.objects.get(id=u["profileid"]) profile2 = Profile.objects.get(id=user["profileid"]) friends = "0" for f in profile1["friends"]: if profile2["user_id"] == f: friends = "2" for f in profile1["pending_friend_requests"]: if profile2["user_id"] == f: friends = "1" for f in profile2["pending_friend_requests"]: if profile1["user_id"] == f: friends = "3" if test == "0" and friends == "0": if user["id"] not in profile1["pending_friend_requests"]: profile1["pending_friend_requests"] += [ user["id"], ] profile1.save() elif test == "1" and friends == "1": try: profile1["pending_friend_requests"].remove(user["id"]) profile1.save() except: pass elif test == "2" and friends == "2": try: profile1["friends"].remove(user["id"]) profile1.save() profile2["friends"].remove(u["id"]) profile2.save() except: pass elif test == "3" and friends == "3": try: profile2["pending_friend_requests"].remove(u["id"]) profile2["friends"].append(u["id"]) profile2.save() profile1["friends"].append(user["id"]) profile1.save() except: pass elif test == "5" and friends == "3": try: profile2["pending_friend_requests"].remove(u["id"]) profile2["friends"].append(u["id"]) profile2.save() profile1["friends"].append(user["id"]) profile1.save() return redirect('user:pendingrequests') except: pass elif test == "4" and friends == "3": try: profile2["pending_friend_requests"].remove(u["id"]) profile2.save() return redirect('user:pendingrequests') except: pass return redirect('user:viewprofile', email) return redirect("user_auth:loggedinhome")
def notifications(request): context = dict() ae, user = check_user_exists(request, request.session["username"]) context["notifications"] = reversed( Notifications.objects.filter(user_id=user["id"])) return render(request, 'user/notifications.html', context)
def userhome(request): print("called userhome view func in user app") ae, user = check_user_exists(request, request.session["username"]) profile = Profile.objects.get(id=user["profileid"]) if request.method == "POST": if "tought" in request.POST: post = Post( user_id=user["id"], created_date=datetime.datetime.now(), # isimage = BooleanField(default=False) # isvideo = BooleanField(default=False) text=request.POST["tought"], # image = ImageField() # text = StringField(max_length=200) ) post.save() addThisPost(request, post, user, profile) HttpResponseRedirect("user.views.userhome") context = {'warning': "Logged in successfully"} try: daily_challange = DailyChallanges.objects.get( posted_date=datetime.date.today()) context['daily_challange'] = daily_challange except: pass try: weekNumber = date.today().isocalendar()[1] Weekly_challange = reversed( WeeklyChallanges.objects.filter(posted_week=str(weekNumber))) for w in Weekly_challange: context['weekly_challange'] = w break except: pass try: ftf = profile["accepted_chall"] lis = [] for f in ftf: lis.append(FriendToFriend.objects.get(id=f)) context['ftf'] = lis except: pass try: lo = Limited_Offer.objects.all() lis = [] for l in lo: loc = Limited_Offer_Coupons.objects.get(id=l["coupons"][0]) if datetime.datetime.now() < loc["expiry_date"]: lis.append(l) context['Limited_Offer'] = lis except: pass try: rchal = recomend_challange(request) if rchal: context['rchal'] = rchal except: pass feed = profile["myfeed"] posts = [] for f in feed: try: p = Post.objects.get(id=f) po = dict() po["id"] = p["id"] po["user_id"] = p["user_id"] profile1 = Profile.objects.get(user_id=p["user_id"]) po["username"] = profile1["name"] photo = profile1["photo"].read() my_string = base64.b64encode(photo) my_string = my_string.decode('utf-8') po["user_photo"] = my_string # print(my_string.decode('utf-8')) po["created_date"] = p["created_date"] # po["isimage"] = p["isimage"] po["isvideo"] = p["isvideo"] po["text"] = p["text"] if p["isvideo"]: content = p.content.read() base64EncodedStr = base64.b64encode(content) content = base64EncodedStr.decode('utf-8') po["content"] = content po["ischallenge"] = p["ischallenge"] if p["ischallenge"]: po["challegetype"] = p["challegetype"] po["challengeid"] = p["challengeid"] po["isad"] = p["isad"] if p["isad"]: po["adid"] = p["adid"] po["likes"] = p["likes"] po["comments"] = p["comments"] posts.append(po) except: pass context["posts"] = posts[-1:-101:-1] context["sfriends"] = returnSuggestedFriends(request) try: unco = [] i = 0 x = [] for u in Unlimited_Coupons.objects.all(): photo = u["banner_image"].read() my_string = base64.b64encode(photo) my_string = my_string.decode('utf-8') x.append([u, my_string]) i = i + 1 if i % 2 == 0: unco.append(x) x = [] if x: unco.append(x) context["unco"] = unco except: pass # print(context) page = request.GET.get('page', 1) paginator = Paginator(posts, 2) try: posts = paginator.page(page) except PageNotAnInteger: posts = paginator.page(1) except EmptyPage: posts = paginator.page(paginator.num_pages) return render(request, 'registration/loginhome.html', context)