예제 #1
0
def sub_follow_user(request):
    if not request.is_ajax():
        return HttpResponseBadRequest()
    data = {
        "follow_case": True,
        "html": "",
        'is_valid': True,
        "msg": "Takipten Çık",
        "active": True
    }
    follower_username = request.GET.get("follower_username", None)
    followed_username = request.GET.get("followed_username", None)

    follower = get_object_or_404(User, username=follower_username)
    followed = get_object_or_404(User, username=followed_username)

    is_follow = Following.is_follow_user(follower=follower, followed=followed)

    if not is_follow:
        Following.follow_user(follower=follower, followed=followed)
        noti = Following.objects.filter(follower=follower, followed=followed)
        Notifications.add_notification(user=followed,
                                       obj=noti[0],
                                       request=request)
    else:
        noti = Following.objects.filter(follower=follower, followed=followed)
        Notifications.delete_notification(obj=noti[0], request=request)
        Following.unfollow_user(follower=follower, followed=followed)
        data.update({
            "msg": "Takip Eyle",
            "active": False,
            "follow_case": False
        })
    return {"data": data, "followed": followed}
예제 #2
0
def update_data_new(request):
    print(request.POST)
    ddd = json.loads(request.POST["user"])
    print(ddd)
    data = ddd["data"]
    user = ddd["cred"]
    u = User.objects.get(email=user["email"])
    from tracking_system.models import Tracker
    try:
        dd = u.order_dashboard.process_ordered_dates(data)
        print(dd)
        # t = Tracker(track_id = u,date = dd["date"],time=dd["time"])
        # dat = data
        # dat["type"] = request.POST["type"]
        # t.update_operation(dat)
        # t.save()
        noti = Notifications(type_msg = "tracking",email = u,sent_from = "Admin",title = "Recieve of order",msg="Your order has been recieved at our warehouse. You can track the order details in tracking page.",seen=False)
        noti.save()
        # onsignal("Your order has been recieved at our warehouse. You can track the order details in tracking page.",u)
        onsignal("Your order has been recieved at our warehouse. You can track the order details in tracking page.",u)
        return HttpResponse(json.dumps(dd))
    except Exception as exp:
        print(exp)
        
        # dd = u.order_dashboard.update_dashboard(request.POST["date"],request.POST["time"],data)
        # noti = Notifications(type_msg = "tracking",email = u,sent_from = "Admin",title = "Completed Processing Your Order",msg="Your order has been processed. You can track the order details in tracking page.",seen=False)
        # noti.save()
        # onsignal("Your order has been completed processing. You can track the order details in tracking page.",u)
        
        # return "Success"
    return HttpResponse("Error")
예제 #3
0
def update_data(request):
    print(request.POST)
    ddd = json.loads(request.POST["user"])
    print(ddd)
    data = ddd["data"]
    user = ddd["cred"]
    u = User.objects.get(email=user["email"])
    from tracking_system.models import Tracker
    try:
        rrr = u.order_dashboard.update_dashboard(ddd["date"],ddd["time"],data)
        print("Updated Dashboard   ",rrr)
        u.save()
        t = Tracker.objects.filter(track_id = u,date = ddd["date"],time=ddd["time"])
        dat = {}
        dat["data"] = data
        dat["type"] = ddd["type"]
        print(len(t))
        for ii in t:
            ii.update_operation(dat)
            ii.save()
        noti = Notifications(type_msg = "tracking",email = u,sent_from = "Admin",title = ddd["title"],msg=ddd["msg"],seen=False)
        noti.save()
        # onsignal("Your order has been recieved at our warehouse. You can track the order details in tracking page.",u)
        onsignal(ddd["msg"],u)
        return HttpResponse("Success")
    except Exception as exp:
        print(exp)
        
        # dd = u.order_dashboard.update_dashboard(request.POST["date"],request.POST["time"],data)
        # noti = Notifications(type_msg = "tracking",email = u,sent_from = "Admin",title = "Completed Processing Your Order",msg="Your order has been processed. You can track the order details in tracking page.",seen=False)
        # noti.save()
        # onsignal("Your order has been completed processing. You can track the order details in tracking page.",u)
        
        # return "Success"
    return HttpResponse("Error")
