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