René's URL Explorer Experiment


Title: Is there an obvious way to override PageManager? · Issue #687 · feincms/feincms · GitHub

Open Graph Title: Is there an obvious way to override PageManager? · Issue #687 · feincms/feincms

X Title: Is there an obvious way to override PageManager? · Issue #687 · feincms/feincms

Description: I would like to override a few methods in PageManager - what would be the most efficient way to achieve that? Here's some context to explain why I want to do that. I wanted to use Django's Sites framework, and configure FeinCMS in a way ...

Open Graph Description: I would like to override a few methods in PageManager - what would be the most efficient way to achieve that? Here's some context to explain why I want to do that. I wanted to use Django's Sites fr...

X Description: I would like to override a few methods in PageManager - what would be the most efficient way to achieve that? Here's some context to explain why I want to do that. I wanted to use Django's ...

Opengraph URL: https://github.com/feincms/feincms/issues/687

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Is there an obvious way to override PageManager?","articleBody":"I would like to override a few methods in PageManager - what would be the most efficient way to achieve that?\r\n\r\n* * *\r\n\r\nHere's some context to explain why I want to do that.\r\n\r\nI wanted to use Django's Sites framework, and configure FeinCMS in a way that would allow me to control on which sites any particular page can be shown.\r\n\r\nYes, FeinCMS already has an extension for that:\r\nhttps://github.com/feincms/feincms/blob/e923d0466b74937d36eb45e2c46ea18cfef83d56/feincms/module/page/extensions/sites.py\r\n\r\nHowever:\r\n\r\n1. It creates 'site' ForeignKey (I want to have 'sites' ManyToMany instead, but I easily fixed that by writing a custom extension)\r\n2. It relies on Site.objects.get_current()\r\n\r\nSite.objects.get_current() works only if you have SITE_ID defined in your settings, otherwise it raises an error and asks to provide request in order to deduce the current Site. I omitted SITE_ID from my settings on purpose because I want to achieve behavior documented in Django docs:\r\nhttps://docs.djangoproject.com/en/dev/ref/contrib/sites/\r\n\r\n\u003eIf the setting is omitted, the get_current_site() function will try to get the current site by comparing the domain with the host name from the request.get_host() method.\r\n\r\nThere are a few problems, though.\r\nI noticed that feincms sites extension modifies which pages are treated as active by using the following approach:\r\n\r\n```\r\ndef current_site(queryset):\r\n    return queryset.filter(site=Site.objects.get_current())\r\n\r\nPageManager.add_to_active_filters(current_site, key=\"current_site\")\r\n```\r\n\r\nHowever, without SITE_ID specified in settings, the only way to filter by current site is to somehow pass request to the filtering logic, and from my understanding, with add_to_active_filter there is no way to do so.\r\n\r\nWhich brought me to conclusion that I need to research how Handler view works, because views have access to request.\r\n\r\nI've tried many different approaches, but the only one that worked was to copy FeinCMS Handler code and then manually redefine PageManager methods before Handler class is defined.\r\nhttps://github.com/feincms/feincms/blob/e923d0466b74937d36eb45e2c46ea18cfef83d56/feincms/views/__init__.py#L29\r\n\r\n```\r\nfrom feincms.module.page.models import PageManager\r\nfrom .managers import for_request, page_for_path, best_match_for_path\r\n\r\nPageManager.for_request = for_request\r\nPageManager.page_for_path = page_for_path\r\nPageManager.best_match_for_path = best_match_for_path\r\n\r\nlogger = logging.getLogger(__name__)\r\n\r\nclass Handler(ContentView):\r\n    # ...\r\n```\r\ncustom for_request simply passes request to custom page_for_path and best_match_for_path\r\n\r\npage_for_path and best_match_for_path are overridden in order to accept ``request`` as an argument and to additionally filter pages with .filter(sites__in=[request.site])\r\n\r\nAlthough it's very cumbersome, it actually works.\r\n\r\nI tried other, seemingly more elegant approaches, but they didn't work:\r\n\r\n1. If I create a custom manager and try to redefine ``objects`` in Page, then ``AttributeError: 'NoneType' object has no attribute '_mptt_meta'`` is thrown in django-mptt. It's probably because of all the MetaClass magic. I assume there must be some way to fix that?\r\n2. I can override FEINCMS_DEFAULT_PAGE_MODEL, but it creates many unwanted side-effects (i.e. I will have to manually recreate Page admin to import custom Page model, because current admin.py in FeinCMS does not use FENCMS_DEFAULT_PAGE_MODEL). Even when I did that, I had to rename db_table in the custom Page.Meta class, after which django was still complaining about two different models named Page. I ended up ditching this approach because too many things started falling apart.\r\n3. If I use ``add_to_class('objects', PageSitesManager())`` in my custom extension, where PageSitesManager is the custom Manager will all the important methods overridden, it simply does nothing.\r\n\r\nIs there a more elegant/obvious way to override PageManager without causing errors in django-mptt?","author":{"url":"https://github.com/paramono","@type":"Person","name":"paramono"},"datePublished":"2020-05-31T23:18:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/687/feincms/issues/687"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e0539bb7-eb7f-5ebf-409f-a4e88c96afa2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD8DE:C3485:24A3B2E:2F1479E:6975F197
html-safe-nonce1b718ab1928663d4b1185de391a444f9519c468f70c365b33a99258f0a205acd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOERFOkMzNDg1OjI0QTNCMkU6MkYxNDc5RTo2OTc1RjE5NyIsInZpc2l0b3JfaWQiOiI0MDkzOTk0NzMxMzMzNjExOTI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac0f57fde0803c2b99f461531f2ac7000221def558b2a2f6223e7e0d42483ab3b1
hovercard-subject-tagissue:628065418
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/feincms/feincms/687/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6f4d6edecc2ada3a8628f8e375e6f8fd5deede7f04356c294cf6525491fa0114/feincms/feincms/issues/687
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6f4d6edecc2ada3a8628f8e375e6f8fd5deede7f04356c294cf6525491fa0114/feincms/feincms/issues/687
og:image:altI would like to override a few methods in PageManager - what would be the most efficient way to achieve that? Here's some context to explain why I want to do that. I wanted to use Django's Sites fr...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameparamono
hostnamegithub.com
expected-hostnamegithub.com
None2bce766e7450b03e00b2fc5badd417927ce33a860e78cda3e4ecb9bbd1374cc6
turbo-cache-controlno-preview
go-importgithub.com/feincms/feincms git https://github.com/feincms/feincms.git
octolytics-dimension-user_id935594
octolytics-dimension-user_loginfeincms
octolytics-dimension-repository_id116021
octolytics-dimension-repository_nwofeincms/feincms
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id116021
octolytics-dimension-repository_network_root_nwofeincms/feincms
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasefcca2b8ef702b5f7f91427a6e920fa44446fe312
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/feincms/feincms/issues/687#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffeincms%2Ffeincms%2Fissues%2F687
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffeincms%2Ffeincms%2Fissues%2F687
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=feincms%2Ffeincms
Reloadhttps://patch-diff.githubusercontent.com/feincms/feincms/issues/687
Reloadhttps://patch-diff.githubusercontent.com/feincms/feincms/issues/687
Reloadhttps://patch-diff.githubusercontent.com/feincms/feincms/issues/687
feincms https://patch-diff.githubusercontent.com/feincms
feincmshttps://patch-diff.githubusercontent.com/feincms/feincms
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Ffeincms%2Ffeincms
Fork 236 https://patch-diff.githubusercontent.com/login?return_to=%2Ffeincms%2Ffeincms
Star 1.1k https://patch-diff.githubusercontent.com/login?return_to=%2Ffeincms%2Ffeincms
Code https://patch-diff.githubusercontent.com/feincms/feincms
Issues 25 https://patch-diff.githubusercontent.com/feincms/feincms/issues
Pull requests 2 https://patch-diff.githubusercontent.com/feincms/feincms/pulls
Actions https://patch-diff.githubusercontent.com/feincms/feincms/actions
Projects 0 https://patch-diff.githubusercontent.com/feincms/feincms/projects
Wiki https://patch-diff.githubusercontent.com/feincms/feincms/wiki
Security 0 https://patch-diff.githubusercontent.com/feincms/feincms/security
Insights https://patch-diff.githubusercontent.com/feincms/feincms/pulse
Code https://patch-diff.githubusercontent.com/feincms/feincms
Issues https://patch-diff.githubusercontent.com/feincms/feincms/issues
Pull requests https://patch-diff.githubusercontent.com/feincms/feincms/pulls
Actions https://patch-diff.githubusercontent.com/feincms/feincms/actions
Projects https://patch-diff.githubusercontent.com/feincms/feincms/projects
Wiki https://patch-diff.githubusercontent.com/feincms/feincms/wiki
Security https://patch-diff.githubusercontent.com/feincms/feincms/security
Insights https://patch-diff.githubusercontent.com/feincms/feincms/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/feincms/feincms/issues/687
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/feincms/feincms/issues/687
Is there an obvious way to override PageManager?https://patch-diff.githubusercontent.com/feincms/feincms/issues/687#top
https://github.com/paramono
https://github.com/paramono
paramonohttps://github.com/paramono
on May 31, 2020https://github.com/feincms/feincms/issues/687#issue-628065418
https://github.com/feincms/feincms/blob/e923d0466b74937d36eb45e2c46ea18cfef83d56/feincms/module/page/extensions/sites.pyhttps://github.com/feincms/feincms/blob/e923d0466b74937d36eb45e2c46ea18cfef83d56/feincms/module/page/extensions/sites.py
https://docs.djangoproject.com/en/dev/ref/contrib/sites/https://docs.djangoproject.com/en/dev/ref/contrib/sites/
feincms/feincms/views/__init__.pyhttps://github.com/feincms/feincms/blob/e923d0466b74937d36eb45e2c46ea18cfef83d56/feincms/views/__init__.py#L29
e923d04https://patch-diff.githubusercontent.com/feincms/feincms/commit/e923d0466b74937d36eb45e2c46ea18cfef83d56
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.