예제 #4
0
 def save_notification(self, msg):
     try:
         u = User.objects.filter(email=self.uname)
         from user.models import Notifications
         n = Notifications(email=u,
                           sent_from=msg["from"],
                           title=msg["title"],
                           msg=msg["msg"])
         n.save()
     except Exception as e:
         print("Error occured while saving notification :  ", e)
예제 #5
0
def thread_task(data):
    print(data)
    # data = data[0]
    try:
        for i in data["u"]:
            if i.plans.plan != "None":
                noti = Notifications(type_msg = "notify",email = i,sent_from = "Admin",title = data["title"],msg=data["msg"],seen=False)
                noti.save()
                onsignal(data["msg"],i)
        return HttpResponse("Success")
    except Exception as exp:
        print(exp)
예제 #6
0
def repost(request, id):
    repost = RepostForm(request.POST or None)
    comment = get_object_or_404(Comment, id=id)
    if repost.is_valid():
        content = repost.cleaned_data.get("repost_content")
        pfrep = Repost.objects.create(reposting_comment=comment,
                                      user=request.user,
                                      repost_content=content)
        Notifications.add_notification(user=comment.user,
                                       obj=pfrep,
                                       request=request)
        ProfileRiver.add_river(pfrep, user=request.user)
    else:
        print("hayat bi else")
    return redirect("pie_thing:index")
예제 #7
0
 def add_comment(cls, obj, model_type, user, content, options, photo, ip,
                 request, is_anon):
     if photo:
         photo = cls.compressImage(photo)
     content_type = ContentType.objects.get_for_model(obj.__class__)
     comment = cls.objects.create(user=user,
                                  is_anon=is_anon,
                                  content=content,
                                  content_type=content_type,
                                  object_id=obj.id,
                                  opt=options,
                                  photo=photo)
     ProfileRiver.add_river(comment, user)
     UserLog.add_log(obj=comment, user=comment.user, ip_adress=ip)
     if model_type == "comment":
         Notifications.add_notification(obj.user, comment, request=request)
         obj.is_parent = True
         obj.save()
예제 #8
0
def delete_comment(request, id, obj):
    comment = get_object_or_404(Comment, id=id)
    cc = Comment.objects.filter(id=id)

    ProfileRiver.delete_river(obj=cc[0], user=request.user)
    UserLog.delete_log(obj=cc[0], user=request.user)
    if comment.get_child_comment_count() != 0:
        for i in comment.get_child_comment():
            Notifications.delete_notification(obj=i, request=request)
            i.delete()
    if comment.get_un_sup_count() != 0 or comment.get_sup_count() != 0:
        for i in comment.sups.all():
            Notifications.delete_notification(obj=i, request=request)
    if comment.reposts.count() != 0:
        for i in comment.reposts.all():
            ProfileRiver.delete_river(obj=i, user=i.user)
    Notifications.delete_notification(obj=comment, request=request)
    comment.delete()
    if obj == 0:
        return redirect("user:profile", request.user.username)
    elif obj == 2:
        child_html = render_to_string(
            "includes/comment/child-review.html",
            context={"comment": comment.content_object},
            request=request)
        return JsonResponse({"child_html": child_html})
    else:
        return redirect("pie_thing:thing", id=obj)
