コード例 #1
0
ファイル: views.py プロジェクト: autogestion/socialhome
    def get(self, request, *args, **kwargs):
        """Redirect to user detail view if root page is a profile or if the user is logged in"""

        if settings.SOCIALHOME_HOME_VIEW:
            p, m = settings.SOCIALHOME_HOME_VIEW.rsplit('.', 1)
            return getattr(import_module(p), m).as_view()(request)

        if request.user.is_authenticated:
            landing_page = request.user.preferences.get(
                "generic__landing_page")
            if landing_page == "profile":
                return ProfileDetailView.as_view()(
                    request, guid=request.user.profile.guid)
            elif landing_page == "profile_all":
                return ProfileAllContentView.as_view()(
                    request, guid=request.user.profile.guid)
            elif landing_page == "followed":
                return FollowedStreamView.as_view()(request)
            elif landing_page == "public":
                return PublicStreamView.as_view()(request)
            else:
                # Fallback to profile view
                return ProfileDetailView.as_view()(
                    request, guid=request.user.profile.guid)
        if settings.SOCIALHOME_ROOT_PROFILE:
            profile = get_object_or_404(
                Profile, user__username=settings.SOCIALHOME_ROOT_PROFILE)
            return ProfileDetailView.as_view()(request, guid=profile.guid)
        return super(HomeView, self).get(request, *args, **kwargs)
コード例 #2
0
 def _get_request_view_and_content(self,
                                   create_content=True,
                                   anonymous_user=False):
     request = self.client.get("/")
     request.site = get_current_site(request)
     if anonymous_user:
         request.user = AnonymousUser()
         profile = self.profile
     else:
         request.user = self.user
         profile = self.user.profile
     contents = []
     if create_content:
         contents.extend([
             ContentFactory(author=profile, order=3, pinned=True),
             ContentFactory(author=profile, order=2, pinned=True),
             ContentFactory(author=profile, order=1, pinned=True),
         ])
         Content.objects.filter(id=contents[0].id).update(order=3)
         Content.objects.filter(id=contents[1].id).update(order=2)
         Content.objects.filter(id=contents[2].id).update(order=1)
     view = ProfileDetailView(request=request,
                              kwargs={"guid": profile.guid})
     view.object = profile
     view.target_profile = profile
     return request, view, contents, profile
コード例 #3
0
 def get(self, request, *args, **kwargs):
     """Redirect to user detail view if root page is a profile or if the user is logged in"""
     if request.user.is_authenticated:
         return ProfileDetailView.as_view()(request,
                                            guid=request.user.profile.guid)
     if settings.SOCIALHOME_ROOT_PROFILE:
         profile = get_object_or_404(
             Profile, user__username=settings.SOCIALHOME_ROOT_PROFILE)
         return ProfileDetailView.as_view()(request, guid=profile.guid)
     return super(HomeView, self).get(request, *args, **kwargs)
コード例 #4
0
 def _get_request_view_and_content(self, rf, create_content=True):
     request = rf.get("/")
     request.user = UserFactory()
     profile = request.user.profile
     profile.visibility = Visibility.PUBLIC
     profile.save()
     contents = []
     if create_content:
         contents.extend([
             ContentFactory(author=profile, order=3, pinned=True),
             ContentFactory(author=profile, order=2, pinned=True),
             ContentFactory(author=profile, order=1, pinned=True),
         ])
     view = ProfileDetailView(request=request,
                              kwargs={"guid": profile.guid})
     view.object = profile
     view.target_profile = profile
     return request, view, contents, profile
コード例 #5
0
 def _get_request_view_and_content(self, create_content=True):
     request = self.client.get("/")
     request.user = self.user
     profile = request.user.profile
     profile.visibility = Visibility.PUBLIC
     profile.save()
     contents = []
     if create_content:
         contents.extend([
             ContentFactory(author=profile, order=3, pinned=True),
             ContentFactory(author=profile, order=2, pinned=True),
             ContentFactory(author=profile, order=1, pinned=True),
         ])
         Content.objects.filter(id=contents[0].id).update(order=3)
         Content.objects.filter(id=contents[1].id).update(order=2)
         Content.objects.filter(id=contents[2].id).update(order=1)
     view = ProfileDetailView(request=request, kwargs={"guid": profile.guid})
     view.object = profile
     view.target_profile = profile
     return request, view, contents, profile
コード例 #6
0
ファイル: test_views.py プロジェクト: jaywink/socialhome
 def _get_request_view_and_content(self, create_content=True, anonymous_user=False):
     request = self.client.get("/")
     if anonymous_user:
         request.user = AnonymousUser()
         profile = self.profile
     else:
         request.user = self.user
         profile = self.user.profile
     contents = []
     if create_content:
         contents.extend([
             ContentFactory(author=profile, order=3, pinned=True),
             ContentFactory(author=profile, order=2, pinned=True),
             ContentFactory(author=profile, order=1, pinned=True),
         ])
         Content.objects.filter(id=contents[0].id).update(order=3)
         Content.objects.filter(id=contents[1].id).update(order=2)
         Content.objects.filter(id=contents[2].id).update(order=1)
     view = ProfileDetailView(request=request, kwargs={"uuid": profile.uuid})
     view.object = profile
     view.set_object_and_data()
     return request, view, contents, profile
コード例 #7
0
ファイル: views.py プロジェクト: jaywink/socialhome
    def get(self, request, *args, **kwargs):
        """Redirect to user detail view if root page is a profile or if the user is logged in"""

        if settings.SOCIALHOME_HOME_VIEW:
            p, m = settings.SOCIALHOME_HOME_VIEW.rsplit('.', 1)
            return getattr(import_module(p), m).as_view()(request)

        if request.user.is_authenticated:
            landing_page = request.user.preferences.get("generic__landing_page")
            if landing_page == "profile":
                return ProfileDetailView.as_view()(request, uuid=request.user.profile.uuid)
            elif landing_page == "profile_all":
                return ProfileAllContentView.as_view()(request, uuid=request.user.profile.uuid)
            elif landing_page == "followed":
                return FollowedStreamView.as_view()(request)
            elif landing_page == "public":
                return PublicStreamView.as_view()(request)
            else:
                # Fallback to profile view
                return ProfileDetailView.as_view()(request, uuid=request.user.profile.uuid)
        if settings.SOCIALHOME_ROOT_PROFILE:
            profile = get_object_or_404(Profile, user__username=settings.SOCIALHOME_ROOT_PROFILE)
            return ProfileDetailView.as_view()(request, uuid=profile.uuid)
        return super(HomeView, self).get(request, *args, **kwargs)