pax_global_header00006660000000000000000000000064132435043510014512gustar00rootroot0000000000000052 comment=45b838767072b59231bedc40644aeaf16498e495 django-stronghold-0.3.0+debian/000077500000000000000000000000001324350435100163535ustar00rootroot00000000000000django-stronghold-0.3.0+debian/.gitignore000066400000000000000000000000651324350435100203440ustar00rootroot00000000000000*.pyc *.DS_Store dist *.egg-info build *.ropeproject django-stronghold-0.3.0+debian/.travis.yml000066400000000000000000000034211324350435100204640ustar00rootroot00000000000000language: python python: - "2.6" - "2.7" - "3.4" - "3.5" - "3.6" env: - DJANGO_VERSION="django>=1.4,<1.5" - DJANGO_VERSION="django>=1.5,<1.6" - DJANGO_VERSION="django>=1.6,<1.7" - DJANGO_VERSION="django>=1.7,<1.8" - DJANGO_VERSION="django>=1.8,<1.9" - DJANGO_VERSION="django>=1.9,<1.10" - DJANGO_VERSION="django>=1.10,<1.11" - DJANGO_VERSION="django>=1.11,<1.12" - DJANGO_VERSION="django>=2.0,<2.1" matrix: exclude: - python: "2.6" env: DJANGO_VERSION="django>=1.7,<1.8" - python: "2.6" env: DJANGO_VERSION="django>=1.8,<1.9" - python: "2.6" env: DJANGO_VERSION="django>=1.9,<1.10" - python: "2.6" env: DJANGO_VERSION="django>=1.10,<1.11" - python: "2.6" env: DJANGO_VERSION="django>=1.11,<1.12" - python: "2.6" env: DJANGO_VERSION="django>=2.0,<2.1" - python: "2.7" env: DJANGO_VERSION="django>=2.0,<2.1" - python: "3.4" env: DJANGO_VERSION="django>=1.4,<1.5" - python: "3.4" env: DJANGO_VERSION="django>=1.5,<1.6" - python: "3.4" env: DJANGO_VERSION="django>=1.6,<1.7" - python: "3.4" env: DJANGO_VERSION="django>=1.7,<1.8" - python: "3.5" env: DJANGO_VERSION="django>=1.4,<1.5" - python: "3.5" env: DJANGO_VERSION="django>=1.5,<1.6" - python: "3.5" env: DJANGO_VERSION="django>=1.6,<1.7" - python: "3.5" env: DJANGO_VERSION="django>=1.7,<1.8" - python: "3.6" env: DJANGO_VERSION="django>=1.4,<1.5" - python: "3.6" env: DJANGO_VERSION="django>=1.5,<1.6" - python: "3.6" env: DJANGO_VERSION="django>=1.6,<1.7" - python: "3.6" env: DJANGO_VERSION="django>=1.7,<1.8" install: - pip install -r requirements.txt - pip install $DJANGO_VERSION - python setup.py install script: make test django-stronghold-0.3.0+debian/CONTRIBUTING.md000066400000000000000000000005301324350435100206020ustar00rootroot00000000000000#Contributing * Let PEP8 be your guide. * Please include tests if new code isn't covered by existing tests * Please [squash the commits in your Pull request into a single commit](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html). Unless there are some extenuating circumstances why you think you shouldn't. * Have fun django-stronghold-0.3.0+debian/LICENSE000066400000000000000000000020451324350435100173610ustar00rootroot00000000000000Copyright (c) 2013-2014 Mike Grouchy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. django-stronghold-0.3.0+debian/MANIFEST.in000066400000000000000000000000331324350435100201050ustar00rootroot00000000000000include *.txt include *.md django-stronghold-0.3.0+debian/Makefile000066400000000000000000000002531324350435100200130ustar00rootroot00000000000000test: python test_project/manage.py test --settings=test_project.settings stronghold.tests update-pypi: python setup.py sdist upload python setup.py bdist_wheel upload django-stronghold-0.3.0+debian/README.md000066400000000000000000000076141324350435100176420ustar00rootroot00000000000000[![Build Status](https://travis-ci.org/mgrouchy/django-stronghold.svg?branch=master)](https://travis-ci.org/mgrouchy/django-stronghold) # Stronghold Get inside your stronghold and make all your Django views default login_required Stronghold is a very small and easy to use django app that makes all your Django project default to require login for all of your views. WARNING: still in development, so some of the DEFAULTS and such will be changing without notice. ## Installation Install via pip. ```sh pip install django-stronghold ``` Add stronghold to your INSTALLED_APPS in your Django settings file ```python INSTALLED_APPS = ( #... 'stronghold', ) ``` Then add the stronghold middleware to your MIDDLEWARE_CLASSES in your Django settings file ```python MIDDLEWARE_CLASSES = ( #... 'stronghold.middleware.LoginRequiredMiddleware', ) ``` ## Usage If you followed the installation instructions now all your views are defaulting to require a login. To make a view public again you can use the public decorator provided in `stronghold.decorators` like so: ### For function based views ```python from stronghold.decorators import public @public def someview(request): # do some work #... ``` ### For class based views (decorator) ```python from django.utils.decorators import method_decorator from stronghold.decorators import public class SomeView(View): def get(self, request, *args, **kwargs): # some view logic #... @method_decorator(public) def dispatch(self, *args, **kwargs): return super(SomeView, self).dispatch(*args, **kwargs) ``` ### For class based views (mixin) ```python from stronghold.views import StrongholdPublicMixin class SomeView(StrongholdPublicMixin, View): pass ``` ## Configuration (optional) ### STRONGHOLD_DEFAULTS Use Strongholds defaults in addition to your own settings. **Default**: ```python STRONGHOLD_DEFAULTS = True ``` You can add a tuple of url regexes in your settings file with the `STRONGHOLD_PUBLIC_URLS` setting. Any url that matches against these patterns will be made public without using the `@public` decorator. ### STRONGHOLD_PUBLIC_URLS **Default**: ```python STRONGHOLD_PUBLIC_URLS = () ``` If STRONGHOLD_DEFAULTS is True STRONGHOLD_PUBLIC_URLS contains: ```python ( r'^%s.+$' % settings.STATIC_URL, r'^%s.+$' % settings.MEDIA_URL, ) ``` When settings.DEBUG = True. This is additive to your settings to support serving Static files and media files from the development server. It does not replace any settings you may have in `STRONGHOLD_PUBLIC_URLS`. > Note: Public URL regexes are matched against [HttpRequest.path_info](https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.path_info). ### STRONGHOLD_PUBLIC_NAMED_URLS You can add a tuple of url names in your settings file with the `STRONGHOLD_PUBLIC_NAMED_URLS` setting. Names in this setting will be reversed using `django.core.urlresolvers.reverse` and any url matching the output of the reverse call will be made public without using the `@public` decorator: **Default**: ```python STRONGHOLD_PUBLIC_NAMED_URLS = () ``` If STRONGHOLD_DEFAULTS is True additionally we search for `django.contrib.auth` if it exists, we add the login and logout view names to `STRONGHOLD_PUBLIC_NAMED_URLS` ### STRONGHOLD_USER_TEST_FUNC Optionally, set STRONGHOLD_USER_TEST_FUNC to a callable to limit access to users that pass a custom test. The callback receives a `User` object and should return `True` if the user is authorized. This is equivalent to decorating a view with `user_passes_test`. **Example**: ```python STRONGHOLD_USER_TEST_FUNC = lambda user: user.is_staff ``` **Default**: ```python STRONGHOLD_USER_TEST_FUNC = lambda user: user.is_authenticated ``` ##Compatiblity Tested with: * Django 1.4.x * Django 1.5.x * Django 1.6.x * Django 1.7.x * Django 1.8.x * Django 1.9.x * Django 1.10.x * Django 1.11.x * Django 2.0.x ## Contribute See CONTRIBUTING.md django-stronghold-0.3.0+debian/README.rst000066400000000000000000000105541324350435100200470ustar00rootroot00000000000000.. figure:: https://travis-ci.org/mgrouchy/django-stronghold.png?branch=master :alt: travis Stronghold ========== Get inside your stronghold and make all your Django views default login\_required Stronghold is a very small and easy to use django app that makes all your Django project default to require login for all of your views. WARNING: still in development, so some of the DEFAULTS and such will be changing without notice. Installation ------------ Install via pip. .. code:: sh pip install django-stronghold Add stronghold to your INSTALLED\_APPS in your Django settings file .. code:: python INSTALLED_APPS = ( #... 'stronghold', ) Then add the stronghold middleware to your MIDDLEWARE\_CLASSES in your Django settings file .. code:: python MIDDLEWARE_CLASSES = ( #... 'stronghold.middleware.LoginRequiredMiddleware', ) Usage ----- If you followed the installation instructions now all your views are defaulting to require a login. To make a view public again you can use the public decorator provided in ``stronghold.decorators`` like so: For function based views ~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: python from stronghold.decorators import public @public def someview(request): # do some work #... for class based views (decorator) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: python from django.utils.decorators import method_decorator from stronghold.decorators import public class SomeView(View): def get(self, request, *args, **kwargs): # some view logic #... @method_decorator(public) def dispatch(self, *args, **kwargs): return super(SomeView, self).dispatch(*args, **kwargs) for class based views (mixin) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: python from stronghold import StrongholdPublicMixin class SomeView(StrongholdPublicMixin, View): pass Configuration (optional) ------------------------ STRONGHOLD\_DEFAULTS ~~~~~~~~~~~~~~~~~~~~ Use Strongholds defaults in addition to your own settings. **Default**: .. code:: python STRONGHOLD_DEFAULTS = True You can add a tuple of url regexes in your settings file with the ``STRONGHOLD_PUBLIC_URLS`` setting. Any url that matches against these patterns will be made public without using the ``@public`` decorator. STRONGHOLD\_PUBLIC\_URLS ~~~~~~~~~~~~~~~~~~~~~~~~ **Default**: .. code:: python STRONGHOLD_PUBLIC_URLS = () If STRONGHOLD\_DEFAULTS is True STRONGHOLD\_PUBLIC\_URLS contains: .. code:: python ( r'^%s.+$' % settings.STATIC_URL, r'^%s.+$' % settings.MEDIA_URL, ) When settings.DEBUG = True. This is additive to your settings to support serving Static files and media files from the development server. It does not replace any settings you may have in ``STRONGHOLD_PUBLIC_URLS``. Note: Public URL regexes are matched against `HttpRequest.path\_info`_. STRONGHOLD\_PUBLIC\_NAMED\_URLS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can add a tuple of url names in your settings file with the ``STRONGHOLD_PUBLIC_NAMED_URLS`` setting. Names in this setting will be reversed using ``django.core.urlresolvers.reverse`` and any url matching the output of the reverse call will be made public without using the ``@public`` decorator: **Default**: .. code:: python STRONGHOLD_PUBLIC_NAMED_URLS = () If STRONGHOLD\_DEFAULTS is True additionally we search for ``django.contrib.auth`` if it exists, we add the login and logout view names to ``STRONGHOLD_PUBLIC_NAMED_URLS`` STRONGHOLD\_USER\_TEST\_FUNC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Optionally, set STRONGHOLD_USER_TEST_FUNC to a callable to limit access to users that pass a custom test. The callback receives a ``User`` object and should return ``True`` if the user is authorized. This is equivalent to decorating a view with ``user_passes_test``. **Example**: .. code:: python STRONGHOLD_USER_TEST_FUNC = lambda user: user.is_staff **Default**: .. code:: python STRONGHOLD_USER_TEST_FUNC = lambda user: user.is_authenticated Compatiblity ------------ Tested with: - Django 1.4.x - Django 1.5.x - Django 1.6.x - Django 1.7.x - Django 1.8.x - Django 1.9.x - Django 1.10.x - Django 1.11.x - Django 2.0.x Contribute ---------- See CONTRIBUTING.md .. _HttpRequest.path\_info: https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.path_info django-stronghold-0.3.0+debian/changelog.txt000066400000000000000000000000001324350435100210310ustar00rootroot00000000000000django-stronghold-0.3.0+debian/docs/000077500000000000000000000000001324350435100173035ustar00rootroot00000000000000django-stronghold-0.3.0+debian/docs/Makefile000066400000000000000000000127501324350435100207500ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-stronghold.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-stronghold.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/django-stronghold" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-stronghold" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." django-stronghold-0.3.0+debian/docs/conf.py000066400000000000000000000215651324350435100206130ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # django-stronghold documentation build configuration file, created by # sphinx-quickstart on Fri Mar 22 22:25:59 2013. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'django-stronghold' copyright = u'2013, Mike Grouchy' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '0.2.0' # The full version, including alpha/beta/rc tags. release = '0.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'django-strongholddoc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'django-stronghold.tex', u'django-stronghold Documentation', u'Mike Grouchy', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'django-stronghold', u'django-stronghold Documentation', [u'Mike Grouchy'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'django-stronghold', u'django-stronghold Documentation', u'Mike Grouchy', 'django-stronghold', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # -- Options for Epub output --------------------------------------------------- # Bibliographic Dublin Core info. epub_title = u'django-stronghold' epub_author = u'Mike Grouchy' epub_publisher = u'Mike Grouchy' epub_copyright = u'2013, Mike Grouchy' # The language of the text. It defaults to the language option # or en if the language is not set. #epub_language = '' # The scheme of the identifier. Typical schemes are ISBN or URL. #epub_scheme = '' # The unique identifier of the text. This can be a ISBN number # or the project homepage. #epub_identifier = '' # A unique identification for the text. #epub_uid = '' # A tuple containing the cover image and cover page html template filenames. #epub_cover = () # HTML files that should be inserted before the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_pre_files = [] # HTML files shat should be inserted after the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_post_files = [] # A list of files that should not be packed into the epub file. #epub_exclude_files = [] # The depth of the table of contents in toc.ncx. #epub_tocdepth = 3 # Allow duplicate toc entries. #epub_tocdup = True django-stronghold-0.3.0+debian/docs/index.rst000066400000000000000000000007101324350435100211420ustar00rootroot00000000000000.. django-stronghold documentation master file, created by sphinx-quickstart on Fri Mar 22 22:25:59 2013. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to django-stronghold's documentation! ============================================= Contents: .. toctree:: :maxdepth: 2 Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` django-stronghold-0.3.0+debian/requirements.txt000066400000000000000000000001401324350435100216320ustar00rootroot00000000000000Jinja2==2.6 Pygments==1.6 Sphinx==1.1.3 docutils==0.10 mock==1.0.1 django-discover-runner==1.0 django-stronghold-0.3.0+debian/setup.cfg000066400000000000000000000000351324350435100201720ustar00rootroot00000000000000[bdist_wheel] universal = 1 django-stronghold-0.3.0+debian/setup.py000077500000000000000000000023401324350435100200670ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- try: from setuptools import setup except ImportError: from distutils.core import setup dependencies = [] test_dependencies = ['django>1.4.0'] setup( name='django-stronghold', version='0.3.0', description='Get inside your stronghold and make all your Django views default login_required', url='https://github.com/mgrouchy/django-stronghold', author='Mike Grouchy', author_email="mgrouchy@gmail.com", packages=[ 'stronghold', 'stronghold.tests', ], license='MIT license', install_requires=dependencies, tests_require=test_dependencies, long_description=open('README.rst').read(), classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Natural Language :: English', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', ], ) django-stronghold-0.3.0+debian/stronghold/000077500000000000000000000000001324350435100205365ustar00rootroot00000000000000django-stronghold-0.3.0+debian/stronghold/__init__.py000066400000000000000000000000001324350435100226350ustar00rootroot00000000000000django-stronghold-0.3.0+debian/stronghold/conf.py000066400000000000000000000042431324350435100220400ustar00rootroot00000000000000import re try: from django.urls import reverse, NoReverseMatch except ImportError: from django.core.urlresolvers import reverse, NoReverseMatch from django.conf import settings from django.contrib.auth.decorators import login_required STRONGHOLD_PUBLIC_URLS = getattr(settings, 'STRONGHOLD_PUBLIC_URLS', ()) STRONGHOLD_DEFAULTS = getattr(settings, 'STRONGHOLD_DEFAULTS', True) STRONGHOLD_PUBLIC_NAMED_URLS = getattr(settings, 'STRONGHOLD_PUBLIC_NAMED_URLS', ()) def is_authenticated(user): """ make compatible with django 1 and 2 """ try: return user.is_authenticated() except TypeError: return user.is_authenticated STRONGHOLD_USER_TEST_FUNC = getattr(settings, 'STRONGHOLD_USER_TEST_FUNC', is_authenticated) if STRONGHOLD_DEFAULTS: if 'django.contrib.auth' in settings.INSTALLED_APPS: STRONGHOLD_PUBLIC_NAMED_URLS += ('login', 'logout') # Do not login protect the logout url, causes an infinite loop logout_url = getattr(settings, 'LOGOUT_URL', None) if logout_url: STRONGHOLD_PUBLIC_URLS += (r'^%s.+$' % logout_url, ) if settings.DEBUG: # In Debug mode we serve the media urls as public by default as a # convenience. We make no other assumptions static_url = getattr(settings, 'STATIC_URL', None) media_url = getattr(settings, 'MEDIA_URL', None) if static_url: STRONGHOLD_PUBLIC_URLS += (r'^%s.+$' % static_url, ) if media_url: STRONGHOLD_PUBLIC_URLS += (r'^%s.+$' % media_url, ) # named urls can be unsafe if a user puts the wrong url in. Right now urls that # dont reverse are just ignored with a warning. Maybe in the future make this # so it breaks? named_urls = [] for named_url in STRONGHOLD_PUBLIC_NAMED_URLS: try: url = reverse(named_url) named_urls.append(url) except NoReverseMatch: # print "Stronghold: Could not reverse Named URL: '%s'. Is it in your `urlpatterns`? Ignoring." % named_url # ignore non-matches pass STRONGHOLD_PUBLIC_URLS += tuple(['^%s$' % url for url in named_urls]) if STRONGHOLD_PUBLIC_URLS: STRONGHOLD_PUBLIC_URLS = [re.compile(v) for v in STRONGHOLD_PUBLIC_URLS] django-stronghold-0.3.0+debian/stronghold/decorators.py000066400000000000000000000006331324350435100232570ustar00rootroot00000000000000from functools import partial from stronghold.utils import set_view_func_public def public(function): """ Decorator for public views that do not require authentication Sets an attribute in the fuction STRONGHOLD_IS_PUBLIC to True """ orig_func = function while isinstance(orig_func, partial): orig_func = orig_func.func set_view_func_public(orig_func) return function django-stronghold-0.3.0+debian/stronghold/middleware.py000066400000000000000000000026261324350435100232330ustar00rootroot00000000000000from django.contrib.auth.decorators import user_passes_test from stronghold import conf, utils try: from django.utils.deprecation import MiddlewareMixin except ImportError: MiddlewareMixin = object class LoginRequiredMiddleware(MiddlewareMixin): """ Restrict access to users that for which STRONGHOLD_USER_TEST_FUNC returns True. Default is to check if the user is authenticated. View is deemed to be public if the @public decorator is applied to the view View is also deemed to be Public if listed in in django settings in the STRONGHOLD_PUBLIC_URLS dictionary each url in STRONGHOLD_PUBLIC_URLS must be a valid regex """ def __init__(self, *args, **kwargs): if MiddlewareMixin != object: super(LoginRequiredMiddleware, self).__init__(*args, **kwargs) self.public_view_urls = getattr(conf, 'STRONGHOLD_PUBLIC_URLS', ()) def process_view(self, request, view_func, view_args, view_kwargs): if conf.STRONGHOLD_USER_TEST_FUNC(request.user) \ or utils.is_view_func_public(view_func) \ or self.is_public_url(request.path_info): return None decorator = user_passes_test(conf.STRONGHOLD_USER_TEST_FUNC) return decorator(view_func)(request, *view_args, **view_kwargs) def is_public_url(self, url): return any(public_url.match(url) for public_url in self.public_view_urls) django-stronghold-0.3.0+debian/stronghold/models.py000066400000000000000000000000001324350435100223610ustar00rootroot00000000000000django-stronghold-0.3.0+debian/stronghold/tests/000077500000000000000000000000001324350435100217005ustar00rootroot00000000000000django-stronghold-0.3.0+debian/stronghold/tests/__init__.py000066400000000000000000000002571324350435100240150ustar00rootroot00000000000000from stronghold.tests.testdecorators import * from stronghold.tests.testmiddleware import * from stronghold.tests.testmixins import * from stronghold.tests.testutils import * django-stronghold-0.3.0+debian/stronghold/tests/testdecorators.py000066400000000000000000000016231324350435100253210ustar00rootroot00000000000000import functools from stronghold import decorators import django if django.VERSION[:2] < (1, 9): from django.utils import unittest else: import unittest class StrongholdDecoratorTests(unittest.TestCase): def test_public_decorator_sets_attr(self): @decorators.public def function(): pass self.assertTrue(function.STRONGHOLD_IS_PUBLIC) def test_public_decorator_sets_attr_with_nested_decorators(self): def stub_decorator(func): return func @decorators.public @stub_decorator def inner_function(): pass self.assertTrue(inner_function.STRONGHOLD_IS_PUBLIC) def test_public_decorator_works_with_partials(self): def function(): pass partial = functools.partial(function) decorators.public(partial) self.assertTrue(function.STRONGHOLD_IS_PUBLIC) django-stronghold-0.3.0+debian/stronghold/tests/testmiddleware.py000066400000000000000000000061071324350435100252730ustar00rootroot00000000000000import mock import re from stronghold import conf from stronghold.middleware import LoginRequiredMiddleware try: from django.urls import reverse except ImportError: from django.core.urlresolvers import reverse from django.http import HttpResponse from django.test import TestCase from django.test.client import RequestFactory class StrongholdMiddlewareTestCase(TestCase): def test_public_view_is_public(self): response = self.client.get(reverse('public_view')) self.assertEqual(response.status_code, 200) def test_private_view_is_private(self): response = self.client.get(reverse('protected_view')) self.assertEqual(response.status_code, 302) class LoginRequiredMiddlewareTests(TestCase): def setUp(self): self.middleware = LoginRequiredMiddleware() self.request = RequestFactory().get('/test-protected-url/') self.request.user = mock.Mock() self.kwargs = { 'view_func': HttpResponse, 'view_args': [], 'view_kwargs': {}, 'request': self.request, } def set_authenticated(self, is_authenticated): """Set whether user is authenticated in the request.""" user = self.request.user user.is_authenticated.return_value = is_authenticated # In Django >= 1.10, is_authenticated acts as property and method user.is_authenticated.__bool__ = lambda self: is_authenticated user.is_authenticated.__nonzero__ = lambda self: is_authenticated def test_redirects_to_login_when_not_authenticated(self): self.set_authenticated(False) response = self.middleware.process_view(**self.kwargs) self.assertEqual(response.status_code, 302) def test_returns_none_when_authenticated(self): self.set_authenticated(True) response = self.middleware.process_view(**self.kwargs) self.assertEqual(response, None) def test_returns_none_when_url_is_in_public_urls(self): self.set_authenticated(False) self.middleware.public_view_urls = [re.compile(r'/test-protected-url/')] response = self.middleware.process_view(**self.kwargs) self.assertEqual(response, None) def test_returns_none_when_url_is_decorated_public(self): self.set_authenticated(False) self.kwargs['view_func'].STRONGHOLD_IS_PUBLIC = True response = self.middleware.process_view(**self.kwargs) self.assertEqual(response, None) def test_redirects_to_login_when_not_passing_custom_test(self): with mock.patch('stronghold.conf.STRONGHOLD_USER_TEST_FUNC', lambda u: u.is_staff): self.request.user.is_staff = False response = self.middleware.process_view(**self.kwargs) self.assertEqual(response.status_code, 302) def test_returns_none_when_passing_custom_test(self): with mock.patch('stronghold.conf.STRONGHOLD_USER_TEST_FUNC', lambda u: u.is_staff): self.request.user.is_staff = True response = self.middleware.process_view(**self.kwargs) self.assertEqual(response, None) django-stronghold-0.3.0+debian/stronghold/tests/testmixins.py000066400000000000000000000013431324350435100244620ustar00rootroot00000000000000from stronghold.views import StrongholdPublicMixin import django from django.views.generic import View from django.views.generic.base import TemplateResponseMixin if django.VERSION[:2] < (1, 9): from django.utils import unittest else: import unittest class StrongholdMixinsTests(unittest.TestCase): def test_public_mixin_sets_attr(self): class TestView(StrongholdPublicMixin, View): pass self.assertTrue(TestView.dispatch.STRONGHOLD_IS_PUBLIC) def test_public_mixin_sets_attr_with_multiple_mixins(self): class TestView(StrongholdPublicMixin, TemplateResponseMixin, View): template_name = 'dummy.html' self.assertTrue(TestView.dispatch.STRONGHOLD_IS_PUBLIC) django-stronghold-0.3.0+debian/stronghold/tests/testutils.py000066400000000000000000000017601324350435100243160ustar00rootroot00000000000000from stronghold import utils import django if django.VERSION[:2] < (1, 9): from django.utils import unittest else: import unittest class IsViewFuncPublicTests(unittest.TestCase): def test_False_when_not_present(self): def function(): pass is_public = utils.is_view_func_public(function) self.assertFalse(is_public) def test_False(self): def function(): pass function.STRONGHOLD_IS_PUBLIC = False is_public = utils.is_view_func_public(function) self.assertFalse(is_public) def test_True(self): def function(): pass function.STRONGHOLD_IS_PUBLIC = True is_public = utils.is_view_func_public(function) self.assertTrue(is_public) class SetViewFuncPublicTests(unittest.TestCase): def test_sets_attr(self): def function(): pass utils.set_view_func_public(function) self.assertTrue(function.STRONGHOLD_IS_PUBLIC) django-stronghold-0.3.0+debian/stronghold/utils.py000066400000000000000000000005611324350435100222520ustar00rootroot00000000000000def is_view_func_public(func): """ Returns whether a view is public or not (ie/ has the STRONGHOLD_IS_PUBLIC attribute set) """ return getattr(func, 'STRONGHOLD_IS_PUBLIC', False) def set_view_func_public(func): """ Set the STRONGHOLD_IS_PUBLIC attribute on a given function to True """ setattr(func, 'STRONGHOLD_IS_PUBLIC', True) django-stronghold-0.3.0+debian/stronghold/views.py000066400000000000000000000004311324350435100222430ustar00rootroot00000000000000from django.utils.decorators import method_decorator from stronghold.decorators import public class StrongholdPublicMixin(object): @method_decorator(public) def dispatch(self, *args, **kwargs): return super(StrongholdPublicMixin, self).dispatch(*args, **kwargs) django-stronghold-0.3.0+debian/test_project/000077500000000000000000000000001324350435100210605ustar00rootroot00000000000000django-stronghold-0.3.0+debian/test_project/manage.py000077500000000000000000000003771324350435100226740ustar00rootroot00000000000000#!/usr/bin/env python import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv) django-stronghold-0.3.0+debian/test_project/test_project/000077500000000000000000000000001324350435100235655ustar00rootroot00000000000000django-stronghold-0.3.0+debian/test_project/test_project/__init__.py000066400000000000000000000000001324350435100256640ustar00rootroot00000000000000django-stronghold-0.3.0+debian/test_project/test_project/settings.py000066400000000000000000000057721324350435100260120ustar00rootroot00000000000000 DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email@example.com'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'test.db', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } TIME_ZONE = 'America/Toronto' LANGUAGE_CODE = 'en-us' SITE_ID = 1 USE_I18N = True USE_L10N = True USE_TZ = True MEDIA_ROOT = '' MEDIA_URL = '/media/' STATIC_ROOT = '' STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = ( ) # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', #'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # Make this unique, and don't share it with anybody. SECRET_KEY = 'dq73h&uf%a5p(*ns7*!y&7f=)lnn(#aoax_1$e*j)2ziy9b3^!' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', #'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'stronghold.middleware.LoginRequiredMiddleware', ) MIDDLEWARE = MIDDLEWARE_CLASSES ROOT_URLCONF = 'test_project.urls' # Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = 'test_project.wsgi.application' TEMPLATE_DIRS = ( ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'stronghold', ) LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } import django if django.VERSION[:2] < (1, 6): TEST_RUNNER = 'discover_runner.DiscoverRunner' else: TEST_RUNNER = 'django.test.runner.DiscoverRunner' django-stronghold-0.3.0+debian/test_project/test_project/urls.py000066400000000000000000000003401324350435100251210ustar00rootroot00000000000000from django.conf.urls import url from . import views urlpatterns = [ url(r'^protected/$', views.ProtectedView.as_view(), name="protected_view"), url(r'^public/$', views.PublicView.as_view(), name="public_view"), ] django-stronghold-0.3.0+debian/test_project/test_project/views.py000066400000000000000000000011511324350435100252720ustar00rootroot00000000000000from django.views.generic import View from django.http import HttpResponse from django.utils.decorators import method_decorator from stronghold.decorators import public class ProtectedView(View): """A view we want to be private""" def get(self, request, *args, **kwargs): return HttpResponse("ProtectedView") class PublicView(View): """ A view we want to be public""" @method_decorator(public) def dispatch(self, *args, **kwargs): return super(PublicView, self).dispatch(*args, **kwargs) def get(self, request, *args, **kwargs): return HttpResponse("PublicView") django-stronghold-0.3.0+debian/test_project/test_project/wsgi.py000066400000000000000000000021721324350435100251120ustar00rootroot00000000000000""" WSGI config for test_project project. This module contains the WSGI application used by Django's development server and any production WSGI deployments. It should expose a module-level variable named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover this application via the ``WSGI_APPLICATION`` setting. Usually you will have the standard Django WSGI application here, but it also might make sense to replace the whole Django WSGI application with a custom one that later delegates to the Django one. For example, you could introduce WSGI middleware here, or combine a Django application with an application of another framework. """ import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. from django.core.wsgi import get_wsgi_application application = get_wsgi_application() # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application)