how to insert arabic characters in database? - django

I'm a Django beginner student that doesn't have much experiences with database
since my country uses Arabic characters , I tried to add some Arabic words in my database instead of Eng., but even when I was typing it in shell (sqlite3) it showed it as ???
how can I insert a word likeمرد‍‍ into database .
also if database doesn't show it correctly why when I add a comment through site in Arabic letters it works perfect?

According to django it supports Unicode data everywhere. You don't need to do anything when Creating Arabic characters in the database using SQLite. if you are on windows 10 just run chcp 1256 in the cmd to change code page session to Code Page 1256 Windows Arabic . if it didn't work just use the Django admin to create your database

Related

Using ColdFusion to show Chinese Characters from AS/400 server

I am writing a ColdFusion program that uses cfquery to get data from an AS/400 iSeries table and then output that data to a web page. Some times the Data is in Chinese, but it does not output the Chinese characters correctly.
I built the query below for testing,
<cfprocessingdirective pageEncoding="UTF-8" />
<cfquery name="Test" Datasource = "AS400">
select dsc1 from sales where ref = '123456'
</cfquery>
<cfoutput>#test.dsc1#</cfoutput>
The result should be "M5方头螺栓" but I only get "M5". I did another test running just:
<cfset x = "M5方头螺栓"/>
<cfoutput>#x#</cfoutput>
and it displays the Chinese no problem.
Since ColdFusion can display the characters when they are written out in the code, but not when it goes to get the data through SQL, it seems like the issue is with either my ODBC settings or my ColdFusion Server Data Source Settings but I'm not familiar enough with these settings to know what needs to be changed to get this working.
A workaround was found and discussed within the comments. Adding some details here as an answer for future visitors to this page.
There are a couple of considerations when dealing with Unicode (Chinese) characters:
The data type for the database table must be set to nvarchar
The form processing script (CFML) must be set to utf-8
I believe ColdFusion defaults to this but you can specify the setting to be sure.For example: <cfprocessingDirective pageEncoding=”utf-8″>
Enable "String Format" within the ColdFusion datasource settings
Under the ColdFusion administrator datasource settings select the appropriate datasource you are using. Then click on the "show advanced settings" button. That will show an option for "String Format" Enable High ASCII characters and Unicode for data sources configured for non-Latin characters. Select this option and save the datasource.
The issue for the OP was that they were using an ODBC datasource and the "String Format" option was not available. After some research and the lack of finding any way to configure an ODBC datasource for that setting I recommended trying to use the builtin JDBC driver for "DB2 Universal Database" that comes with ColdFusion. Switching to that driver resolved this issue for the OP.
From the comments
Good info. Though is "Enable String Format..." necessary with the added support for cf_sql_nvarchar in CF10+? – #Leigh
I do believe Leigh is correct that the newer versions of ColdFusion (10 and later) have much better support for nvarchar fields.
Also to note, it looks like some older versions of ColdFusion don't always work with the installed DB2 Universal Driver, and it doesn't look like the older standard versions even have it, I'm not sure if the newer ones have it either, but using the "other" option with jt400.jar, should also work. - #MHall
You've already proven that CF can output UTF-8 characters correctly. Have you tried running that query in the DB console or UI? Do you get the correct charaters?
If the characters were stored as VARCHAR and not NVARCHAR, then there's nothing you can do. The data has to have been properly stored in the first place.
If the characters are stored correctly in the DB, try adding <cfprocessingdirective pageEncoding="utf-8"> at the top of the request. CF should be using UTF-8 by defualt, but this will force the correct character set if, for some reason, it isn't.

Django template filters not working at all

