Information ID from Opencart twig - opencart

trying to get the full URL of a page including the page ID, in this instance, for an information page.
In my header.php controller file i have :
$data['currentURL'] = $this->url->link($this->request->get['route'], '', 'SSL');
But when i call that into my twig file using :
{{ currentURL }}
I only get 1/2 the URL :
index.php?route=information/information
Rather than :
index.php?route=information/information&information_id=10
Where have i gone wrong? And how can i fix this?
Thanks in advance!

Sorted it, this done the trick :
$data['newURL'] = $_SERVER["REQUEST_URI"];
popped that into my header.php controller and it worked out! Thankyou for pointing me in the right direction!

Related

Django links to other other apps

Maybe this question has been answered before in one way or another. But I need to ask because I tried to answer it myself I googled it for days but I couldn't figure it out.
I have an app called reception in my Django project.
I figured out everything but this.
I have the link in the html directing to the right urlpattern.
<p><tab1>Reception</tab1></p>
urlpatterns = [..., path('go_to_reception', views.reception, name='go_to_reception'), ...]
And the view is like this
def reception(request):
return render(request, 'reception.html')
now instead of reception.html I want the link to go the reception page. The app page. What do I need to write there. I have tried everything that came to my mind but nothing worked.
the reception is as follows:
http://127.0.0.1:8000/admin/reception/
So how do I point to this.
Please help!
Thanks
So im just going to write the solution that we discussed in the chat:
{% url "admin:app_list" app_label="reception" %}
documentation
Look, this help you? i solve a similar problem in this way
url.py
path('gotoreception', views.reception, name="go_to_reception"),
html
<a href="{% url 'go_to_reception' slug=slug %}"
model
slug = models.SlugField(max_length=255, unique=True)
view
def home(request, slug):
context = {'yourdata':yourdata}
return render(request,'index.html', context)
On the template tag url you need use the name of your path, you can use a slug if you store the field on your db
3º option but not recommended, you can add the value if you have on a variable but is not a good practice
I recommend you this 2 resources:
https://docs.djangoproject.com/en/2.1/ref/utils/
https://docs.djangoproject.com/en/2.1/ref/templates/builtins/
hardcoded way
can you test this?
urls
urlpatterns = [..., path('reception/', views.reception, name='go_to_reception'), ...]
html
and on the link <a href="127.0.0.1/reception/">
is the hardcoded way but in the future you can have troubles or relative urls, 404 on internal pages
Thank you for your answer Matthew,
After your latest comment, I have changed my code to the following:
<p><tab1>Reception</tab1></p>
and in url.py its:
path('reception/', include('reception.urls', namespace='reception-urls')),
in reception.urls.py
app_name = "reception"
and the message now says:
django.urls.exceptions.NoReverseMatch: Reverse for 'go_to_reception' not found. 'go_to_reception' is not a valid view function or pattern name.
I am sorry for going back and forth like this, but I honestly can't make it work.
have you got a view called go_to_rececption in your reception.views or a url named go_to_reception in your reception.urls?.
and no worries just trying to help!!!

Django: get current url path from actual current page

I have a situation which I hope you can help me. I have read a few post and answers about getting current url path on SO current_url and url TEMPLATE_CONTEXT_PROCESSORS (which are most relevant). But it doesn't seem to fit what I am trying to do. I have a view:
def fish_search(request):
args = {}
#irrelevant code here
args['fishes'] = fishes
args['current_path'] = request.get_full_path()
return render_to_response('ajax_search.html', args)
In my ajax_search.html:
<a id="search-results" href="{{ current_path }}"></a>
And base.html:
div id="search-results" ></div>
Javascript dumps the search results to base.html. And base.html is extended in fishMarket.html, fishDictionary.html, fishRumour.html, etc. So, sadly, the paths that show up are all "/search/"
I want the path to be /fishMarket/ if I am searching from fishMarket.html, /fishDictionary/ should show up if I am searching from fishDictionary.html, and likewise, /fishRumour/ if I am searching from fishRumour.html. Have anyone come across this type of situation? How did you solve this problem? I'm relatively new to django, so please dumb down the solution.
I really appreciate your help. many thanks!
Instead of using request.get_full_path(), which will give you path of search view, use referrer from the HTTP headers.
You can get that with request.META['HTTP_REFERER']

Add comment to a post - NoReverseMatch error

I am building a website with a simple blog.
I follow the instructions from: http://lightbird.net/dbe/blog.html
I got to a point where I see posts, but then he adds links to each post.
I added :
(r"^(\d+)/$", "post"),
to my urls.py and when I added : Comments everything breaks. It's like it's not sending the value. I think I am doing something wrong with the links..
Can anyone check my app?
Admin account : admin/admin.
Wrong code is in: templates/news/list.html
When I delete that line it works.
Here is my code: https://db.tt/b7qpib28
TRACEBACK : http://dpaste.com/1471932/
You need to remove the $ in url pattern that includes news.urls, so in Uploader/uploader/uploader/urls.py change the line 32:
(r"^news/$", include('news.urls')),
by this
(r"^news/", include('news.urls')),
That's all ;) ...this obstruct the rest of url, you can display the url for news.views.main because it didn't add anything to the url but news.views.post need to add the pk parameter
Firstly, your closing single quote is I the wrong place. Secondly, try using the url pattern name instead of the path to the view.
Try the following:
{% url 'post' post.pk %}

Sugarcrm : How to rewrite a document URL

