Skip to content

Commit

Permalink
Merge pull request #537 from leancloud/release-299
Browse files Browse the repository at this point in the history
docs: prepare to release 2.9.9
  • Loading branch information
weakish authored Dec 14, 2021
2 parents 056e079 + a2061ea commit 1a7ad7f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
11 changes: 11 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [2.9.9] - 2021-12-14

### Added

- LCFile exposes the `key` attribute for non-external files.

### Fixed

- created_at and updated_at were missing on LCFile.
- updated_at was missing on new created LCObject.

## [2.9.8] - 2021-12-10

### Fixed
Expand Down
20 changes: 20 additions & 0 deletions docs/_modules/leancloud/file_.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ <h1>leancloud.file_ 源代码</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="n">name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_url</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_successful_url</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_acl</span> <span class="o">=</span> <span class="kc">None</span>
Expand Down Expand Up @@ -293,9 +295,18 @@ <h1>leancloud.file_ 源代码</h1><div class="highlight"><pre>
<span class="p">}</span>
<span class="n">response</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;/files&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_name</span><span class="p">),</span> <span class="n">data</span><span class="p">)</span>
<span class="n">content</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">content</span><span class="p">[</span><span class="s2">&quot;objectId&quot;</span><span class="p">]</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_successful_url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_url</span>

<span class="n">_created_at</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode_date_string</span><span class="p">(</span><span class="n">content</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;createdAt&quot;</span><span class="p">))</span>
<span class="n">_updated_at</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode_updated_at</span><span class="p">(</span><span class="n">content</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;updatedAt&quot;</span><span class="p">),</span> <span class="n">_created_at</span><span class="p">)</span>
<span class="k">if</span> <span class="n">_created_at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="o">=</span> <span class="n">_created_at</span>
<span class="k">if</span> <span class="n">_updated_at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span> <span class="o">=</span> <span class="n">_updated_at</span>

<span class="k">def</span> <span class="nf">_save_to_qcloud</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">upload_url</span><span class="p">):</span>
<span class="n">headers</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;Authorization&quot;</span><span class="p">:</span> <span class="n">token</span><span class="p">,</span>
Expand Down Expand Up @@ -356,10 +367,19 @@ <h1>leancloud.file_ 源代码</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="s2">&quot;url&quot;</span> <span class="ow">in</span> <span class="n">server_data</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_url</span> <span class="o">=</span> <span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;url&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_successful_url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_url</span>
<span class="k">if</span> <span class="s2">&quot;key&quot;</span> <span class="ow">in</span> <span class="n">server_data</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;key&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="s2">&quot;mime_type&quot;</span> <span class="ow">in</span> <span class="n">server_data</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_mime_type</span> <span class="o">=</span> <span class="n">server_data</span><span class="p">[</span><span class="s2">&quot;mime_type&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;metaData&quot;</span> <span class="ow">in</span> <span class="n">server_data</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_metadata</span> <span class="o">=</span> <span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;metaData&quot;</span><span class="p">)</span>

<span class="n">_created_at</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode_date_string</span><span class="p">(</span><span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;createdAt&quot;</span><span class="p">))</span>
<span class="n">_updated_at</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode_updated_at</span><span class="p">(</span><span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;updatedAt&quot;</span><span class="p">),</span> <span class="n">_created_at</span><span class="p">)</span>
<span class="k">if</span> <span class="n">_created_at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="o">=</span> <span class="n">_created_at</span>
<span class="k">if</span> <span class="n">_updated_at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span> <span class="o">=</span> <span class="n">_updated_at</span>

<span class="k">def</span> <span class="nf">_get_file_token</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
Expand Down
48 changes: 29 additions & 19 deletions docs/_modules/leancloud/object_.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,25 +401,18 @@ <h1>leancloud.object_ 源代码</h1><div class="highlight"><pre>
<span class="p">}</span>

