当前位置: 首页>>代码示例>>Python>>正文


Python Contact.set_contag_visibility方法代码示例

本文整理汇总了Python中models.Contact.set_contag_visibility方法的典型用法代码示例。如果您正苦于以下问题:Python Contact.set_contag_visibility方法的具体用法?Python Contact.set_contag_visibility怎么用?Python Contact.set_contag_visibility使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Contact的用法示例。


在下文中一共展示了Contact.set_contag_visibility方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import set_contag_visibility [as 别名]
    def get(self, request):
        try:
            response = []
            if "contag_id" in request.query_params:
                #Look for a contag by contag id
                user = User.objects.filter(contag=request.query_params["contag_id"])
                if user.exists():
                    user= user[0]
                    user.set_visible_profile(current_user_id=request.user.id)
                    contact = Contact(user=request.user, contact_name=user.name, contact_number=user.mobile_number,
                                      is_on_contag=1, contact_contag_user=user)
                    existing_request = Contact.existing_add_request_exists(from_user=request.user, for_user_id=user.id)
                    response = ContactViewSerializer(instance=[contact], many=True, context={'current_user': request.user.id}).data
                    response[0]["has_existing_add_request"] = existing_request
            else:
                if "user_id" in request.query_params:

                    user = User.objects.get(pk=request.query_params["user_id"])
                    contact = Contact.objects.filter(user=request.user, contact_number=user.mobile_number)

                    if contact.exists():
                        contacts = contact[0]
                        contacts.is_on_contag = True
                        contacts.contact_contag_user = user
                        contacts.is_local_profile_updated = True
                        contacts.save()
                    else:
                        contacts = Contact(user=request.user, contact_name=user.name,
                                      contact_number=user.mobile_number,
                                      is_on_contag=1, contact_contag_user=user)

                    contacts = Contact.set_contag_visibility(contacts=[contacts], current_user_id=request.user.id)
                    response = ContactViewSerializer(instance=contacts, many=True, context={'current_user': request.user.id}).data
                else:
                    contacts = Contact.objects.filter(user=request.user)

                    contacts = Contact.set_contag_visibility(contacts, current_user_id=request.user.id)
                    response = ContactViewSerializer(instance=contacts, many=True, context={'current_user': request.user.id}).data

            return JSONResponse(response, status=200)
        except Exception as e:
            print traceback.format_exc(e)
            beam(e, request)
            return JSONResponse(ERROR_MESSAGE, status=200)
开发者ID:trolltartar,项目名称:contagbackend,代码行数:46,代码来源:views.py

示例2: post

# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import set_contag_visibility [as 别名]
    def post(self, request):

        try:

            # Create/Update whatever contacts come from the app
            contact_numbers = [contact["contact_number"] for contact in request.data]
            contact_names = [contact["contact_name"] for contact in request.data]

            contacts = Contact.objects.filter(user=request.user)
            synced_contacts = []
            #Update the existing contacts saved in db, this is an update on the name
            #Explicitly this checks if the saved user is on contag and sets the boolean accordingly
            for contact in contacts.iterator():
                if contact.contact_number in contact_numbers:
                    index = contact_numbers.index(contact.contact_number)
                    contact.contact_name = contact_names[index]
                    contact.save()
                    del contact_numbers[index]
                    del contact_names[index]
                synced_contacts.append(contact)

            new_contacts = []
            for new_contact in contact_numbers:
                index = contact_numbers.index(new_contact)
                if not request.user.mobile_number == new_contact:
                    new = Contact.objects.create(user=request.user, contact_number=new_contact,
                                                 contact_name=contact_names[index])
                    new_contacts.append(new)

            synced_contacts.extend(new_contacts)
            synced_contacts = Contact.set_contag_visibility(contacts=synced_contacts, current_user_id=request.user.id)

            response_data = ContactViewSerializer(instance=synced_contacts, many=True, context={'current_user': request.user.id}).data
            print "Just synced contacts"
            if request.user.is_new:
                print "Yes the user is new, going to create feeds and notifications"
                request.user.new_user_update()

            return JSONResponse(response_data, status=200)
        except Exception as e:
            print traceback.format_exc(e)
            beam(e, request)
            return JSONResponse(VALIDATION_ERROR_MESSAGE, status=200)
开发者ID:trolltartar,项目名称:contagbackend,代码行数:45,代码来源:views.py


注:本文中的models.Contact.set_contag_visibility方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。