src/build/html/utilities.html
changeset 11 ba0b83b57c0c
parent 10 1d12ff3f036a
child 12 f1f1e99a6572
equal deleted inserted replaced
10:1d12ff3f036a 11:ba0b83b57c0c
     1 
       
     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       
     3   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
     4 
       
     5 <html xmlns="http://www.w3.org/1999/xhtml">
       
     6   <head>
       
     7     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
     8     <title>Custom PyAMS utilities &#8212; PyAMS User Guide 0.1.0 documentation</title>
       
     9     <link rel="stylesheet" href="_static/pyramid.css" type="text/css" />
       
    10     <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
       
    11     <script type="text/javascript">
       
    12       var DOCUMENTATION_OPTIONS = {
       
    13         URL_ROOT:    './',
       
    14         VERSION:     '0.1.0',
       
    15         COLLAPSE_INDEX: false,
       
    16         FILE_SUFFIX: '.html',
       
    17         HAS_SOURCE:  true,
       
    18         SOURCELINK_SUFFIX: '.txt'
       
    19       };
       
    20     </script>
       
    21     <script type="text/javascript" src="_static/jquery.js"></script>
       
    22     <script type="text/javascript" src="_static/underscore.js"></script>
       
    23     <script type="text/javascript" src="_static/doctools.js"></script>
       
    24     <link rel="index" title="Index" href="genindex.html" />
       
    25     <link rel="search" title="Search" href="search.html" />
       
    26     <link rel="prev" title="Custom TALES extensions" href="tales.html" />
       
    27 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Neuton&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
       
    28 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nobile:regular,italic,bold,bolditalic&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
       
    29 <!--[if lte IE 6]>
       
    30 <link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
       
    31 <![endif]-->
       
    32 
       
    33   </head>
       
    34   <body>
       
    35 
       
    36     <div class="related" role="navigation" aria-label="related navigation">
       
    37       <h3>Navigation</h3>
       
    38       <ul>
       
    39         <li class="right" style="margin-right: 10px">
       
    40           <a href="genindex.html" title="General Index"
       
    41              accesskey="I">index</a></li>
       
    42         <li class="right" >
       
    43           <a href="tales.html" title="Custom TALES extensions"
       
    44              accesskey="P">previous</a> |</li>
       
    45         <li class="nav-item nav-item-0"><a href="index.html">PyAMS User Guide 0.1.0 documentation</a> &#187;</li> 
       
    46       </ul>
       
    47     </div>  
       
    48 
       
    49     <div class="document">
       
    50       <div class="documentwrapper">
       
    51         <div class="bodywrapper">
       
    52           <div class="body" role="main">
       
    53             
       
    54   <div class="section" id="custom-pyams-utilities">
       
    55 <span id="utilities"></span><h1>Custom PyAMS utilities<a class="headerlink" href="#custom-pyams-utilities" title="Permalink to this headline">¶</a></h1>
       
    56 <p>PyAMS_utils provides a small set of utilities. You can create some of them as global utilities registered in
       
    57 the global components registry; other ones can be created manually by a site administrator and
       
    58 are then registered automatically.</p>
       
    59 <div class="section" id="server-timezone">
       
    60 <h2>Server timezone<a class="headerlink" href="#server-timezone" title="Permalink to this headline">¶</a></h2>
       
    61 <p>To manage timezones correctly, and display datetimes based on current server timezone, all datetimes should
       
    62 be defined and stored in UTC.</p>
       
    63 <p>PyAMS_utils provides a <code class="xref py py-class docutils literal"><span class="pre">ServerTimezoneUtility</span></code> which
       
    64 allows you to assign a default timezone to your server.</p>
       
    65 <p>To display a datetime with correct timezone, you can use the <code class="xref py py-func docutils literal"><span class="pre">tztime</span></code> function,
       
    66 which assign server timezone to the given parameter:</p>
       
    67 <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
       
    68 <span class="kn">from</span> <span class="nn">pyams_utils.timezone</span> <span class="kn">import</span> <span class="n">tztime</span>
       
    69 
       
    70 <span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span>
       
    71 <span class="n">my_date</span> <span class="o">=</span> <span class="n">tztime</span><span class="p">(</span><span class="n">now</span><span class="p">)</span>  <span class="c1"># converts *now* to server timezone</span>
       
    72 </pre></div>
       
    73 </div>
       
    74 <p>We could imagine that datetimes could be displayed with current user timezone. But it’s quite impossible to know
       
    75 the user timazone from a server request. The only options are:</p>
       
    76 <ul class="simple">
       
    77 <li>you ask an authenticated user to update a timezone setting in his profile</li>
       
    78 <li>you can include Javascript libraries which will try to detect browser timezone from their computer configuration, and
       
    79 do an AJAX request to update data in their session.</li>
       
    80 </ul>
       
    81 <p>That should require an update of <code class="xref py py-func docutils literal"><span class="pre">tzinfo()</span></code> adapter to get timezone info from session, request or user profile.</p>
       
    82 </div>
       
    83 <div class="section" id="zeo-connection">
       
    84 <h2>ZEO connection<a class="headerlink" href="#zeo-connection" title="Permalink to this headline">¶</a></h2>
       
    85 <p>Several PyAMS utilities (like the tasks scheduler or the medias converter) are working with dedicated processes,
       
    86 are connected to main PyAMS process through ØMQ, and use ZEO connections for their PyAMS database access.</p>
       
    87 <p>Clients of these processes have to send settings of the ZEO connections that they should use.</p>
       
    88 <p>The ZEOConnection utility can be created by the site manager through the web management interface (ZMI) from the
       
    89 <em>Control panel</em>:</p>
       
    90 <img alt="_images/zeo-add-menu.png" src="_images/zeo-add-menu.png" />
       
    91 <p>ZEO connection creation form allows you to define all settings of a ZEO connection:</p>
       
    92 <img alt="_images/zeo-add-form.png" src="_images/zeo-add-form.png" />
       
    93 </div>
       
    94 </div>
       
    95 
       
    96 
       
    97           </div>
       
    98         </div>
       
    99       </div>
       
   100       <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
       
   101         <div class="sphinxsidebarwrapper">
       
   102   <h3><a href="index.html">Table Of Contents</a></h3>
       
   103   <ul>
       
   104 <li><a class="reference internal" href="#">Custom PyAMS utilities</a><ul>
       
   105 <li><a class="reference internal" href="#server-timezone">Server timezone</a></li>
       
   106 <li><a class="reference internal" href="#zeo-connection">ZEO connection</a></li>
       
   107 </ul>
       
   108 </li>
       
   109 </ul>
       
   110 
       
   111   <h4>Previous topic</h4>
       
   112   <p class="topless"><a href="tales.html"
       
   113                         title="previous chapter">Custom TALES extensions</a></p>
       
   114 <div id="searchbox" style="display: none" role="search">
       
   115   <h3>Quick search</h3>
       
   116     <form class="search" action="search.html" method="get">
       
   117       <div><input type="text" name="q" /></div>
       
   118       <div><input type="submit" value="Go" /></div>
       
   119       <input type="hidden" name="check_keywords" value="yes" />
       
   120       <input type="hidden" name="area" value="default" />
       
   121     </form>
       
   122 </div>
       
   123 <script type="text/javascript">$('#searchbox').show(0);</script>
       
   124         </div>
       
   125       </div>
       
   126       <div class="clearer"></div>
       
   127     </div>
       
   128     <div class="related" role="navigation" aria-label="related navigation">
       
   129       <h3>Navigation</h3>
       
   130       <ul>
       
   131         <li class="right" style="margin-right: 10px">
       
   132           <a href="genindex.html" title="General Index"
       
   133              >index</a></li>
       
   134         <li class="right" >
       
   135           <a href="tales.html" title="Custom TALES extensions"
       
   136              >previous</a> |</li>
       
   137         <li class="nav-item nav-item-0"><a href="index.html">PyAMS User Guide 0.1.0 documentation</a> &#187;</li> 
       
   138       </ul>
       
   139     </div>
       
   140     <div class="footer" role="contentinfo">
       
   141         &#169; Copyright 2017, Thierry Florac.
       
   142       Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.5.
       
   143     </div>
       
   144   </body>
       
   145 </html>