Changeset 3524

Show
Ignore:
Timestamp:
04/17/08 05:12:23 (9 months ago)
Author:
richard
Message:

TicketTemplate? 0.4 (Mar 25, 2008)

  • add preview to admin page
  • use one persistence file to store all template texts
  • fixed bug: leading space in template text is not stripped now
  • add some default template text for trac's default install:
    • defect
    • enhancement
    • task
    • default
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/En/tickettemplate/changelog.txt

    r3138 r3524  
     1TicketTemplate 0.4 (Mar 25, 2008) 
     2 
     3 * add preview to admin page 
     4 * use one persistence file to store all template texts 
     5 * fixed bug: leading space in template text is not stripped now 
     6 * add some default template text for trac's default install:  
     7  * defect 
     8  * enhancement 
     9  * task 
     10  * default 
     11 
    112TicketTemplate 0.3 (Jan 2, 2008) 
    213 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/En/tickettemplate/readme.txt

    r3273 r3524  
    88 
    99= Install = 
     10 
     11 '''IMPORTANT''': Please BACKUP you ticket templates if you are upgrading this plugin. 
     12 
    1013 You can install this software as normal Trac plugin. 
    1114 
     
    3033}}} 
    3134 
     35 6. If you are installing this plugin first time, you can copy description.tmpl to your/trac/environment/templates to utilize some default ticket templates. 
    3236 
    3337= Prerequisite = 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/En/tickettemplate/templates/admin_tickettemplate.cs

    r3138 r3524  
    22    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    33    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    4 <html xmlns="http://www.w3.org/1999/xhtml" lang="cn" xml:lang="cn" charset="utf-8"> 
     4<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" charset="utf-8"> 
    55<head><title>Available Projects</title></head> 
    66<body> 
     
    2020 
    2121  <div class="field"> 
    22     <label for="description">Full description (you may use <a tabindex="42" href="<?cs 
     22    <label for="description">Full description (you may use <a tabindex="42" href="<?cs  
    2323    var:$trac.href.wiki ?>/WikiFormatting">WikiFormatting</a> here):</label><br /> 
    24     <textarea id="description" name="description" class="wikitext" rows="20" style="width:63%" name="tt_text"><?cs var:tt_text ?></textarea> 
     24    <textarea id="description" name="description" class="wikitext" rows="20" cols="66" name="tt_text"><?cs var:tt_text ?></textarea> 
     25  <?cs 
     26  if:description_preview ?> 
     27   <fieldset id="preview"> 
     28    <legend>preview</legend> 
     29    <?cs var:description_preview ?> 
     30   </fieldset><?cs 
     31  /if ?> 
    2532  </div> 
    26    
    27 </form> 
     33 
    2834 
    2935 <script type="text/javascript" src="<?cs 
    3036   var:htdocs_location ?>js/wikitoolbar.js"></script> 
    3137 
     38 <div class="buttons"> 
     39  <input type="submit" name="preview" value="preview" accesskey="r" />&nbsp; 
     40  <input type="submit" value="submit" /> 
     41 </div> 
     42   
     43</form> 
     44 
     45 
     46 
    3247</html> 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/En/tickettemplate/ttadmin.py

    r3523 r3524  
    1313from trac.web.chrome import INavigationContributor 
    1414from trac.web.chrome import * 
     15from trac.wiki import wiki_to_html, wiki_to_oneliner 
    1516 
    1617from trac.ticket import Milestone, Ticket, TicketSystem, ITicketManipulator 
     
    2324 
    2425import os 
    25 import base64 
     26import pickle 
    2627 
    2728__all__ = ['TicketTemplateModule'] 
     
    120121 
    121122        if req.method == 'POST': 
    122             tt_file_name = "description_%s.tmpl" % req.args.get('type') 
    123             tt_file_name_default = "description_%s.tmpl" % "default" 
    124              
    125             tt_file = os.path.join(self.env.path, "templates", tt_file_name) 
    126             tt_file_default = os.path.join(self.env.path, "templates", tt_file_name_default) 
     123#            tt_file_name = "description_%s.tmpl" % req.args.get('type') 
     124#            tt_file_name_default = "description_%s.tmpl" % "default" 
     125#             
     126#            tt_file = os.path.join(self.env.path, "templates", tt_file_name) 
     127#            tt_file_default = os.path.join(self.env.path, "templates", tt_file_name_default) 
    127128 
    128129            # Load 
     
    134135            # Save 
    135136            elif req.args.get('savetickettemplate'): 
    136                 tt_text = req.args.get('description').strip().replace('\r', '') 
     137                tt_text = req.args.get('description').replace('\r', '') 
    137138                tt_name = req.args.get('type') 
    138139 
    139140                self._saveTemplateText(tt_name, tt_text) 
    140141                req.hdf['tt_text'] = tt_text 
     142                 
     143            # Save 
     144            elif req.args.get('preview'): 
     145                tt_text = req.args.get('description').replace('\r', '') 
     146                tt_name = req.args.get('type') 
     147 
     148                description_preview = self._previewTemplateText(tt_name, tt_text, req) 
     149                req.hdf['tt_text'] = tt_text 
     150                req.hdf['description_preview'] = description_preview 
    141151 
    142152        return 'admin_tickettemplate.cs', None 
     153 
     154    def _previewTemplateText(self, tt_name, tt_text, req): 
     155        """ preview ticket template 
     156        """ 
     157        db = self.env.get_db_cnx()         
     158        description_preview = wiki_to_html(tt_text, self.env, req, db) 
     159        return description_preview 
     160     
    143161 
    144162    # ITemplateProvider 
     
    165183     
    166184    # private methods 
    167     def _getTTFilePath(self, tt_name): 
     185    def _getTTFilePath(self): 
    168186        """ get ticket template file path 
    169187        """ 
    170         tt_file_name = "description_%s.tmpl" % base64.encodestring(tt_name.encode("utf-8")) 
    171         tt_file = os.path.join(self.env.path, "templates", tt_file_name) 
    172         return tt_file 
    173  
    174     def _loadTemplateText(self, tt_name): 
    175         """ load ticket template text from file. 
    176         """ 
    177         tt_file         = self._getTTFilePath(tt_name) 
    178         tt_file_default = self._getTTFilePath(u"default") 
     188        return os.path.join(self.env.path, "templates", "description.tmpl") 
     189 
     190    def _loadTTDict(self): 
     191        """ load ticket template dict from file. 
     192        """ 
     193        tt_file = self._getTTFilePath() 
    179194 
    180195        try: 
    181             fp = open(tt_file,'r') 
    182             tt_text = fp.read() 
     196            fp = open(tt_file,'rb') 
     197            tt_stream = fp.read() 
    183198            fp.close() 
    184199        except: 
    185             try: 
    186                 fp = open(tt_file_default, 'r') 
    187                 tt_text = fp.read() 
    188                 fp.close() 
    189             except: 
    190                 tt_text = "" 
    191                  
    192         return tt_text 
    193  
     200            tt_stream = "" 
     201 
     202        try: 
     203            tt_dict = pickle.loads(tt_stream) 
     204        except: 
     205            tt_dict = {} 
     206 
     207        return tt_dict 
     208     
     209    def _loadTemplateText(self, tt_name): 
     210        """ get tempate text from tt_dict. 
     211            return tt_text if found in tt_dict 
     212                or default tt_text if exists 
     213                or empty string if default not exists. 
     214        """ 
     215        tt_dict = self._loadTTDict() 
     216        return tt_dict.get(tt_name, tt_dict.get("default", "")) 
     217         
    194218    def _saveTemplateText(self, tt_name, tt_text): 
    195219        """ save ticket template text to file. 
    196220        """ 
    197         tt_file = self._getTTFilePath(tt_name) 
    198  
     221        # dump tt_dict 
     222        tt_dict = self._loadTTDict() 
     223        tt_dict[tt_name] = tt_text 
     224        tt_stream = pickle.dumps(tt_dict) 
     225         
     226        tt_file = self._getTTFilePath() 
    199227        try: 
    200             fp = open(tt_file,'w') 
    201         except Exception, e
     228            fp = open(tt_file,'wb') 
     229        except
    202230            raise TracError("Can't write ticket template file %s" % tt_file) 
    203231        else: 
    204             fp.write(tt_text.encode("utf-8")
     232            fp.write(tt_stream
    205233            fp.close() 
    206234 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/En/tickettemplate/version.txt

    r3523 r3524  
    1 0.3 
     10.4 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/Zh/tickettemplate/changelog.txt

    r3138 r3524  
     1TicketTemplate 0.4 (Mar 25, 2008) 
     2 
     3 * add preview to admin page 
     4 * use one persistence file to store all template texts 
     5 * fixed bug: leading space in template text is not stripped now 
     6 * add some default template text for trac's default install:  
     7  * defect 
     8  * enhancement 
     9  * task 
     10  * default 
     11 
    112TicketTemplate 0.3 (Jan 2, 2008) 
    213 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/Zh/tickettemplate/readme.txt

    r3273 r3524  
    88 
    99= Install = 
     10 
     11 '''IMPORTANT''': Please BACKUP you ticket templates if you are upgrading this plugin. 
     12 
    1013 You can install this software as normal Trac plugin. 
    1114 
     
    3033}}} 
    3134 
     35 6. If you are installing this plugin first time, you can copy description.tmpl to your/trac/environment/templates to utilize some default ticket templates. 
    3236 
    3337= Prerequisite = 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/Zh/tickettemplate/templates/admin_tickettemplate.cs

    r3138 r3524  
    1010 
    1111 
    12 <form id="savetickettemplate" method="post"> 
     12<form id="savetickettemplate" action="tickettemplate" method="post"> 
    1313 
    1414  <div class="field"><label for="type">种类:</label> <?cs 
     
    2222  <div class="field"> 
    2323    <label for="description">完敎描述 (<a tabindex="42" href="<?cs var:$trac.href.wiki ?>/WikiFormatting">Wiki栌匏</a> 垮助):</label><br /> 
    24     <textarea id="description" name="description" class="wikitext" rows="20" style="width:63%" name="tt_text"><?cs var:tt_text ?></textarea> 
     24    <textarea id="description" name="description" class="wikitext" rows="20" cols="66" name="tt_text"><?cs var:tt_text ?></textarea> 
     25  <?cs 
     26  if:description_preview ?> 
     27   <fieldset id="preview"> 
     28    <legend>描述预览</legend> 
     29    <?cs var:description_preview ?> 
     30   </fieldset><?cs 
     31  /if ?> 
    2532  </div> 
    26    
    27 </form> 
     33 
    2834 
    2935 <script type="text/javascript" src="<?cs 
    3036   var:htdocs_location ?>js/wikitoolbar.js"></script> 
    3137 
     38 <div class="buttons"> 
     39  <input type="submit" name="preview" value="预览" accesskey="r" />&nbsp; 
     40  <input type="submit" value="发送" /> 
     41 </div> 
     42   
     43</form> 
     44 
     45 
     46 
    3247</html> 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/Zh/tickettemplate/ttadmin.py

    r3523 r3524  
    1313from trac.web.chrome import INavigationContributor 
    1414from trac.web.chrome import * 
     15from trac.wiki import wiki_to_html, wiki_to_oneliner 
    1516 
    1617from trac.ticket import Milestone, Ticket, TicketSystem, ITicketManipulator 
     
    2324 
    2425import os 
    25 import base64 
     26import pickle 
    2627 
    2728__all__ = ['TicketTemplateModule'] 
     
    121122 
    122123        if req.method == 'POST': 
    123             tt_file_name = "description_%s.tmpl" % req.args.get('type') 
    124             tt_file_name_default = "description_%s.tmpl" % "default" 
    125              
    126             tt_file = os.path.join(self.env.path, "templates", tt_file_name) 
    127             tt_file_default = os.path.join(self.env.path, "templates", tt_file_name_default) 
     124#            tt_file_name = "description_%s.tmpl" % req.args.get('type') 
     125#            tt_file_name_default = "description_%s.tmpl" % "default" 
     126#             
     127#            tt_file = os.path.join(self.env.path, "templates", tt_file_name) 
     128#            tt_file_default = os.path.join(self.env.path, "templates", tt_file_name_default) 
    128129 
    129130            # Load 
     
    135136            # Save 
    136137            elif req.args.get('savetickettemplate'): 
    137                 tt_text = req.args.get('description').strip().replace('\r', '') 
     138                tt_text = req.args.get('description').replace('\r', '') 
    138139                tt_name = req.args.get('type') 
    139140 
    140141                self._saveTemplateText(tt_name, tt_text) 
    141142                req.hdf['tt_text'] = tt_text 
     143                 
     144            # Save 
     145            elif req.args.get('preview'): 
     146                tt_text = req.args.get('description').replace('\r', '') 
     147                tt_name = req.args.get('type') 
     148 
     149                description_preview = self._previewTemplateText(tt_name, tt_text, req) 
     150                req.hdf['tt_text'] = tt_text 
     151                req.hdf['description_preview'] = description_preview 
    142152 
    143153        return 'admin_tickettemplate.cs', None 
     154 
     155    def _previewTemplateText(self, tt_name, tt_text, req): 
     156        """ preview ticket template 
     157        """ 
     158        db = self.env.get_db_cnx()         
     159        description_preview = wiki_to_html(tt_text, self.env, req, db) 
     160        return description_preview 
     161     
    144162 
    145163    # ITemplateProvider 
     
    166184     
    167185    # private methods 
    168     def _getTTFilePath(self, tt_name): 
     186    def _getTTFilePath(self): 
    169187        """ get ticket template file path 
    170188        """ 
    171         tt_file_name = "description_%s.tmpl" % base64.encodestring(tt_name.encode("utf-8")) 
    172         tt_file = os.path.join(self.env.path, "templates", tt_file_name) 
    173         return tt_file 
    174  
    175     def _loadTemplateText(self, tt_name): 
    176         """ load ticket template text from file. 
    177         """ 
    178         tt_file         = self._getTTFilePath(tt_name) 
    179         tt_file_default = self._getTTFilePath(u"default") 
     189        return os.path.join(self.env.path, "templates", "description.tmpl") 
     190 
     191    def _loadTTDict(self): 
     192        """ load ticket template dict from file. 
     193        """ 
     194        tt_file = self._getTTFilePath() 
    180195 
    181196        try: 
    182             fp = open(tt_file,'r') 
    183             tt_text = fp.read() 
     197            fp = open(tt_file,'rb') 
     198            tt_stream = fp.read() 
    184199            fp.close() 
    185200        except: 
    186             try: 
    187                 fp = open(tt_file_default, 'r') 
    188                 tt_text = fp.read() 
    189                 fp.close() 
    190             except: 
    191                 tt_text = "" 
    192                  
    193         return tt_text 
    194  
     201            tt_stream = "" 
     202 
     203        try: 
     204            tt_dict = pickle.loads(tt_stream) 
     205        except: 
     206            tt_dict = {} 
     207 
     208        return tt_dict 
     209     
     210    def _loadTemplateText(self, tt_name): 
     211        """ get tempate text from tt_dict. 
     212            return tt_text if found in tt_dict 
     213                or default tt_text if exists 
     214                or empty string if default not exists. 
     215        """ 
     216        tt_dict = self._loadTTDict() 
     217        return tt_dict.get(tt_name, tt_dict.get("default", "")) 
     218         
    195219    def _saveTemplateText(self, tt_name, tt_text): 
    196220        """ save ticket template text to file. 
    197221        """ 
    198         tt_file = self._getTTFilePath(tt_name) 
    199  
     222        # dump tt_dict 
     223        tt_dict = self._loadTTDict() 
     224        tt_dict[tt_name] = tt_text 
     225        tt_stream = pickle.dumps(tt_dict) 
     226         
     227        tt_file = self._getTTFilePath() 
    200228        try: 
    201             fp = open(tt_file,'w') 
    202         except Exception, e
     229            fp = open(tt_file,'wb') 
     230        except
    203231            raise TracError("Can't write ticket template file %s" % tt_file) 
    204232        else: 
    205             fp.write(tt_text.encode("utf-8")
     233            fp.write(tt_stream
    206234            fp.close() 
    207235 
  • zoomquiettranslation/plugins/KSTracTicketTemplate/0.10/Zh/tickettemplate/version.txt

    r3523 r3524  
    1 0.3 
     10.4