My version :
SugarCRM CE 6.5.2 running on linux
What I want to do :
I've customized the Documents module in "custom/modules/Documents" by writing several logic hooks.
These logic hooks creates new folders in "ressources/" which is my new upload folder. (I've change the 'upload_dir' from "./upload" into "./ressources" in the config.php)
This is done through a custom field created in studio named "folder_name"
And then, the logic hooks cut and paste the document uploaded into this new folder.
What is my problem
So, with all of this, my download url in Edit, Detail and Revisions Subpanel Views is false. I would like to change it to the right folder, like, for example adding a folder parameter in the url
like this :
/index.php?entryPoint=download&folder=Images&id=idDoc&type=Documents
I tried to change the a href link in EditView.tpl or DetailView.tpl, (like )
but it didn't work since they were located in my cache/modules/Documents folder and were overriding when i did a quick repair.
So I copies/pasted the DetailView.tpl and the EditView.tpl into custom/modules/Documents/tpls and tried to override the view.edit.php and the view.detail.php to link the customized templates, but it did not work.
code :
<?php
require_once('include/MVC/View/views/view.detail.php');
class DocumentsViewDetail extends ViewDetail {
function DocumentsViewDetail() {
parent::ViewDetail();
}
function display() {
parent::display();
}
function detailViewProcess() {
$this->processSearchForm();
$this->lv->searchColumns = $this->searchForm->searchColumns;
if (!$this->headers)
return;
if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) {
//here we are overriding with your custom template
$this->lv->setup($this->seed, 'custom/modules/Documents/tpls/DetailView.tpl', $this->where, $this->params);
echo $this->lv->display();
}
}
}
?>
Do you have any idea why this doesn't work?
Do you have any idea on how i could rewrite my URLS or override the Edit, Revisions SubPanel and Details Views?
Please answer, this is URGENT
Thank you by advance.
Try adding the folder parameter to the variable $file_url inside the method fill_in_additional_detail_fields() in modules/Documents/Document.php.
[Edited]
EditView: include/SugarFields/Fields/File/EditView.tpl
DetailView: include/SugarFields/Fields/File/DetailView.tpl
<a href="index.php?entryPoint=download&id={$fields.{{$vardef.fileId}}.value}&type={{$vardef.linkModule}}&folder=test" ...
ListView: include/SugarFields/Fields/File/ListView.tpl
<a href="index.php?entryPoint=download&id={$parentFieldArray.ID}&type={$displayParams.module}{$vardef.displayParams.module}&folder=test" ...
So, thanks to #air4x, i did answer my trouble : overriding the DetailView.tpl
To make it upgrade-safe, i copies it from
include/SugarFields/Fields/File/DetailView.tpl
to
custom/include/SugarFields/Fields/File/DetailView.tpl
It works!
BUT there is a big trouble coming...
explanations :
1] I create a new Document, uploading image01 to Folder01. Save. Database ok. in DetailView the folder name is "Folder01" and the link '//Folder01/image01_id' works.
2] I create another new Document, uploading image02 to Folder02. Save. Databse ok. BUT in DetailView the folder's name is not "Folder02" but "Folder01". AND the link is //Folder01/image02_id so it doesn't work, because in database or in my folders, the file is still in Folder02.
Here is my custom/include/SugarFields/Fields/File/DetailView.tpl code :
//BEGIN the code i modified
<span class="sugar_field" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}">
<a href="ressources/{$fields.folder_name_c.value}/{$fields.{{$vardef.fileId}}.value}" class="tabDetailViewDFLink" target='_blank'>{{sugarvar key='value'}}</a>
</span>
//END the code i modified
{{if isset($vardef) && isset($vardef.allowEapm) && $vardef.allowEapm}}
{if isset($fields.{{$vardef.docType}}) && !empty($fields.{{$vardef.docType}}.value) && $fields.{{$vardef.docType}}.value != 'SugarCRM' && !empty($fields.{{$vardef.docUrl}}.value) }
{capture name=imageNameCapture assign=imageName}
{$fields.{{$vardef.docType}}.value}_image_inline.png
{/capture}
{sugar_getimage name=$imageName alt=$imageName other_attributes='border="0" '}
{/if}
{{/if}}
{{if !empty($displayParams.enableConnectors)}}
{{sugarvar_connector view='DetailView'}}
{{/if}}
I really don't know why my $fields.folder_name_c.value stay from the first document and replace the one in the second document...
Do you know how i could do a sql query in my EditView.tpl to change it and have the right value?
Please, i really need help.
Thank you
(ps : #air4x, thanks a LOT, even if i have another trouble, that showed me hox to override EditView. THANK YOU! )

tag url template django doesn't work

I trying to implement the url template tag into my project.
I have a button that allows the user to save the data he is seeing.
So the url of this button is this:
(2)url(r'^nameviews/download/$', 'my.path.is.this.to.download' name="load"),
template:
Download
the url of the page that shows the information, and where the button is located is:
(1)(r'^nameviews/$', path.to.page),
but when I tried to click on the button (it should appear the url 2)it doesn't open the file with the data but instead gives me the same url that the main page (1)
the html validator gives me a error on the
<a href="">
It seems it doesn't recognize the url tag.
Anyone has any idea?
Resolved! I didn't really understood what's happen because I didn't change much but should have been some silly mistake.
Sorry!
Thanks any way :)
EDIT
Be careful with the order of the urls. At urls.py try this order:
url(r'^nameviews/download/$', name_of_view, name="load"),
url(r'^nameviews/$', name_of_view, name="first page"),
name_of_view is equal if the view is the same