예제 #9
0
def register(request):

    # uu=User.objects.get(email=email)
    # uu.set_password("1234rko")
    # uu.save()
    # if(len(validate_password(password=password))==0):
    #     User.objects._create_user(email="*****@*****.**",password=password,first_name="sahith",last_name = "kumar",address="adsd",phone_number="sdasd",zip_code="sadsad",contracts="sadsad",contracts_address="sdsad",gender="sadas")
        
    #     d="done"
    # else:
    #     d="ee"
    # data = {
    #     'log' : User.objects.filter(email=email,password=password).exists()
    # }
    from contracts.models import Contracts
   
    import json
    data = {"c":True,"g":False,"ee":False,"inve":False}
    
    try:
        
        email = request.POST["email"]
        password = request.POST["pswd"]

        from django.core.exceptions import ValidationError

        from django.core.validators import validate_email
        try:
            validate_email(email)
            # print("pass e")
            u = User.objects.get(email = email)
            data['inve']=True
            
        except ValidationError:
            data['ee']=True
        except:
            try:
                fn=request.POST["first_name"]
                ln=request.POST["last_name"]
                phno=request.POST["phno"]
                addr=request.POST["address"]
                gender=request.POST["gender"]
                col=request.POST["college"]
                con_u = Contracts.objects.get(contract_name = col)
                coladd=request.POST['coladdress']
                
                u=User.objects._create_user(email=email,password=password,first_name=fn,last_name=ln,gender=gender,address=addr,phone_number=phno,zip_code="500076",contract_name=con_u ,last_login=datetime.strptime(datetime.now(tz=settings.ist_info).strftime("%Y-%m-%d %H:%M:%S %p"),"%Y-%m-%d %H:%M:%S %p"))
                print("User created")
                u = User.objects.get(email=email)
                print("got user and changing")
                qr = pyqrcode.create(json.dumps({"email":u.email,"first_name":u.first_name,"last_name":u.last_name,"gender":u.gender,"contract_name":u.contract_name.contract_name,"contract_address":u.contract_name.contract_address}))
                dta = "data:image/png;base64," + qr.png_as_base64_str()
                u.qr_code_data = bytes(dta,'utf-8')
                u.save()
                from user.models import Notifications
                noti = Notifications(type_msg = "notify",email = u,sent_from = "Wasche",title = "Welcome!",msg = "Welcome "+u.first_name + ". We are happy to see you here. We hope you like our service. If you have any issues please send us a contact mail we will verify your response. Thank you.",seen = False)
                noti.save()
                # u.last_login=datetime.strptime(datetime.now(tz=settings.ist_info).strftime("%Y-%m-%d %H:%M:%S %p"),"%Y-%m-%d %H:%M:%S %p")
                # u.save()
            # response.delete_cookie("vote")
            # max_age = 24*60*365 # two weeks
            # expires = datetime.strftime(datetime.utcnow() + datetime.timedelta(seconds=max_age), "%a, %d-%b-%Y %H:%M:%S GMT")
                
                data['g']=True
                response=HttpResponse(json.dumps(data))

                response.set_cookie('wasche', {"e":email,"fn":fn,"ln":ln,"gender":gender},6307200)
                return response
            except Exception as exp:
                print("Reg Error  ",exp)

                data['c']=False
        
            
                
    except:
        data['c']=False
    response=HttpResponse(json.dumps(data))

    return response
예제 #10
0
def add_or_remove_sup(request, id, sup_type):
    data = {"status": "deleted"}
    comment = get_object_or_404(Comment, id=id)
    sup_comment = SupportComment.objects.filter(comment=comment,
                                                user=request.user,
                                                sup_type=sup_type)
    anti_comment = SupportComment.objects.filter(comment=comment,
                                                 user=request.user,
                                                 sup_type=not sup_type)
    if sup_comment.exists():  #VAR OLAN OY GERİ ÇEKİLİR
        Notifications.delete_notification(obj=sup_comment[0], request=request)
        UserLog.delete_log(obj=sup_comment[0], user=request.user)
        sup_comment.delete()
        if sup_type == 1:
            comment.point = comment.point - 1
            comment.save()
        else:
            comment.point = comment.point + 1
            comment.save()

    else:
        if anti_comment.exists():
            Notifications.delete_notification(obj=anti_comment[0],
                                              request=request)
            UserLog.delete_log(obj=anti_comment[0], user=request.user)
            anti_comment.delete()
            noti = SupportComment.objects.create(comment=comment,
                                                 user=request.user,
                                                 sup_type=sup_type)
            if comment.user != request.user:
                Notifications.add_notification(user=comment.user,
                                               obj=noti,
                                               request=request)
            UserLog.add_log(obj=noti,
                            user=request.user,
                            ip_adress=str(get_client_ip(request)))
            data.update({"status": "added"})

            if sup_type == 1:
                comment.point = comment.point + 2
                comment.save()
            else:
                comment.point = comment.point - 2
                comment.save()
        else:
            noti = SupportComment.objects.create(comment=comment,
                                                 user=request.user,
                                                 sup_type=sup_type)
            Notifications.add_notification(user=comment.user,
                                           obj=noti,
                                           request=request)
            UserLog.add_log(obj=noti,
                            user=request.user,
                            ip_adress=str(get_client_ip(request)))

            if sup_type == 1:
                comment.point = comment.point + 1
                comment.save()
            else:

                comment.point = comment.point - 1
                comment.save()
            data.update({"status": "added"})

    html = render_to_string("includes/supporting/comment_reaction.html",
                            context={"comment": comment},
                            request=request)
    count = comment.get_sup_count()
    data.update({"count": count})
    return JsonResponse({"reaction_html": html})
