Django Tables Link Column link to page with query - django

I have a Django table (Django Tables 2) with Link Column containing a link to another page with another table with the search form. So after click, I get from:
localhost:8000/stats/office/
to:
localhost:8000/stats/office/workers/
However, I would like to filter data by search form in the table in the second page, so it would render only clicked office (e.g. "1" as in this query):
localhost:8000/stats/office/workers/?action=submit&office=1&owner=&date_month=0&date_year=2016&submit=search
my code looks like:
#table.py
office = tables.LinkColumn('stats:office-workers', verbose_name=_(u'Pobočka'), accessor='office')
#urls.py
url(r'^stats/office/$', login_required(permission_required('view_office', raise_exception=True)(OfficeSummarizeList.as_view())), name='office'),
url(r'^stats/office/workers/$', login_required(permission_required('view_worker', raise_exception=True)(WorkerSummarizeList.as_view())), name='stats-office-workers'),
I tried many things but I was not able to pass the parameter 'office' to the view, thank you very much for your help.

Finally figured it out myself, this was enough:
table.py
office = tables.TemplateColumn('{{ record.office }}')

Related

Flask WTForms - option_widget for SelectMultipleField?

I have a field in my Flask WTForm which uses a SelectMultipleField. I'm using a frontend library which renders the choices fine from the db and adds them to the input field as tags when I select them (like the tags do on this website when creating a question!).
However the data is not being saved, form.field.data and request.form.getlist('field') etc all show None. If I add option_widget=widgets.CheckboxInput to the SelectMultipleField, I can select and save data.
So what I'm wondering is, do I need make a custom field or widget in order for the form to use the selected options as the form data (for example, instead of checking if the field has been checked, it checks if it's in the input field). Going a bit mad reading all the documentation so grateful for a hint in the right direction! Code below:
field = SelectMultipleField(
"fieldname",
validators=[Optional()],
widget=widgets.ListWidget(prefix_label=False),
# option_widget=CheckboxInput(),
)
please try this way
from flask_appbuilder.fieldwidgets import Select2ManyWidget
"users": QuerySelectMultipleField(
_("group.user"),
query_factory=lambda: db.session.query(User),
widget=Select2ManyWidget(),
default=[],
),
The result will look like the image below

How to show django filter form elements seperately

I am new to django and using the material online I was able to build a filtering form using django-filter. I am able to show the filter on the html page using a format as below:
{{filtergroup.form}}
This does show the filter correctly and worked well on the page however I wanted to check if there is a way to show individual elements / filters in the form separately so that I can arrange the filters and format easily. Please advise.
Thank you!
If you have a field, say, author, you can access it like this :
{{ filter.form.author }}

joomla 2.5.6: how to fetch all articles by category id

I am using Joomla 2.5.6 and using my custom query wants to fetch all articles by category id. I study Joomla 2.5.6 db model and found xma7k_content table is stores Articles meta and xma7k_categories stores Category info & it seems that we can easily fetch records by id, the alias in xma7k_content table is exactly what the article tile is but the path to view the article is some thing like
destinations/2012-08-08-05-05-05/thailand/overview-of-trips
which stored in xma7k_menu table.
If I remove date/time from path while creating article. (But how I
could?)
or how I could use JOIN xma7k_content, xma7k_categories &
xma7k_menu tables to get required result
Use Acesef Joomla extension and you can define your own SEF URL for the page, download here http://www.joomace.net/joomla-extensions/acesef-joomla-seo-sef-urls.
Check the document for more info.

Getting a list of people who liked a URL with Facebook like button

I'm trying to find the list user ids who clicked on the liked a url address via Facebook Like button.
What I have found so far is that, I can use FQL to get the like information for a facebook object like this:
SELECT user_id FROM like WHERE object_id = 123
With this query I can find the user_id list who like and object. Therefore i need to find the object_id of the url using this query:
SELECT id FROM object_url WHERE url = 'http://localhost/facebook_page.html'
However when I put the returned id to the first query, no result is returned. I have also looked at the url_like table, however I cannot query url column as it's not indexed.
I have found from somewhere else that I have to add fb:admins tag, and force the administrator to like the link for an "open graph page node" to be created in the Graph. I tried that but it did not seemed to work. I don't know how I can check if the "page node" is created or not because I was not able to find any references at all.
user_like table does not work for me, as I cannot use the url column on the where clause.
http://developers.facebook.com/bugs/250668685029065
It seems like it's not possible for now.

Customising specific fields in Django Admin change form

I have a couple of fields in my model that to which I wish to add a link that will allow the user to search for names/files (external from the application's database).
So what I would like is:
Field name: [text box] - LINK
Is there a straightforward django way of achieving this?
Cheers.
You need to change the widget that the form field uses to display the models information. You basically add some html after the input to link to where you want.
Here's some code I put together to create a widget that displays how many characters are left for a CharacterField so it's similar to what you are looking to do:
https://github.com/pastylegs/django-widget-charsleft/blob/master/widget_charsleft/widgets.py