I have a Django website in which I want site administrators to be able to edit rich content.
Suppose we're talking about an organizational info page, which might include some pictures, and some links, where the page is not as structured as a news page (which updates with news pieces every few days), but still needs the ability to be easily edited by site admins which do not necessarily want to mess with HTML (or rather, I do not want them to).
So where do I put this dynamic content? On the database? In which format? How do I make it accesible in the django default admin?
Use one of the existing rich-text editors
The lightest weight would be to use something at the js level like DojoEditor:
http://code.djangoproject.com/wiki/AddDojoEditor
See also this thread:
Replace textarea with rich text editor in Django Admin?
For what you're describing I'd use flatpages, which is a django app that lets users create and edit pages in the admin panel.
As for formatting, I'd use TinyMCE. Integrating it is pretty easy, here is a walkthrough (do steps 1 and 2 and jump to the bottom, "Using TinyMCE with flatpages (newforms)")
Related
So in the Django tutorials we make a sparse polls application that shows off some of what Django can do, but leaves a lot to be desired when it comes to learning Django (e.g. using their UserCreationForm to make a user portal).
In part of the tutorial they talk about how the admin should be publishing content (e.g. if it were a blog or newspaper) and we set up the admin site where one can make new questions for the polls.
In regard to the blog idea - since an article would be lengthy most likely - I think the correct model would include models.TextField. However, looking at Django's naturally generated admin site for adding / modifying new models with a TextField leaves a lot to be desired.
What if there should be images embedded among the text? or what if there should be formatted text? The admin site does not support a user friendly way to do this.
My question is how to produce a user friendly way for making mixed media e.g. a Stack Exchange post which might have images, code formatting, text formats, etc.
You could use Django Pagedown which aims exactly to offer a way of editing similar to that found on stackexchange sites. As for now you cannot yet upload images (this feature is though on the todos list of the author), they must be already uploaded somewhere on the web and you can insert them using their url.
I have an app that allows users (admins actually) to add html to a model. Then I serve that html on some page to other users (nonadmins). I would like to allow the admins to create arbitrary html on these pages, including adding images. I don't want the admins to have to jump through hoops to get their content into this html field. Suppose a user has some images on their local machine that they want to go into this html field they are creating. I want it to be super brain-dead easy for them to get those images in there.
Right now I just have a model with an html field and I provide a WYSIWYG editor . On a page that users can see, I just load that model.html (filter it as safe) and display. But if the admin user wants to add an image, they still have to figure out hosting and linking in their html document.
Is there a way to use Django flatpages + static to achieve this? Or some kind of app that provides a wordpress-like editor inside Django?
Honestly I would recommend just installing Mezzanine. It does exactly what you want and is the most lightweight, simple and Wordpress like of the Django CMSs. It integrates TinyMCE and Django filebrowser like you want and you can throw away the bits you don't want. This is almost definitely the quickest way to do what you want.
I'm new to working with Django and am developing for a client who wants to be able to change page content in the Django Admin. They need to be able to change the html of the index page without editing the files on the server.
I know about flatfiles but I'm not sure that's completely what I'm after as I can't display stuff such as Django forms for example.
EDIT: Kind of like how a CMS works but without the users/group stuff and be able to use Django View modules such as forms.
Any advice?
Thanks
Honestly, the scope of what you're looking for is too huge to cover in this format. There's a number of ways this could be done, but they're all going to require some work and customization based on the client's needs.
Flatpages could work if you allow HTML content and make sure the content is rendered as "safe" in the template. This really only covers the "content" area of the site, though. It wouldn't be wise to use flatpages for an entire site template, including header, sidebar, footer, etc.
You could create editable areas. So, you actually create models for things like headers, sidebars, footers, and modules within those areas, and then just pull them into the template as needed. Then, the client is only editing pieces of the template instead of responsible for the whole HTML document.
Forms are going to be a challenge, because they require backend-processing that requires a connected view. The client won't be able to just arbitrarily drop in some form code and have a form. But, you could use a third-party service form forms and just embed them in the available content regions. Or, there's a couple of django apps that try to implement a type of "form builder" in the admin. That might somehow let the client add a form via something like the shortcodes used in Wordpress, but you'd likely have to lay down some infrastructure to make that work.
At a certain point, stuff like this reaches a point of diminishing returns, though. The only way to allow total customization of the template is to drop down into the actual physical file and make changes there. You can make certain things easier for the client, but ultimately, they either need to scale back their customization needs or deal with the fact that they'll have to work with the filesystem.
I don't believe that is possible at this time. Of course you can edit your models but templates, I think not.
I would find out how much they need to change? If they plan a complete redesign every week then you're still looking for an answer. If they just need a dynamic front page then you can split it up into variables and let them edit sections of html. Much safer and less prone to breaking the html.
I need to implement workflows in my Django-CMS application at work. But form the Django-CMS feature list, we can read:
Editorial workflow
Workflows for publishing and approval.
I tried to search for it and didn't find anything. I've search the Django-CMS documentation (http://docs.django-cms.org/en/latest/index.html) and couldn't find something there either.
Does anyone has a clue about Workflows in Django-CMS (especially for the pages system) ?
An update for 2016:
No Editorial Workflow in django CMS 3 (yet)
django CMS 3 (v3.3.2 as of today) has no editorial workflow. This feature was removed in version 2.3, and replaced by the concept of "simple publishing" (2 versions of content: draft, public). Read the related blog post from Divio for their motivation.
For version 3.5 there is some extended moderation support planned via an addon, as explained by Angelo Dini in a current comment on the original blog post from 2012. Don't bet on it, though.
Control over Editing
If what you want is, at least, some control over editing, e.g. "some users are allowed to create and edit only but can't publish changes", then you're in luck. It works as follows:
Control over editing goes with the following formula, it's a combination of 3 things:
"Staff" status + App permissions + CMS permissions
The first two are plain Django concepts (from django.contrib.auth, see the Django docs) and the latter comes from django CMS. All 3 play together, here's why:
Without "Staff" status no editing is allowed at all, no CMS toolbar for front-end editing is shown either. Note that this status cannot be set on a group, it must be set on individual users. (d'oh!)
Without all app permissions (cms, djangocms-, cmsplugin-, zinnia) assigned to the group (or user directly) there is no editing; the CMS toolbar will be shown and you can typically double-click on content to initiate editing, but django CMS will tell you that you have no permission.
Omitting some of the CMS permissions (e.g. create, publish) disables the buttons on the CMS toolbar. That's about it. There is no message instructing the user what to do or explanation about what is happening (acknowledged, it's difficult to provide a generic solution here), neither are emails or other notifications sent (of course, there is no such thing as an editorial workflow).
IOW, it's possible to split your users into groups and allow them to do just some specific things (editing only, publishing only, etc.), but the user notifications, a central concept to workflow implementions, are not available in django CMS v3.3.
EDIT: See "Editorial workflow for django CMS" in the django CMS developers G+ group for details and a demo of a related implementation.
When you turn on CMS_MODERATION in Django-CMS, you will get three icons next to each page in the page list view. From left to right, these control
whether changes to this page will require moderator approval
whether changes to this page's children will require moderator approval
whether changes to this page's descendents will require moderator approval
When you create or change a page, you will be able to save it, and preview the page or new version of the page on your site, but it will require moderator approval before the page or new version of the page is visible to end users.
I would like to create a single page in the admin site of django where I can change some global variables of the website (title of the website, items in the navigation menu, etc). At the moment I have them coded as context processors but I would like to make them editable. Something similar to what happens in WordPress.
Is this possible?
I can store the data in the databse, but can I have a link in the admin site that goes straight to the first document record and doesnt allow the creation of multiple records (they wouldnt make sense)
Instead of creating a model in the database, would it be possible to change some context_processor from the admin site (I think this would be best)
django-preferences does exactly what you are looking for. The implementation is a bit hacky (particularly the setting of __module__ on the model class to trick Django into thinking it was loaded from a different app), but it works.
This sounds like what the sites framework is intended to help with.
http://docs.djangoproject.com/en/stable/ref/contrib/sites/
"It’s a hook for associating objects and functionality to particular Web sites, and it’s a holding place for the domain names and “verbose” names of your Django-powered sites."
The docs make it sound like it's only good for multiple sites, but it's a great place to put stuff in a single-site-per-django model too.
There's an app called django-values that allows you storing of specific settings in the database.