add {mm} and {dd} media format support, resolves #12

This commit is contained in:
meeb 2020-12-18 21:02:06 +11:00
parent cda021cbbf
commit 8f4b09f346
5 changed files with 24 additions and 4 deletions

View File

@ -370,6 +370,8 @@ class Source(models.Model):
'yyyymmdd': timezone.now().strftime('%Y%m%d'), 'yyyymmdd': timezone.now().strftime('%Y%m%d'),
'yyyy_mm_dd': timezone.now().strftime('%Y-%m-%d'), 'yyyy_mm_dd': timezone.now().strftime('%Y-%m-%d'),
'yyyy': timezone.now().strftime('%Y'), 'yyyy': timezone.now().strftime('%Y'),
'mm': timezone.now().strftime('%m'),
'dd': timezone.now().strftime('%d'),
'source': self.slugname, 'source': self.slugname,
'source_full': self.name, 'source_full': self.name,
'title': 'some-media-title-name', 'title': 'some-media-title-name',
@ -805,6 +807,8 @@ class Media(models.Model):
'yyyymmdd': dateobj.strftime('%Y%m%d'), 'yyyymmdd': dateobj.strftime('%Y%m%d'),
'yyyy_mm_dd': dateobj.strftime('%Y-%m-%d'), 'yyyy_mm_dd': dateobj.strftime('%Y-%m-%d'),
'yyyy': dateobj.strftime('%Y'), 'yyyy': dateobj.strftime('%Y'),
'mm': dateobj.strftime('%m'),
'dd': dateobj.strftime('%d'),
'source': self.source.slugname, 'source': self.source.slugname,
'source_full': self.source.name, 'source_full': self.source.name,
'title': self.slugtitle, 'title': self.slugtitle,

View File

@ -11,18 +11,28 @@
<tr> <tr>
<td>{yyyymmdd}</td> <td>{yyyymmdd}</td>
<td>Media publish date in YYYYMMDD</td> <td>Media publish date in YYYYMMDD</td>
<td>20210101</td> <td>20210131</td>
</tr> </tr>
<tr> <tr>
<td>{yyyy_mm_dd}</td> <td>{yyyy_mm_dd}</td>
<td>Media publish date in YYYY-MM-DD</td> <td>Media publish date in YYYY-MM-DD</td>
<td>2021-01-01</td> <td>2021-01-31</td>
</tr> </tr>
<tr> <tr>
<td>{yyyy}</td> <td>{yyyy}</td>
<td>Media publish year in YYYY</td> <td>Media publish year in YYYY</td>
<td>2021</td> <td>2021</td>
</tr> </tr>
<tr>
<td>{mm}</td>
<td>Media publish year in MM</td>
<td>01</td>
</tr>
<tr>
<td>{dd}</td>
<td>Media publish year in DD</td>
<td>31</td>
</tr>
<tr> <tr>
<td>{source}</td> <td>{source}</td>
<td>Lower case source name, max 80 chars</td> <td>Lower case source name, max 80 chars</td>

View File

@ -25,7 +25,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
{% include 'mediaformatvars.html' %} {% include 'sync/_mediaformatvars.html' %}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -27,7 +27,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
{% include 'mediaformatvars.html' %} {% include 'sync/_mediaformatvars.html' %}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -507,6 +507,12 @@ class FilepathTestCase(TestCase):
self.source.media_format = 'test-{yyyy}' self.source.media_format = 'test-{yyyy}'
self.assertEqual(self.source.get_example_media_format(), self.assertEqual(self.source.get_example_media_format(),
'test-' + timezone.now().strftime('%Y')) 'test-' + timezone.now().strftime('%Y'))
self.source.media_format = 'test-{mm}'
self.assertEqual(self.source.get_example_media_format(),
'test-' + timezone.now().strftime('%m'))
self.source.media_format = 'test-{dd}'
self.assertEqual(self.source.get_example_media_format(),
'test-' + timezone.now().strftime('%d'))
self.source.media_format = 'test-{source}' self.source.media_format = 'test-{source}'
self.assertEqual(self.source.get_example_media_format(), self.assertEqual(self.source.get_example_media_format(),
'test-' + self.source.slugname) 'test-' + self.source.slugname)