mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
Add pinyin autocomplete in group message
This commit is contained in:
@@ -9,6 +9,7 @@ from django.utils.safestring import mark_safe
|
|||||||
|
|
||||||
from profile.models import Profile
|
from profile.models import Profile
|
||||||
from profile.settings import NICKNAME_CACHE_TIMEOUT, NICKNAME_CACHE_PREFIX
|
from profile.settings import NICKNAME_CACHE_TIMEOUT, NICKNAME_CACHE_PREFIX
|
||||||
|
from seahub.cconvert import CConvert
|
||||||
from seahub.settings import FILEEXT_ICON_MAP
|
from seahub.settings import FILEEXT_ICON_MAP
|
||||||
from seahub.po import TRANSLATION_MAP
|
from seahub.po import TRANSLATION_MAP
|
||||||
from seahub.shortcuts import get_first_object_or_none
|
from seahub.shortcuts import get_first_object_or_none
|
||||||
@@ -154,3 +155,9 @@ def seahub_urlize(value, autoescape=None):
|
|||||||
return mark_safe(urlize(value, nofollow=True, autoescape=autoescape))
|
return mark_safe(urlize(value, nofollow=True, autoescape=autoescape))
|
||||||
seahub_urlize.is_safe=True
|
seahub_urlize.is_safe=True
|
||||||
seahub_urlize.needs_autoescape = True
|
seahub_urlize.needs_autoescape = True
|
||||||
|
|
||||||
|
cc = CConvert()
|
||||||
|
@register.filter(name='char2pinyin')
|
||||||
|
def char2pinyin(value):
|
||||||
|
"""Convert Chinese character to pinyin."""
|
||||||
|
return cc.convert(value)
|
||||||
|
101
cconvert.py
Normal file
101
cconvert.py
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# Script Name: convert.py
|
||||||
|
# Creation Date: 2010-09-21 02:12
|
||||||
|
# Last Modified: 2011-11-12 18:38:13
|
||||||
|
# Copyright (c)2011, DDTCMS Project
|
||||||
|
# Purpose: This file used for DDTCMS Project
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
# Written by caocao #
|
||||||
|
# Modified by huyoo353@126.com #
|
||||||
|
# caocao@eastday.com #
|
||||||
|
# http://nethermit.yeah.net #
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
# python.
|
||||||
|
import sys,os
|
||||||
|
import re
|
||||||
|
import string
|
||||||
|
class CConvert:
|
||||||
|
def __init__(self):
|
||||||
|
self.has_shengdiao = False
|
||||||
|
self.just_shengmu = False
|
||||||
|
self.spliter = '-'
|
||||||
|
"Load data table"
|
||||||
|
try:
|
||||||
|
fp=open('convert-utf-8.txt')
|
||||||
|
except IOError:
|
||||||
|
print "Can't load data from convert-utf-8.txt\nPlease make sure this file exists."
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
self.data=fp.read().decode("utf-8")# decoded data to unicode
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
def convert1(self, strIn):
|
||||||
|
"Convert Unicode strIn to PinYin"
|
||||||
|
length, strOutKey, strOutValue, i=len(strIn), "", "", 0
|
||||||
|
while i<length:
|
||||||
|
code1 =ord(strIn[i:i+1])
|
||||||
|
if code1>=0x4e02 and code1<=0xe863:
|
||||||
|
strTemp = self.getIndex(strIn[i:i+1])
|
||||||
|
if not self.has_shengdiao:
|
||||||
|
strTemp = strTemp[:-1]
|
||||||
|
strLength = len(strTemp)
|
||||||
|
if strLength<1:strLength=1
|
||||||
|
strOutKey += string.center(strIn[i:i+1], strLength)+" "
|
||||||
|
strOutValue += self.spliter + string.center(strTemp, strLength) + self.spliter
|
||||||
|
else:#ascii code;
|
||||||
|
strOutKey+=strIn[i:i+1]+" "
|
||||||
|
strOutValue+=strIn[i:i+1] + ' '
|
||||||
|
i+=1
|
||||||
|
#############################
|
||||||
|
#txlist = utf8String.split()
|
||||||
|
#out=convert.convert(utf8String)
|
||||||
|
#l=[]
|
||||||
|
#for t in map(convert.convert, txlist):
|
||||||
|
# l.append(t[0])
|
||||||
|
#v = '-'.join(l).replace(' ','').replace(u'--','-').strip('-')
|
||||||
|
#############################
|
||||||
|
return [strOutValue, strOutKey]
|
||||||
|
|
||||||
|
def getIndex(self, strIn):
|
||||||
|
"Convert single Unicode to PinYin from index"
|
||||||
|
if strIn==' ':return self.spliter
|
||||||
|
if set(strIn).issubset("'\"`~!@#$%^&*()=+[]{}\\|;:,.<>/?"):return self.spliter # or return ""
|
||||||
|
if set(strIn).issubset("-—!##%%&&()*,、。:;?? @@\{{|}}~~‘’“”《》【】++==×¥·… ".decode("utf-8")):return ""
|
||||||
|
pos=re.search("^"+strIn+"([0-9a-zA-Z]+)", self.data, re.M)
|
||||||
|
if pos==None:
|
||||||
|
return strIn
|
||||||
|
else:
|
||||||
|
if not self.just_shengmu:
|
||||||
|
return pos.group(1)
|
||||||
|
else:
|
||||||
|
return pos.group(1)[:1]
|
||||||
|
|
||||||
|
def convert(self, strIn):
|
||||||
|
"Convert Unicode strIn to PinYin"
|
||||||
|
if self.spliter != '-' and self.spliter !='_' and self.spliter != '' and self.spliter != ' ':
|
||||||
|
self.spliter = '-'
|
||||||
|
pinyin_list=[]
|
||||||
|
for c in strIn :
|
||||||
|
pinyin_list.append(self.getIndex(c))
|
||||||
|
pinyin=''
|
||||||
|
for p in pinyin_list:
|
||||||
|
if p==' ':
|
||||||
|
pinyin+= self.spliter
|
||||||
|
continue
|
||||||
|
if len(p)<2:# only shengmu,just get one char,or number
|
||||||
|
#if p.isdigit():
|
||||||
|
# pinyin += p + ' '
|
||||||
|
#else:
|
||||||
|
# pinyin += p + ' '
|
||||||
|
pinyin += p + ' '
|
||||||
|
else:
|
||||||
|
if not self.has_shengdiao: p = p[:-1]
|
||||||
|
pinyin += self.spliter + p + self.spliter
|
||||||
|
pinyin = pinyin.replace(' ','') \
|
||||||
|
.replace(self.spliter+self.spliter,self.spliter) \
|
||||||
|
.strip(self.spliter+' ').replace(self.spliter+self.spliter,self.spliter)
|
||||||
|
return pinyin
|
20520
convert-utf-8.txt
Normal file
20520
convert-utf-8.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -194,9 +194,11 @@ addConfirmTo($('.cancel-share'), '确定要取消共享该目录?');
|
|||||||
$(function() {
|
$(function() {
|
||||||
var member_list = [];
|
var member_list = [];
|
||||||
{% for member in members %}
|
{% for member in members %}
|
||||||
member_list.push('{{ member.user_name|email2nickname}}');
|
var nickname = "{{ member.user_name|email2nickname }}";
|
||||||
|
var pinyin = "{{ member.user_name|email2nickname|char2pinyin }}";
|
||||||
|
|
||||||
|
member_list.push({value:nickname + pinyin, label:nickname});
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
addAtAutocomplete('#message', '#group-message-form', member_list);
|
addAtAutocomplete('#message', '#group-message-form', member_list);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -105,18 +105,22 @@ function addAtAutocomplete(ele_id, container_id, data) {
|
|||||||
var lastTerm = extractLast(request.term);
|
var lastTerm = extractLast(request.term);
|
||||||
var lastIndex = lastTerm.lastIndexOf('@');
|
var lastIndex = lastTerm.lastIndexOf('@');
|
||||||
if (lastIndex == 0) {
|
if (lastIndex == 0) {
|
||||||
response($.ui.autocomplete.filter(data, lastTerm.substring(lastIndex+1)));
|
var matcher = new RegExp($.ui.autocomplete.escapeRegex(lastTerm.substring(lastIndex+1)), "i");
|
||||||
|
response($.grep(data, function(value) {
|
||||||
|
return matcher.test(value.value);
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
response();
|
response();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
focus: function() {
|
focus: function() {
|
||||||
|
this.value = ui.item.label;
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
var terms = split(this.value);
|
var terms = split(this.value);
|
||||||
terms.pop();
|
terms.pop();
|
||||||
terms.push('@'.concat(ui.item.value));
|
terms.push('@'.concat(ui.item.label));
|
||||||
terms.push("");
|
terms.push("");
|
||||||
this.value = terms.join(" ");
|
this.value = terms.join(" ");
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user