Django Show Files on Disk - django

I want to have a page that will show files from a particular folder on the disk and have the user select one and then "pass" the file path of that file to another view for further processing. I have no idea where to start, all of my searching turns up uploading files.

If you only need to display files from one directory on disk, perhaps a simpler solution would be to use the built-in Django FilePathFeld. It will return a path as the value and is represented by a select in forms.
This field isn't for uploading a file, it's only for selecting a pre-existing file.

The only project i know that is still maintained is django-filebrowser
The extension is pretty flexible, you can choose to use paths relative to a storage location or absolute server paths.
You should be able to pass the file path to another view by adding the view's path to your form action attribute like this:
<form name="form" method="post" action="/path/to/view">
...
</form>

Related

Django - How to setup dynamic templating within django

So I am having this major issue regarding the templating setup. I have a model that is created and attaches html, JS, and CSS files on upload to a corresponding folder with the model name. The user is able to upload these files (HTML,CSS,JS), and I need to be able to access the HTML file within this weird location.
/template/app/app.html (the location where the view leads, which idc about)
/media/uploads/modelName1/base.html ( I want to dynamically link each view with their corresponding model folder )
/media/uploads/modelName1/style.css
/media/uploads/modelName1/base.js
for the view I made it so the HTML file of the model is passed within the template and then I can use {% include %} but obv that can't work b.c the HTML included isn't even part of the template. If you have any suggestions on how to approach this problem, it would be much appreciated.

Show article only in popup using Joomla with actual template

I'm using Joomla 3.4 and want to open popup with some article only.
I have this link to load into popop: index.php?option=com_content&view=article&catid=13&Itemid=176&id=6&tmpl=component
I know that I must add tmpl=component but when I add this it load system CSS, JS and HTML layout. It doesn't load active template CSS, JS etc. Why is this happening? Without this attribute it load whole page with active template.
Thanks for advice.
Never mind! I have already done this. I just need to edit component.php file in template.
OK so I found the solution.
I just create file named 'component.php' in the template root folder and edit it as I want. I include my CSS, JS, etc to the file with my specific HTML. So if I add tmpl=component to the URL it looks for compoment.php file. That's all.

Joomla 3 Template override a plugin

I could not find any info on overriding a Joomla plugin in my template.
Some forums claimed there was no plugin override, and the Joomla documentation (being the menacing forest that it is) either has nothing on the subject, or the page is hard to find.
So how can we override the output of a Joomla plugin in the same was we override the output of com_content or mod_contact?
I have found a way to do this:
Navigate to <joomla_homefolder>/administrator/language/<your_language>/
Search for the plugin's corresponding language file.
Copy the file name, EXCLUDING the language prefix (ie en-GB.) and the .ini suffix.
In your template create a folder named html (a common practice for template overrides).
In the html folder create a subfolder and name with the language file name as you copied it in step 3.
Navigate to the tmpl subfolder in the plugin's path: <joomla_homefolder>/plugins/<plugin_type>/<plugin_name>/tmpl
Copy the view file you wish to override into the folder you've created in step 5.
Modify the copied file to override the plugins output.
For example -
To change the page navigation buttons - modify the output of <joomla_homefolder>/plugins/content/pagenavigation:
Go into <joomla_homefolder>/administrator/language/en-GB/ and find the file named en-GB.plg_content_pagenavigation.ini.
From the filename copy only plg_content_pagenavigation.
Create a folder named html (If it does not exist already) in your theme, inside it create a subfolder and name it plg_content_pagenavigation.
Copy the view file <joomla_homefolder>/plugins/content/pagenavigation/tmpl/default.php into the plg_content_pagenavigation folder you just created.
Modify the file.
Note: I have tried it only with Joomla 3.1.
The method may not work with some plugins.
Good Luck.
In joomla 3 you can override plugins output only, that's why the origin plugin must be implemented with a tmpl.
The naming convention of the folder in you [template]/html is
plg_[type*]_[pluginElement]
Template overridden native joomla plugins is only the pagenavigation.
type* : obviously there's no sense to be other than content but if it's custom plugin no one can stop you.
On a Joomla 3.1 install, I am using the Simple Image Gallery plugin and I felt the need to override it in order to add extra functionality to each thumbnail of the gallery.
I copied all of the contents of <joomla_homefolder>/plugins/content/jw_sig/jw_sig/tmpl/ into the folder <joomla_homefolder>/templates/protostar/html/jw_sig/ and I was then able to modify both the default.php file for output modifications, and the accompanying template.css file for styling modifications. This successfully overrides the plugin's output without risking issues during future updates.
Of course, this will not work with all plugins, but it offers another alternative if you have a plugin that was nice enough to be developed with a tmpl folder.
No you can't override the same way because there is not tmpl folder because plugins really should not be rendering though of course a lot do. You probably need to clone the plugin and make a the layout your want possibly using a jlayout to make it easier to manage.
Elin's answer is not quite correct for Joomla 2.5-3.x. Some plugins do render screen output and have /tmpl folders that you may be able to override. See http://docs.joomla.org/Layout_Overrides_in_Joomla
In some cases you may need to create alternative views within the plugin /tmpl folder. For example, some of the simple, newer custom content components that use JForms let you add fields to com_content articles and select a view template for each field. Then overrides for com_content are generated dynamically to display the custom fields. Each field type can be displayed in the component area through plugins, or in a module, or within the template code, but it will use the /tmpl file you selected for the field in the CCK component. If there is a way to override the different field views from within the template folder, it must require an arcane menu structure I haven't been able to discover.

