django-helpdesk email template - json

I'm new to Django, and need help with a question about email templates.
I'm using a Django-helpdesk apps and it's have a model name Ticket. Along with many other fields, I would like to add an extra field to it, that is, a field name foo. All database is updated, and when a user submitter a new ticket, an email is sent to the user with some info, i.e submitter_email, dates etc. Everything seems to be correct but the new field foo I've added is blank.
For example, in email templates we can retrieve a ticket id by calling in HTML field:
{{ ticket.ticket }}
you'll get Ticket number 1234, or:
{{ ticket.submitter_email }}
If you want to retrieve a submitter email. But when I call:
{{ ticket.foo }}
the foo is blank.
To mention: Django-Helpdesk email templates using JSON, and south, and I've checked that south is migrated corectly after the field foo is added.
Do I missed something here? I'm very thankful for your help.
Thanks.

I've found my answer. All you need is to add your field foo in the contex of the method safe_template_context(ticket) in the lib.py.

Related

Semantic Wiki: Check form input if value already exists

we have a formular to create host names with some additional information.
Inside the formular we include a template, which gets the values via input fields:
{{{for template|IP|multiple|add button text=Add IP}}}
'''IP:''' {{{field|IP|mandatory|property=Host IP}}}
'''MAC:''' {{{field|MAC}}}
{{{end template}}}
We want to have a check if the given IP adress is already used by another host.
I already tried creating an array and iterating through the values and compare it with a given value: this works.
{{#arraydefine: myArray1 | {{ #ask: [[IP::+]] | mainlabel=- |headers=hide | ?IP }} }}
{{#arrayprint: myArray1||####| {{#ifeq: #### | {{{IP}}} | Duplicate #### <br>| No duplicate #### <br>}} }}
However, if I include this in the form itself, the IP input box doesn't assign the value to an actual variable {{{IP}}} - therefor I cannot access it with the method above.
I then tried to use it on the template "IP" directly. That works, but now it checks with every existing site which uses this template and of course, finds duplicates (because it checks it's own value against the array which also contains the value since it's already existing).
I spent almost 2 work days on this little issue now and I reach the limits of my understanding of semantic wiki. Any ideas would be appreciated.
Thank you in advance!
Since your page name is the host name, and host pages store the IP, you can do the following:
Ask for pages with the same IP as the current page :
{{#ask:[[IP::{{{IP}}}]] |mainlabel=-|?#-=}}
Store the result into an array, lets call it "hosts". The array now contains host names that have the same IP as the current page (with html link removed) and the current page itself.
Create a new array containing a single value, the current page name (using {{FULLPAGENAME}} magic word), lets call it "current"
Substract the two arrays :
{{#arraydiff:duplicate|hosts|current}}
Then check the length of the resulting array "duplicate".
if arraysize > 0, a host page different from current page exists with the same IP.

Passing variables with Jinja2 within 3 templates

I have this problem:
I have 3 templates:
Search_user
Show_user
Edit_user
Whit the search_user I'm getting the name value with the post method, then I'll search the data in the db, save the data in an array called user and then pass the array to the Show_user template.
In the Show_user template I show the data with {{ user[0] }}, {{ user[1] }}...{{ user[7] }}, under this data I have a button that bring me to the Edit_user template.
But in the Edit_user template I don't know how to pass the previous data, I don't know hot to export data with the post method or any other methods.
A walk around could be <input type="text" name="surname" value="user[0]" required> but I don't want to show the textbox in the Show_user template.
You don't need to pass any data except some kind of user identifier (a number or a user name) to fetch the user back from the database when needed.
It can be done in multiple ways:
add it to the endpoint URL in the form action (/user/edit/<user-id>)
or use your web framework session to store the user identifier
or add the identifier to your templates as a hidden form field (type=hidden)
...
In any case you just need to get that piece of information (from the URL endpoint, from the session, from the form data...), use it to fetch the user from the database, then pass the user to the edit template.
If you're using a web framework just read the docs, this is a trivial use case that we'll be very likely well documented.
If you need more details, please, share a few code fragments.

How to store hidden fields inside message in web application?

I have web app (laravel 5.3, mysql) where users can comment any entity in project (almost every page contains something like chat)
I want to add possibility to mention other users inside message via '#' symbol ("Hello, #John, see here", for example).
When this message is posted to chat user named John must get notification about new message (via email, if he is offline).
Every message is connected to some page (/object/45, for example), so when email is sent user will know the page where he was mentioned.
The question is how to store this inside database?
message field has type text
In this example row would contain this data "Hello, #John, see here" (without quotes).
Problem is that there can be many users with name "John" so I can not not do simple:
select email from users where username = 'John' -- email is used as login
Also username can be something like #John Malkovich, so I have to parse string to find out, if "John" or "John Malkovich" was mentioned.
What is unique - user id.
So how to store this inside database?
Possible solution:
Hello, [user=34], see here - field in database
Parse string before displaying to web browser and replace this string with
Hello, #John, see here
but, obviously, no one can paste literal text '[user=123]' inside message, because it would be interpreted as userid.
P.S. Inside one message many users can be mentioned.
Maybe you could create something like <span value="user34">John Malkovich</span> and parse the value?
Or <span data-user-id="user34">John Malkovich</span> is probably better semantically.
Have absolutely no experience in this kind of stuff though, so don't take me too seriously ;)

Admin - Add new post - hook to display some custom input fields

i have a custom post type
this post type needs some fields to be inserted into a custom MySQL table (wp_my_custom_table) where i store some relations IDs with other products and a number to sort them
i don't know how to put these input fields them after the textarea. I know how to insert them at "save_post" action hook.
these are not registered as "custom fields", are just a few input fields needed for each post type like this
The tag doesn't work, so i put the code that i have tried as image:
I have found, there is a hook "edit_form_after_editor".

Change post type name without losing custom field values

I need to change the name of one of my custom post types. These posts have several custom fields associated with them. After changing the name, I update the name of the post types in the database and all of the posts appear again in Wordpress. However, they seem to have lost their custom field information. Is this also updatable?
Just Run following query in your wp_posts
UPDATE `wp_posts` SET `post_type`='<old-value>' WHERE `post_type`='new value';
Do remember to enter your old post type name and new post type name, changing post type name will not effect custom fields as meta fields are associated with post id only.
Cheers...