├── .gitignore ├── MANIFEST.in ├── README.rst ├── docs ├── Makefile ├── conf.py ├── index.rst └── make.bat ├── flatpages_x ├── __init__.py ├── admin.py ├── fixtures │ └── test_data.json ├── markdown_parser.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py ├── settings.py ├── templates │ └── flatpages_x │ │ └── _metatag_snippet.html ├── templatetags │ ├── __init__.py │ └── flatpages_x_tags.py ├── tests.py └── utils.py ├── pypi_upload.sh └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.egg-info 3 | .DS_Store* 4 | _build* 5 | build* 6 | dist* 7 | *.wpr 8 | *.wpu 9 | *~ -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include MANIFEST.in 2 | include README.rst 3 | recursive-include docs * 4 | recursive-include flatpages_x/templates * 5 | recursive-include flatpages_x/fixtures * 6 | exclude *.wpr *.wpu .DS_Store -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | Django Flatpage Extensions 3 | =============================== 4 | 5 | An extension to django.contrib.flatpages to provide 6 | 7 | - Better support for **markdown** and other similar markup formats. We provide support for Markdown but you can write your own parser to support rst or creole. 8 | 9 | - Optional support for the excellent **markItUp** jquery editor. This requires the installation ``django-markitup``. 10 | 11 | - Easy inclusion of images in flatpages. Viewing Admin **image thumbnails** requires the installation of ``sorl-thumbnail``. 12 | 13 | - The inclusion of HTML **metatags** such as keywords and descriptions in flatpages. 14 | 15 | - Content **revisions**. 16 | 17 | Migrating you data to flapages_x should not be difficult since the 18 | data which currently in the contrib.Flatpage model (content, titles) is not affected. 19 | Your templates will still utilize the *{{flatpage.content}}* and *{{flatpage.body}}* 20 | context variables. 21 | Once you install flatpages_x, the Markdown 22 | is actually stored in the related Revisions model. 23 | When you save a flatpage, this will be rendered as html via the markdown 24 | parser and saved to the Flatpage.content field 25 | 26 | Contributors 27 | ============ 28 | - `Christopher Clarke `_ 29 | - `Lendl R Smith `_ 30 | - `Mikhail Andreev `_ 31 | - `Eddy `_ 32 | - `Mahmoud Yaser `_ 33 | 34 | Quickstart 35 | =========== 36 | Create a virtual environment for your project and activate it:: 37 | 38 | $ virtualenv mysite-env 39 | $ source mysite-env/bin/activate 40 | (mysite-env)$ 41 | 42 | Next install ``flatpages_x`` :: 43 | 44 | (mysite-env)$ pip install django-flatpages-x 45 | 46 | Add ``flatpages_x`` to your INSTALLED_APPS setting. 47 | 48 | Inside your project run:: 49 | 50 | (mysite-env)$ python manage.py syncdb 51 | 52 | Django-flatpages-x comes with support for `Markdown `_ 53 | You can also associate and display images with your flatpages. 54 | To include your images in your content using reference-style image syntax looks like this :: 55 | 56 | ![Atl text][image.pk] 57 | 58 | Where [image.pk] is the primary key of image the that you want to include. 59 | The primary key of the image 60 | should is visible in the flatpages Admin form which will now contains an inline image form 61 | 62 | markItUp support 63 | ------------------ 64 | If you want to use the excellent markItUp! editor widget. Install django-markItUp:: 65 | 66 | (mysite-env)$ pip install django-markitup 67 | 68 | You need a few configuration steps 69 | 70 | 1. Add 'markitup' to your INSTALLED_APPS setting. 71 | 72 | 2. Add the following to settings:: 73 | 74 | MARKITUP_SET = 'markitup/sets/markdown' 75 | MARKITUP_SKIN = 'markitup/skins/markitup' 76 | MARKITUP_FILTER = ('markdown.markdown', {'safe_mode': True}) 77 | 78 | 3. You need to use the AJAX-based preview for the admin widget:: 79 | 80 | url(r'^markitup/', include('markitup.urls')) 81 | 82 | in your root URLconf. 83 | 84 | 85 | Admin thumbnails 86 | ---------------- 87 | If you want view admin image thumbnails install sorl-thumbnail:: 88 | 89 | (mysite-env)$ pip install sorl-thumbnail 90 | 91 | 1. Add ``sorl.thumbnail`` to your ``settings.INSTALLED_APPS``. 92 | 2. Configure your ``settings`` 93 | 3. If you are using the cached database key value store you need to sync the 94 | database:: 95 | 96 | python manage.py syncdb 97 | 98 | Markup Support 99 | --------------- 100 | Django-flatpages-x come with a simple parser that supports Markdown. However, 101 | you can supply your own parser by setting the value for *FLATPAGES_X_PARSER* 102 | to settings.py. So if you want to use a parser ``myparser_parser`` simply add 103 | the following to you settings :: 104 | 105 | FLATPAGES_X_PARSER= ["flatpages_x.markdown_parser.parse", {}] 106 | 107 | .. end-here 108 | 109 | Documentation 110 | -------------- 111 | 112 | See the `full documentation`_ for more details. 113 | 114 | .. _full documentation: http://django-flatpages-x.readthedocs.org/ 115 | 116 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-flatpages-x.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-flatpages-x.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/django-flatpages-x" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-flatpages-x" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # django-flatpages-x documentation build configuration file, created by 4 | # sphinx-quickstart on Fri Aug 10 11:02:29 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys 15 | import os 16 | 17 | # If extensions (or modules to document with autodoc) are in another directory, 18 | # add these directories to sys.path here. If the directory is relative to the 19 | # documentation root, use os.path.abspath to make it absolute, like shown here. 20 | #sys.path.insert(0, os.path.abspath('.')) 21 | 22 | # -- General configuration ----------------------------------------------------- 23 | 24 | # If your documentation needs a minimal Sphinx version, state it here. 25 | #needs_sphinx = '1.0' 26 | 27 | # Add any Sphinx extension module names here, as strings. They can be extensions 28 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 29 | extensions = [] 30 | 31 | # Add any paths that contain templates here, relative to this directory. 32 | templates_path = ['_templates'] 33 | 34 | # The suffix of source filenames. 35 | source_suffix = '.rst' 36 | 37 | # The encoding of source files. 38 | #source_encoding = 'utf-8-sig' 39 | 40 | # The master toctree document. 41 | master_doc = 'index' 42 | 43 | # General information about the project. 44 | project = u'django-flatpages-x' 45 | copyright = u'2012, Christopher Clarke' 46 | 47 | # The version info for the project you're documenting, acts as replacement for 48 | # |version| and |release|, also used in various other places throughout the 49 | # built documents. 50 | # 51 | # The short X.Y version. 52 | version = '0.1.1' 53 | # The full version, including alpha/beta/rc tags. 54 | release = '0.1.1' 55 | 56 | # The language for content autogenerated by Sphinx. Refer to documentation 57 | # for a list of supported languages. 58 | #language = None 59 | 60 | # There are two options for replacing |today|: either, you set today to some 61 | # non-false value, then it is used: 62 | #today = '' 63 | # Else, today_fmt is used as the format for a strftime call. 64 | #today_fmt = '%B %d, %Y' 65 | 66 | # List of patterns, relative to source directory, that match files and 67 | # directories to ignore when looking for source files. 68 | exclude_patterns = ['_build'] 69 | 70 | # The reST default role (used for this markup: `text`) to use for all documents. 71 | #default_role = None 72 | 73 | # If true, '()' will be appended to :func: etc. cross-reference text. 74 | #add_function_parentheses = True 75 | 76 | # If true, the current module name will be prepended to all description 77 | # unit titles (such as .. function::). 78 | #add_module_names = True 79 | 80 | # If true, sectionauthor and moduleauthor directives will be shown in the 81 | # output. They are ignored by default. 82 | #show_authors = False 83 | 84 | # The name of the Pygments (syntax highlighting) style to use. 85 | pygments_style = 'sphinx' 86 | 87 | # A list of ignored prefixes for module index sorting. 88 | #modindex_common_prefix = [] 89 | 90 | 91 | # -- Options for HTML output --------------------------------------------------- 92 | 93 | # The theme to use for HTML and HTML Help pages. See the documentation for 94 | # a list of builtin themes. 95 | html_theme = 'default' 96 | 97 | # Theme options are theme-specific and customize the look and feel of a theme 98 | # further. For a list of options available for each theme, see the 99 | # documentation. 100 | #html_theme_options = {} 101 | 102 | # Add any paths that contain custom themes here, relative to this directory. 103 | #html_theme_path = [] 104 | 105 | # The name for this set of Sphinx documents. If None, it defaults to 106 | # " v documentation". 107 | #html_title = None 108 | 109 | # A shorter title for the navigation bar. Default is the same as html_title. 110 | #html_short_title = None 111 | 112 | # The name of an image file (relative to this directory) to place at the top 113 | # of the sidebar. 114 | #html_logo = None 115 | 116 | # The name of an image file (within the static path) to use as favicon of the 117 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 118 | # pixels large. 119 | #html_favicon = None 120 | 121 | # Add any paths that contain custom static files (such as style sheets) here, 122 | # relative to this directory. They are copied after the builtin static files, 123 | # so a file named "default.css" will overwrite the builtin "default.css". 124 | html_static_path = ['_static'] 125 | 126 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 127 | # using the given strftime format. 128 | #html_last_updated_fmt = '%b %d, %Y' 129 | 130 | # If true, SmartyPants will be used to convert quotes and dashes to 131 | # typographically correct entities. 132 | #html_use_smartypants = True 133 | 134 | # Custom sidebar templates, maps document names to template names. 135 | #html_sidebars = {} 136 | 137 | # Additional templates that should be rendered to pages, maps page names to 138 | # template names. 139 | #html_additional_pages = {} 140 | 141 | # If false, no module index is generated. 142 | #html_domain_indices = True 143 | 144 | # If false, no index is generated. 145 | #html_use_index = True 146 | 147 | # If true, the index is split into individual pages for each letter. 148 | #html_split_index = False 149 | 150 | # If true, links to the reST sources are added to the pages. 151 | #html_show_sourcelink = True 152 | 153 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 154 | #html_show_sphinx = True 155 | 156 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 157 | #html_show_copyright = True 158 | 159 | # If true, an OpenSearch description file will be output, and all pages will 160 | # contain a tag referring to it. The value of this option must be the 161 | # base URL from which the finished HTML is served. 162 | #html_use_opensearch = '' 163 | 164 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 165 | #html_file_suffix = None 166 | 167 | # Output file base name for HTML help builder. 168 | htmlhelp_basename = 'django-flatpages-xdoc' 169 | 170 | 171 | # -- Options for LaTeX output -------------------------------------------------- 172 | 173 | latex_elements = { 174 | # The paper size ('letterpaper' or 'a4paper'). 175 | #'papersize': 'letterpaper', 176 | 177 | # The font size ('10pt', '11pt' or '12pt'). 178 | #'pointsize': '10pt', 179 | 180 | # Additional stuff for the LaTeX preamble. 181 | #'preamble': '', 182 | } 183 | 184 | # Grouping the document tree into LaTeX files. List of tuples 185 | # (source start file, target name, title, author, documentclass [howto/manual]). 186 | latex_documents = [ 187 | ('index', 'django-flatpages-x.tex', u'django-flatpages-x Documentation', 188 | u'Christopher Clarke', 'manual'), 189 | ] 190 | 191 | # The name of an image file (relative to this directory) to place at the top of 192 | # the title page. 193 | #latex_logo = None 194 | 195 | # For "manual" documents, if this is true, then toplevel headings are parts, 196 | # not chapters. 197 | #latex_use_parts = False 198 | 199 | # If true, show page references after internal links. 200 | #latex_show_pagerefs = False 201 | 202 | # If true, show URL addresses after external links. 203 | #latex_show_urls = False 204 | 205 | # Documents to append as an appendix to all manuals. 206 | #latex_appendices = [] 207 | 208 | # If false, no module index is generated. 209 | #latex_domain_indices = True 210 | 211 | 212 | # -- Options for manual page output -------------------------------------------- 213 | 214 | # One entry per manual page. List of tuples 215 | # (source start file, name, description, authors, manual section). 216 | man_pages = [ 217 | ('index', 'django-flatpages-x', u'django-flatpages-x Documentation', 218 | [u'Christopher Clarke'], 1) 219 | ] 220 | 221 | # If true, show URL addresses after external links. 222 | #man_show_urls = False 223 | 224 | 225 | # -- Options for Texinfo output ------------------------------------------------ 226 | 227 | # Grouping the document tree into Texinfo files. List of tuples 228 | # (source start file, target name, title, author, 229 | # dir menu entry, description, category) 230 | texinfo_documents = [ 231 | ('index', 'django-flatpages-x', u'django-flatpages-x Documentation', 232 | u'Christopher Clarke', 'django-flatpages-x', 'One line description of project.', 233 | 'Miscellaneous'), 234 | ] 235 | 236 | # Documents to append as an appendix to all manuals. 237 | #texinfo_appendices = [] 238 | 239 | # If false, no module index is generated. 240 | #texinfo_domain_indices = True 241 | 242 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 243 | #texinfo_show_urls = 'footnote' 244 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | :end-before: end-here 3 | 4 | 5 | Indices and tables 6 | ================== 7 | 8 | * :ref:`genindex` 9 | * :ref:`modindex` 10 | * :ref:`search` 11 | 12 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. linkcheck to check all external links for integrity 37 | echo. doctest to run all doctests embedded in the documentation if enabled 38 | goto end 39 | ) 40 | 41 | if "%1" == "clean" ( 42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 43 | del /q /s %BUILDDIR%\* 44 | goto end 45 | ) 46 | 47 | if "%1" == "html" ( 48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 49 | if errorlevel 1 exit /b 1 50 | echo. 51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 52 | goto end 53 | ) 54 | 55 | if "%1" == "dirhtml" ( 56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 57 | if errorlevel 1 exit /b 1 58 | echo. 59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 60 | goto end 61 | ) 62 | 63 | if "%1" == "singlehtml" ( 64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 68 | goto end 69 | ) 70 | 71 | if "%1" == "pickle" ( 72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished; now you can process the pickle files. 76 | goto end 77 | ) 78 | 79 | if "%1" == "json" ( 80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished; now you can process the JSON files. 84 | goto end 85 | ) 86 | 87 | if "%1" == "htmlhelp" ( 88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can run HTML Help Workshop with the ^ 92 | .hhp project file in %BUILDDIR%/htmlhelp. 93 | goto end 94 | ) 95 | 96 | if "%1" == "qthelp" ( 97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 98 | if errorlevel 1 exit /b 1 99 | echo. 100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 101 | .qhcp project file in %BUILDDIR%/qthelp, like this: 102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\django-flatpages-x.qhcp 103 | echo.To view the help file: 104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\django-flatpages-x.ghc 105 | goto end 106 | ) 107 | 108 | if "%1" == "devhelp" ( 109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 110 | if errorlevel 1 exit /b 1 111 | echo. 112 | echo.Build finished. 113 | goto end 114 | ) 115 | 116 | if "%1" == "epub" ( 117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 118 | if errorlevel 1 exit /b 1 119 | echo. 120 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 121 | goto end 122 | ) 123 | 124 | if "%1" == "latex" ( 125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 129 | goto end 130 | ) 131 | 132 | if "%1" == "text" ( 133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The text files are in %BUILDDIR%/text. 137 | goto end 138 | ) 139 | 140 | if "%1" == "man" ( 141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 145 | goto end 146 | ) 147 | 148 | if "%1" == "texinfo" ( 149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 150 | if errorlevel 1 exit /b 1 151 | echo. 152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 153 | goto end 154 | ) 155 | 156 | if "%1" == "gettext" ( 157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 158 | if errorlevel 1 exit /b 1 159 | echo. 160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 161 | goto end 162 | ) 163 | 164 | if "%1" == "changes" ( 165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 166 | if errorlevel 1 exit /b 1 167 | echo. 168 | echo.The overview file is in %BUILDDIR%/changes. 169 | goto end 170 | ) 171 | 172 | if "%1" == "linkcheck" ( 173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 174 | if errorlevel 1 exit /b 1 175 | echo. 176 | echo.Link check complete; look for any errors in the above output ^ 177 | or in %BUILDDIR%/linkcheck/output.txt. 178 | goto end 179 | ) 180 | 181 | if "%1" == "doctest" ( 182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 183 | if errorlevel 1 exit /b 1 184 | echo. 185 | echo.Testing of doctests in the sources finished, look at the ^ 186 | results in %BUILDDIR%/doctest/output.txt. 187 | goto end 188 | ) 189 | 190 | :end 191 | -------------------------------------------------------------------------------- /flatpages_x/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1.5' 2 | -------------------------------------------------------------------------------- /flatpages_x/admin.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | from django import forms 4 | from django.contrib import admin 5 | from django.contrib.flatpages.admin import FlatPageAdmin as StockFlatPageAdmin, FlatpageForm 6 | from django.contrib.flatpages.models import FlatPage 7 | from django.utils.translation import ugettext_lazy as _ 8 | from django.utils.functional import curry 9 | 10 | from flatpages_x.models import FlatPageImage, FlatPageMeta, Revision 11 | from flatpages_x.settings import FPX_TEMPLATE_CHOICES 12 | from flatpages_x.settings import PARSER 13 | from flatpages_x.utils import load_path_attr 14 | 15 | # Use markitup if available 16 | try: 17 | from markitup.widgets import AdminMarkItUpWidget as content_widget 18 | except ImportError: 19 | content_widget = forms.Textarea 20 | 21 | # Thumbnails 22 | try: 23 | from sorl.thumbnail import admin as thumbs 24 | except ImportError: 25 | thumbs = None 26 | 27 | 28 | class CustomFlatPageForm(FlatpageForm): 29 | template_name = forms.ChoiceField( 30 | choices=FPX_TEMPLATE_CHOICES, required=False, 31 | label='Template', 32 | help_text=_("Sepcify a template for displaying your content") 33 | ) 34 | 35 | content_md = forms.CharField(label="Content", widget=content_widget()) 36 | content = forms.CharField(widget=forms.Textarea(), required=False) 37 | 38 | def __init__(self, *args, **kwargs): 39 | super(CustomFlatPageForm, self).__init__(*args, **kwargs) 40 | fp = self.instance 41 | 42 | try: 43 | latest_revision = fp.revisions.order_by("-updated")[0] 44 | except IndexError: 45 | latest_revision = None 46 | 47 | if latest_revision: 48 | self.fields["content_md"].initial = latest_revision.content_source 49 | 50 | def save(self): 51 | fp = super(CustomFlatPageForm, self).save(commit=False) 52 | 53 | if PARSER: 54 | render_func = curry(load_path_attr(PARSER[0], **PARSER[1])) 55 | fp.content = render_func(self.cleaned_data["content_md"]) 56 | else: 57 | fp.content = self.cleaned_data["content_md"] 58 | 59 | fp.save() 60 | 61 | r = Revision() 62 | r.flatpage = fp 63 | r.title = fp.title 64 | r.content_source = self.cleaned_data["content_md"] 65 | r.updated = datetime.now() 66 | r.save() 67 | 68 | return fp 69 | 70 | 71 | class FlatPageMetaAdmin(admin.ModelAdmin): 72 | list_display = ('flatpage', 'created',) 73 | list_filter = ('flatpage',) 74 | ordering = ('flatpage',) 75 | search_fields = ('flatpage',) 76 | 77 | 78 | admin.site.register(FlatPageMeta, FlatPageMetaAdmin) 79 | 80 | 81 | class MetaInline(admin.StackedInline): 82 | model = FlatPageMeta 83 | 84 | 85 | class ImageInline(admin.TabularInline): 86 | model = FlatPageImage 87 | 88 | if thumbs is not None: 89 | # Add the mixin to the MRO 90 | class ImageInline(thumbs.AdminImageMixin, ImageInline): 91 | pass 92 | 93 | 94 | class FlatPageAdmin(StockFlatPageAdmin): 95 | fieldsets = ( 96 | (None, {'fields': ('url', 'title', 'content_md', 'template_name',)}), 97 | (_('Advanced options'), {'classes': ('collapse',), 98 | 'fields': ('enable_comments', 'registration_required', 'sites')}), 99 | ) 100 | form = CustomFlatPageForm 101 | inlines = [MetaInline, 102 | ImageInline, 103 | ] 104 | 105 | def save_form(self, request, form, change): 106 | # form.save doesn't take a commit kwarg 107 | return form.save() 108 | 109 | admin.site.unregister(FlatPage) 110 | admin.site.register(FlatPage, FlatPageAdmin) 111 | admin.site.register(FlatPageImage) 112 | admin.site.register(Revision) 113 | -------------------------------------------------------------------------------- /flatpages_x/fixtures/test_data.json: -------------------------------------------------------------------------------- 1 | [{"pk": 1, "model": "flatpages.flatpage", "fields": {"registration_required": false, "title": "This is my flatpage", "url": "/flatpage/", "template_name": "flatpages/image_flatpage.html", "sites": [1], "content": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero. Vivamus pharetra posuere sapien. Nam consectetuer. Sed aliquam, nunc eget euismod ullamcorper, lectus nunc ullamcorper orci, fermentum bibendum enim nibh eget ipsum. Donec porttitor ligula eu dolor. Maecenas vitae nulla consequat libero cursus venenatis. Nam magna enim, accumsan eu, blandit sed, blandit a, eros.\r\n\r\nQuisque facilisis erat a dui. Nam malesuada ornare dolor. Cras gravida, diam sit amet rhoncus ornare, erat elit consectetuer erat, id egestas pede nibh eget odio. Proin tincidunt, velit vel porta elementum, magna diam molestie sapien, non aliquet massa pede eu diam. Aliquam iaculis. Fusce et ipsum et nulla tristique facilisis. Donec eget sem sit amet ligula viverra gravida.\r\n\r\n", "enable_comments": false}}][{"pk": 1, "model": "flatpage_x.flatpagemeta", "fields": {"keywords": "keyword1,keyword2,keyword3,", "description": "Bazinga i am a description", "flatpage": 1, "modified": "2012-02-08 14:50:23", "created": "2012-02-08 14:50:23"}}, {"pk": 1, "model": "flatpage_x.flatpageimage", "fields": {"image_path": "flatpage/2012/02/08/Argentina.gif", "url": "", "timestamp": "2012-02-08 14:50:22", "caption": "flag 1", "flatpage": 1, "slug": "flag1"}}, {"pk": 2, "model": "flatpage_x.flatpageimage", "fields": {"image_path": "flatpage/2012/02/08/China.gif", "url": "", "timestamp": "2012-02-08 14:50:22", "caption": "flag 2", "flatpage": 1, "slug": "flag2"}}, {"pk": 3, "model": "flatpage_x.flatpageimage", "fields": {"image_path": "flatpage/2012/02/08/Finland.gif", "url": "", "timestamp": "2012-02-08 14:50:22", "caption": "flag 3", "flatpage": 1, "slug": "flag3"}}] -------------------------------------------------------------------------------- /flatpages_x/markdown_parser.py: -------------------------------------------------------------------------------- 1 | import re 2 | import markdown 3 | from markdown.inlinepatterns import IMAGE_REFERENCE_RE 4 | 5 | from flatpages_x.models import FlatPageImage 6 | 7 | img_ref_re = re.compile(IMAGE_REFERENCE_RE) 8 | 9 | 10 | def parse(text): 11 | md = markdown.Markdown(['codehilite']) 12 | for iref in re.findall(img_ref_re, text): 13 | img_id = iref[7] 14 | try: 15 | image = FlatPageImage.objects.get(pk=int(img_id)) 16 | md.references[img_id] = (image.image_path.url, '') 17 | except FlatPageImage.DoesNotExist: 18 | pass 19 | return md.convert(text) 20 | -------------------------------------------------------------------------------- /flatpages_x/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10.7 on 2017-05-31 07:59 3 | from __future__ import unicode_literals 4 | 5 | import datetime 6 | from django.db import migrations, models 7 | import django.db.models.deletion 8 | import sorl.thumbnail.fields 9 | 10 | 11 | class Migration(migrations.Migration): 12 | 13 | initial = True 14 | 15 | dependencies = [ 16 | ('flatpages', '0001_initial'), 17 | ] 18 | 19 | operations = [ 20 | migrations.CreateModel( 21 | name='FlatPageImage', 22 | fields=[ 23 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 24 | ('image_path', sorl.thumbnail.fields.ImageField(upload_to='flatpage/%Y/%m/%d')), 25 | ('url', models.CharField(blank=True, max_length=150)), 26 | ('flatpage', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='flatpages.FlatPage')), 27 | ], 28 | ), 29 | migrations.CreateModel( 30 | name='FlatPageMeta', 31 | fields=[ 32 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 33 | ('created', models.DateTimeField(auto_now_add=True)), 34 | ('modified', models.DateTimeField(auto_now=True)), 35 | ('keywords', models.CharField(blank=True, help_text='Separate keywords by commas', max_length=250)), 36 | ('description', models.TextField(blank=True, verbose_name='meta description')), 37 | ('flatpage', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='metadata', to='flatpages.FlatPage')), 38 | ], 39 | options={ 40 | 'verbose_name_plural': 'Page MetaData', 41 | 'verbose_name': 'Page MetaData', 42 | }, 43 | ), 44 | migrations.CreateModel( 45 | name='Revision', 46 | fields=[ 47 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 48 | ('title', models.CharField(max_length=90)), 49 | ('content_source', models.TextField()), 50 | ('updated', models.DateTimeField(default=datetime.datetime.now)), 51 | ('view_count', models.IntegerField(default=0, editable=False)), 52 | ('flatpage', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='revisions', to='flatpages.FlatPage')), 53 | ], 54 | ), 55 | ] 56 | -------------------------------------------------------------------------------- /flatpages_x/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrisdev/django-flatpages-x/a4677d438236effb3cdd0e039d6a06648a9f879c/flatpages_x/migrations/__init__.py -------------------------------------------------------------------------------- /flatpages_x/models.py: -------------------------------------------------------------------------------- 1 | from os.path import split 2 | from datetime import datetime 3 | 4 | from django.db import models 5 | from django.contrib.flatpages.models import FlatPage 6 | from django.utils.translation import ugettext_lazy as _ 7 | 8 | # Thumbnailability 9 | try: 10 | from sorl.thumbnail import ImageField 11 | except ImportError: 12 | ImageField = models.ImageField 13 | 14 | 15 | # Create your models here. 16 | class FlatPageMeta(models.Model): 17 | flatpage = models.OneToOneField(FlatPage, related_name="metadata", on_delete=models.CASCADE) 18 | created = models.DateTimeField(auto_now_add=True) 19 | modified = models.DateTimeField(auto_now=True) 20 | keywords = models.CharField(blank=True, max_length=250, 21 | help_text=_("Separate keywords by commas")) 22 | description = models.TextField( 23 | verbose_name=_('meta description'), blank=True) 24 | 25 | def __unicode__(self): 26 | return self.flatpage.title 27 | 28 | class Meta: 29 | verbose_name = "Page MetaData" 30 | verbose_name_plural = "Page MetaData" 31 | 32 | 33 | class FlatPageImage(models.Model): 34 | flatpage = models.ForeignKey(FlatPage, related_name='images', on_delete=models.CASCADE) 35 | image_path = ImageField(upload_to="flatpage/%Y/%m/%d") 36 | url = models.CharField(blank=True, max_length=150) 37 | 38 | def __unicode__(self): 39 | if self.pk is not None: 40 | img_file = split(self.image_path.url)[1] 41 | return "[%s] %s" % (self.pk, img_file) 42 | else: 43 | return "deleted image" 44 | 45 | 46 | class Revision(models.Model): 47 | """ 48 | Note the revision model stores the markdown while the 49 | flapage contents will store the redered html 50 | """ 51 | flatpage = models.ForeignKey(FlatPage, related_name="revisions", on_delete=models.CASCADE) 52 | title = models.CharField(max_length=90) 53 | content_source = models.TextField() 54 | 55 | updated = models.DateTimeField(default=datetime.now) 56 | 57 | view_count = models.IntegerField(default=0, editable=False) 58 | 59 | def __unicode__(self): 60 | return 'Revision %s for %s' % (self.updated.strftime('%Y%m%d-%H%M'), self.flatpage) 61 | 62 | def inc_views(self): 63 | self.view_count += 1 64 | self.save() 65 | -------------------------------------------------------------------------------- /flatpages_x/settings.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | 3 | PARSER = getattr(settings, 'FLATPAGES_X_PARSER', None) 4 | DEFAULT_TEMPLATE_CHOICES = [ 5 | ('flatpages/default.html', 'Text Only', ), 6 | ] 7 | FPX_TEMPLATE_CHOICES = getattr( 8 | settings, 'FLATPAGES_X_TEMPLATE_CHOICES', DEFAULT_TEMPLATE_CHOICES) 9 | -------------------------------------------------------------------------------- /flatpages_x/templates/flatpages_x/_metatag_snippet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /flatpages_x/templatetags/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrisdev/django-flatpages-x/a4677d438236effb3cdd0e039d6a06648a9f879c/flatpages_x/templatetags/__init__.py -------------------------------------------------------------------------------- /flatpages_x/templatetags/flatpages_x_tags.py: -------------------------------------------------------------------------------- 1 | from django import template 2 | 3 | register = template.Library() 4 | 5 | 6 | @register.inclusion_tag('flatpages_x/_metatag_snippet.html') 7 | def show_meta(flatpage): 8 | ret = { 9 | "keywords": flatpage.metadata.keywords, 10 | "description": flatpage.metadata.description 11 | } 12 | return ret 13 | -------------------------------------------------------------------------------- /flatpages_x/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | from django.contrib.flatpages.models import FlatPage 3 | 4 | 5 | class FpxTestCase(TestCase): 6 | fixtures = ['test_data', ] 7 | 8 | def setUp(self): 9 | self.fp = FlatPage.objects.all()[0] 10 | 11 | def test_flapage_objects(self): 12 | self.fp.images.all() 13 | -------------------------------------------------------------------------------- /flatpages_x/utils.py: -------------------------------------------------------------------------------- 1 | from importlib import import_module 2 | from django.core.exceptions import ImproperlyConfigured 3 | 4 | 5 | def load_path_attr(path): 6 | i = path.rfind(".") 7 | module, attr = path[:i], path[i + 1:] 8 | try: 9 | mod = import_module(module) 10 | except ImportError as e: 11 | raise ImproperlyConfigured("Error importing %s: '%s'" % (module, e)) 12 | try: 13 | attr = getattr(mod, attr) 14 | except AttributeError: 15 | raise ImproperlyConfigured( 16 | "Module '%s' does not define a '%s'" % (module, attr)) 17 | return attr 18 | -------------------------------------------------------------------------------- /pypi_upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # django-flatpages-x shell script to upload to pypi. 3 | 4 | WORKDIR=/tmp/django-flatpages-x-build.$$ 5 | mkdir $WORKDIR 6 | pushd $WORKDIR 7 | 8 | git clone git://github.com/chrisdev/django-flatpages-x.git 9 | cd django-flatpages-x 10 | 11 | /usr/bin/python setup.py sdist upload 12 | 13 | popd 14 | rm -rf $WORKDIR -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from setuptools import setup, find_packages 4 | 5 | 6 | def long_desc(root_path): 7 | FILES = ['README.rst', ] 8 | for filename in FILES: 9 | filepath = os.path.realpath(os.path.join(root_path, filename)) 10 | if os.path.isfile(filepath): 11 | with open(filepath, mode='r') as f: 12 | yield f.read() 13 | 14 | 15 | HERE = os.path.abspath(os.path.dirname(__file__)) 16 | long_description = "\n\n".join(long_desc(HERE)) 17 | 18 | 19 | PACKAGE = "flatpages_x" 20 | NAME = "django-flatpages-x" 21 | DESCRIPTION = "Some Basic extensions for django-contrib-flatpages" 22 | AUTHOR = "Chris Clarke" 23 | AUTHOR_EMAIL = "cclarke@chrisdev.com" 24 | URL = "http://github.com/chrisdev/django-flatpages-x" 25 | VERSION = __import__(PACKAGE).__version__ 26 | 27 | setup( 28 | name=NAME, 29 | version=VERSION, 30 | description=DESCRIPTION, 31 | long_description=long_description, 32 | author=AUTHOR, 33 | author_email=AUTHOR_EMAIL, 34 | license="MIT", 35 | url=URL, 36 | packages=find_packages(exclude=["*.wpr", "*.wpu"]), 37 | include_package_data=True, 38 | classifiers=[ 39 | "Development Status :: 3 - Alpha", 40 | "Environment :: Web Environment", 41 | "Intended Audience :: Developers", 42 | "License :: OSI Approved :: BSD License", 43 | "Operating System :: OS Independent", 44 | "Programming Language :: Python", 45 | "Framework :: Django", 46 | ], 47 | zip_safe=False, 48 | ) 49 | --------------------------------------------------------------------------------