Where to store flat files in CakePHP?

I am building an application that allows a user to browse html templates. The html template will be displayed in a preview area (source code will be obfuscated), and although the template will contain inline CSS/JS, there will also be the odd linked image asset.
For this reason, I thought it might be best for me to just store them as a library of folders, and retrieve the flat file from my server for display, as opposed to storing the HTML in the database and having to organise the external assets too.
My question is: Where in the CakePHP directory structure, is the best home for these files? I'd rather keep them above the webroot, and I'm thinking View.
Any ideas? Thanks.
I would suggest that you keep all the out-of-cakephp-framework related files, stored under the webroot.
My suggestion is the following directory structure for saving the html template as well as the css and js related files.
/webroot/files/templates/<template-project-name>/<the-actual-file>.html
Any external css, would then be under
/webroot/css/templates/<template-project-name>/<the-actual-css>.css
And the JS libraries would be under
/webroot/js/templates/<template-project-name>/<the-actual-js>.js
Use a seperate layout file (call it preview_layout.ctp) which simply renders
the template file as it is.
Hope it helps
Why do you want to store them above the webroot, when they are publicly-viewable assets? My gut feeling is that they really belong in the webroot or in the database. I would pick one or the other.
If you must store them above the webroot, I guess the best thing might be to store them as elements.
app/View/Elements/your_templates/
And that way, you can load it into the preview area of your View using:
echo $this->element('your_templates/template');
Edit:
Honestly, the suggestion of elements is not what I would recommend, I'm just trying to offer you different suggestions. It would be terribly bad practice and I think it will be more messy and problematic than it's worth.
As for the image files, put them in the webroot, regardless of where you choose to store the HTML templates. You can't stop people downloading the images once they are viewing them in their browser anyway.

Django: using {{STATIC_URL}} from python side

Building a "history" system that serves static pages based on the date the user asks for. Not all dates have associated pages, and it isn't possible to know, based on what's in the database which do, which don't. I haven't been able to find a way to redirect to a static page because there doesn't seem to be any way to capture the value of the {{STATIC_URL}} tag on the python side. I have got some code that depends on the static file being on the same file system as the django server, but that is clearly wrong. I have two needs:
1: how can I (redirect?) to the static page(s) from my views.py file?
2: how can I query for the existence of a particular one of those static pages?
I'm not certain from your question if you understand the intention of the {{ STATIC_URL }} tag. It is a URL prefix for static content files such as css, javascript, or image files. It is not intended as a path for your own static HTML files. In the end I'm not sure you are asking the right question for what you are wanting to accomplish.
As zzzirk says: Django really isn't about flat pages, so the most Djangonic solution is to put flat pages beside the django app, not within it.