<span class="k">def</span> <span class="nf">_merge_metadata</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">server_data</span><span class="p">):</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;objectId&quot;</span><span class="p">,</span> <span class="s2">&quot;createdAt&quot;</span><span class="p">,</span> <span class="s2">&quot;updatedAt&quot;</span><span class="p">):</span>
<span class="k">if</span> <span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">continue</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s2">&quot;objectId&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">server_data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">server_data</span><span class="p">[</span><span class="n">key</span><span class="p">],</span> <span class="n">six</span><span class="o">.</span><span class="n">string_types</span><span class="p">):</span>
<span class="n">dt</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;__type&quot;</span><span class="p">:</span> <span class="s2">&quot;Date&quot;</span><span class="p">,</span> <span class="s2">&quot;iso&quot;</span><span class="p">:</span> <span class="n">server_data</span><span class="p">[</span><span class="n">key</span><span class="p">]})</span>
<span class="k">elif</span> <span class="n">server_data</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">&quot;__type&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;Date&quot;</span><span class="p">:</span>
<span class="n">dt</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">server_data</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Invalid date type&quot;</span><span class="p">)</span>
<span class="n">server_data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">dt</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s2">&quot;createdAt&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="o">=</span> <span class="n">dt</span>
<span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s2">&quot;updatedAt&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span> <span class="o">=</span> <span class="n">dt</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">TypeError</span>
<span class="n">object_id</span> <span class="o">=</span> <span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;objectId&quot;</span><span class="p">)</span>
<span class="n">_created_at</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode_date_string</span><span class="p">(</span><span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;createdAt&quot;</span><span class="p">))</span>
<span class="n">_updated_at</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">decode_updated_at</span><span class="p">(</span><span class="n">server_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;updatedAt&quot;</span><span class="p">),</span> <span class="n">_created_at</span><span class="p">)</span>

<span class="k">if</span> <span class="n">object_id</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">object_id</span>
<span class="k">if</span> <span class="n">_created_at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="o">=</span> <span class="n">_created_at</span>
<span class="k">if</span> <span class="n">_updated_at</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span> <span class="o">=</span> <span class="n">_updated_at</span>



<div class="viewcode-block" id="Object.validate"><a class="viewcode-back" href="../../index.html#leancloud.Object.validate">[文档]</a> <span class="k">def</span> <span class="nf">validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attrs</span><span class="p">):</span>
<span class="k">if</span> <span class="s2">&quot;ACL&quot;</span> <span class="ow">in</span> <span class="n">attrs</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">attrs</span><span class="p">[</span><span class="s2">&quot;ACL&quot;</span><span class="p">],</span> <span class="n">leancloud</span><span class="o">.</span><span class="n">ACL</span><span class="p">):</span>
Expand All @@ -437,6 +430,23 @@ <h1>leancloud.object_ 源代码</h1><div class="highlight"><pre>
<span class="c1"># for backward compatibility</span>
<span class="k">if</span> <span class="p">(</span><span class="n">deafult</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">default</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">):</span>
<span class="n">default</span> <span class="o">=</span> <span class="n">deafult</span>

<span class="c1"># createdAt is stored as string in the cloud but used as datetime object on the client side.</span>
<span class="c1"># We need to make sure that `.created_at` and `.get(&quot;createdAt&quot;)` return the same value.</span>
<span class="c1"># Otherwise users will get confused.</span>
<span class="k">if</span> <span class="n">attr</span> <span class="o">==</span> <span class="s2">&quot;createdAt&quot;</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">created_at</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">created_at</span>

<span class="c1"># Similar to createdAt.</span>
<span class="k">if</span> <span class="n">attr</span> <span class="o">==</span> <span class="s2">&quot;updatedAt&quot;</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">updated_at</span>

<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_attributes</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">attr</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span></div>

<div class="viewcode-block" id="Object.relation"><a class="viewcode-back" href="../../index.html#leancloud.Object.relation">[文档]</a> <span class="k">def</span> <span class="nf">relation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='leancloud',
version='2.9.8',
version='2.9.9',
description='LeanCloud Python SDK',
url='https://leancloud.cn/',
author='asaka',
Expand Down

0 comments on commit 1a7ad7f

Please sign in to comment.