Package: armstrong.core.arm_access
Provides a mechanism for restricting access to models inside Armstrong.UsageMake sure thatarmstrong.core.arm_contentis installed in your
environment and has been added to yourINSTALLED_APPS. You will also need
to make sure the models have been installed in your database viaarmstrong syncdb. See the ‘Restricting Content’ and ‘User Memberships’ sections for more
information.Restricting ContentContent objects can have access restricted to certain levels by having them
inherit from thearmstrong.core.arm_access.mixins.AccessMixinclass. This
will allow for the association ofarmstrong.core.arm_access.models.Assignment’s which specify levels that
grant access to that object for a specific time frame.For the basic paywall scenario where some stories are always premium and others
are always public, create twoarmstrong.core.arm_access.models.Level’s. One
will be your premium level which will haveis_protectedset toTruewhile the other will be your public level which will haveis_protectedset
toFalse. When publishing an article, assign one of the two levels to the
content.For content which is premium for a period and then becomes public, create two
levels as before. Assign new content to the premium level with an
immediatestart_date, and also assign it to the public
level with astart_datewhen you would like the content to become freely
available.To restrict access to your archives to only premium subscribers you would add
content to the public level with an immediatestart_dateand anend_dateof when you want to no longer offer free access. You will then
need to add the content to the premium level with an immediatestart_dateand noend_date(which will default todatetime.datetime.max).User MembershipsUsers are granted access to Levels viaarmstrong.core.arm_access.models.AccessMembership’s. Each membership has astart_dateandend_datewhich defines the time frame for which the
membership is valid. Each memrbership also has anactiveboolean field
which can be set to False to invalidate the membership. A user’s active
memberships can be queried withuser.access_memberships.current()PaywallsThe actual process of preventing a user from accessing a piece of content is
handled via the paywalls in thearmstrong.core.arm_access.paywallspackage.
Currently the only provided paywall isarmstrong.core.arm_access.paywalls.subscription.SubscriptionPaywallwhich
checks for current memberships. The SubscriptionPaywall only works on a view
which returns a TemplateResponse.To use the SubscriptionPaywall in the demo app, you would use code like the
following:...

paywall = SubscriptionPaywall()
protected_detail = paywall.protect(object_detail)

...

url(r'^article/(?P<slug>[-\w]+)/', protected_detail, {
                    'queryset':Article.published.all().select_subclasses(),
                    'template_name':'article.html',
                    'slug_field':'slug',
                },
        name='article_detail'),An AccessDenied would be raised any time a user visited an article that was
protected with an access Level that they didn’t have a membership for.
SubscriptionPaywall takes an additional argumentpermission_deniedthat
determines what action to take on failure. The argument must be a callable that
takes one argument, a TemplateResponse, and returns a Response object
representing what to do on access denied. For example:# to redirect to a new url entirely
from armstrong.core.arm_access.paywalls import redirect_on_deny
redirecting_paywall = SubscriptionPaywall(
        permission_denied=redirect_on_deny='/membership/signup')

# to render the request's context with a new template (to provide teaser
# content)
from armstrong.core.arm_access.paywalls import render_on_deny
rendering_paywall = SubscriptionPaywall(
        permission_denied=render_on_deny='/membership/upsell.html')If you wanted to only render ads for users without a premium access level, you
could use the SubscriptionPaywall with a default template that doesn’t render
ads and a render_on_deny that does.To only allow an anonymous user a certain number of full article views and then
display the paywall, you would need to build a custom paywall implementation,
but the SubscriptionPaywall should provide a decent template. If you do
implement it, it would be an excellent candidate for inclusion in this package.Installation & ConfigurationYou can install the latest release ofarmstrong.core.arm_accessusingpip:pip install armstrong.core.arm_accessMake sure to addarmstrong.core.arm_accessto yourINSTALLED_APPS.  You
can add this however you like.  This works as a copy-and-paste solution:INSTALLED_APPS += ["armstrong.core.arm_access", ]Once installed, you have to run eithersyncdb, ormigrateif you are
usingSouth.ContributingCreate something awesome – make the code better, add some functionality,
whatever (this is the hardest part).Fork itCreate a topic branch to house your changesGet all of your commits in the new topic branchSubmit apull requestState of ProjectArmstrong is an open-source news platform that is freely available to any
organization.  It is the result of a collaboration between theTexas TribuneandBay Citizen, and a grant from theJohn S. and James L. Knight
Foundation.To follow development, be sure to join theGoogle Group.armstrong.core.arm_accessis part of theArmstrongproject.  You’re
probably looking for that.LicenseCopyright 2011 Bay Citizen and Texas TribuneLicensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.