예제 #11
0
def delete_repost(request, id):
    repost = get_object_or_404(Repost, id=id)
    ProfileRiver.delete_river(obj=repost, user=request.user)
    Notifications.delete_notification(obj=repost, request=request)
    repost.delete()
    return JsonResponse({})
예제 #12
0
def update_tracker(request):
    user = json.loads(request.POST["user"])
    print("Type   :  ", request.POST["type"])
    if request.POST["type"] == "po":
        try:

            ded = Deliver_Executive.objects.filter(
                contract_name=user["cred"]["contract_name"])
            for dedd in ded:
                deod = ongoing_delivery.objects.filter(name=dedd)
                for deodd in deod:
                    if deodd.on_going == "initialized":
                        deodd.on_going = "Processing Order"
                        deodd.save()
                user["type"] = "po"
                user["data"]["p"] = False
                user["data"]["s"] = user["data"]["t"]
                user["data"]["c"] = 1
                user["msg"] = "Your order has been processed."
                user["data"]["start"] = False
                user["title"] = "Order Details"
                # print("\n\nSaving : ",user,"\n\n")
                req = requests.post(root_url + "/dashboard/update_data/",
                                    data={"user": json.dumps(user)})
        except Exception as exp:
            print("Error :  ", exp)
    elif request.POST["type"] == "di":
        try:
            ded = Deliver_Executive.objects.filter(
                contract_name=user["cred"]["contract_name"])
            for dedd in ded:
                deod = ongoing_delivery.objects.filter(name=dedd)
                for deodd in deod:
                    if deodd.on_going == "Processing Order":
                        deodd.on_going = "Started Delivery"
                        deodd.save()
            u = User.objects.get(email=user["cred"]["email"])
            t = Tracker.objects.filter(track_id=u,
                                       date=user["date"],
                                       time=user["time"])
            dat = {}

            print(len(t))
            for ii in t:
                ii.update_operation({"type": "di"})
                ii.save()
            noti = Notifications(
                type_msg="tracking",
                email=u,
                sent_from="Admin",
                title="Order Information",
                msg=
                "Your order has completed. It may reach you in another 2 hours.",
                seen=False)
            noti.save()
            # onsignal("Your order has been recieved at our warehouse. You can track the order details in tracking page.",u)
            onsignal(
                "Your order has completed. It may reach you in another 2 hours.",
                u)
        except Exception as exp:
            print("Error  :  ", exp)
    elif request.POST["type"] == "pd":
        try:

            ded = Deliver_Executive.objects.filter(
                contract_name=user["cred"]["contract_name"])
            for dedd in ded:
                deod = ongoing_delivery.objects.filter(name=dedd)
                for deodd in deod:
                    if deodd.on_going == "Started Delivery":
                        deodd.on_going = "Completed Delivery"
                        deodd.save()
            u = User.objects.get(email=user["cred"]["email"])
            t = Tracker.objects.filter(track_id=u,
                                       date=user["date"],
                                       time=user["time"])
            dat = {}

            print(len(t))
            for ii in t:
                ii.update_operation({"type": "pd"})
                ii.save()
            noti = Notifications(type_msg="tracking",
                                 email=u,
                                 sent_from="Admin",
                                 title="Order Conpletion",
                                 msg="Hey, your order has arrived.",
                                 seen=False)
            noti.save()
            # onsignal("Your order has been recieved at our warehouse. You can track the order details in tracking page.",u)
            onsignal("Hey, your order has arrived.", u)
        except Exception as exp:
            print("Error  :  ", exp)
    elif request.POST["type"] == "qc":
        try:
            u = User.objects.get(email=user["cred"]["email"])
            t = Tracker.objects.filter(track_id=u,
                                       date=user["date"],
                                       time=user["time"])
            dat = {}

            print(len(t))
            for ii in t:
                ii.update_operation({"type": "qc"})
                ii.save()
            # noti = Notifications(type_msg = "tracking",email = u,sent_from = "Admin",title = "Order Conpletion",msg="Hey, your order has arrived.",seen=False)
            # noti.save()
            # onsignal("Your order has been recieved at our warehouse. You can track the order details in tracking page.",u)
            # onsignal("Hey, your order has arrived.",u)
        except Exception as exp:
            print("Error  :  ", exp)
    return HttpResponse("complete")

    return HttpResponse("complete")