Currently I have a working Django 1.9 application using Python 3.5 in development. The database is Postgres 9.4.2.0.
I have a TEXT type field in the database which contains raw input gathered from users, which is then rendered back for other users to read.
The raw text contains newlines and whatnot which look like:
chat.freenode.net\r\n#randomchannel
The HTML template itself attempts to replace the line breaks with break tags and escape anything else
{{ post.body|linebreaksbr|escape }}
But it doesn't seem to matter what filters I add to the post.body, it always renders the raw \r\n and never replaces the values with <br> tags.
I am not getting any errors in the development server and the rendering of the template works fine, it just seems the filters are not working.
I'm pulling my hair our trying to work out why these filters are not working. Does anyone have any ideas?
Turns out this had nothing to do with Django itself, which is not surprising.
The data migration which happened between the last and current version broke the newlines in the raw data. Therefore the linebreaksbr was working, but didn't find any linebreaks.

Django character latin1 mysql

I create a django application with existing MySQL database, the problem is the encoding to database is latin1_general_c and the utf8 characters is save like this ñ => ñ , ó => ó, i need present the information in that page in correctly form but django show the information of database like this
recepción, 4 oficinas, 2 baños
i need show like this
recepcíon, 4 oficinas, 2 baños
For many reasons I can't change the database to utf8
what do I do for show information the correctly way?
Django seems to explicitly require that your database use UTF-8:
Django assumes that all databases use UTF-8 encoding. Using other encodings may result in unexpected behavior.
That said, it should be possible to use the custom OPTIONS setting to pass the desired character set to the database driver. See this answer, in which setting charset solved the problem. But you should check the documentation for the specific MySQL driver and database that you're using, since these options are not used by Django itself.
As suggested by the quote above, even if this works to correctly translate strings between the database and unicode, parts of Django still won't work correctly. For example, to correctly validate the length of a CharField Django has to know the encoding, and it will always assume UTF-8.

DCM4CHE cannot display Japnese Character

I am using dcm4che as my PACS and I am inserting a DICOM file which contains the patient name in Japanese character.
But the web based url of dcm4chee is not supporting Japanese character and showing the patient name as garbled characters( like question marks and squares ).
For DCM4CHE i am using postgresql as the DataBase. In DB properties it is showing 'Encoding as UTF8', 'Collation as English_India.1252' and 'Character Type as English_India.1252'. Does my DB supports Japanese character ?
I am new to Database and any help will be appreciated.
EDIT:
This issue was not related to PACS. I obtained a valid DICOM file with Japanese charters( they are using specific character set as \ISO 2022 IR 87 ) and send the same to PACS. Its correctly showing in the PACS. So the issue is with my DICOM file. I also inserted the specific character set as '\ISO 2022 IR 87'. But still I am getting garbled japanese characters.
I am using MergeCom Dicom utility and using 'MC_Set_Value_From_String' API for inserting the japanese string. Am I missing anything ? Is it not possible to insert Japanese characters by using 'MC_Set_Value_From_String' ? I am thinking of using the API MC_Set_Value_From_UnicodeString.
UTF-8 supports all unicode code points, which includes Japanese. So it is unlikely the database is the issue.
What is the content of the Specific Character Set (0008,0005) tag? The default character encoding for dicom is ASCII. There is a section in the dicom spec providing examples of use with Japanese.
I could solve the issue.
The issue was related to the encoding. For Unicode conversion, I was using the windows API "WideCharToMultiByte" with code page was UTF-8. This was not properly converting the Japanese characters which was fixed by using code page as 50222.
You can find all the entire code page from below link.
https://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx

How can I access django admin's transliterator for slugs when using fixtures?

In the admin, if you enter in a slug two things are applied through JS:
The string is made slug-friendly
The string is transliterated if the language is not English, so for example Cyrillic Russian text gets converted into Transliterated Russian ( typed out in English )
I'm basically inserting a couple thousand rows and I need to access this. Does django provide a non-js server-side version of this transliterator which I can access to somehow do the insertion?
Looks like I have to port over the usr/lib/pymodules/python2.5/django/contrib/admin/media/js/urlify.js code unless I can figure out a way to programmatically load all articles on the client side and slugify themselves automatically.