<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andy Byers on Medium]]></title>
        <description><![CDATA[Stories by Andy Byers on Medium]]></description>
        <link>https://medium.com/@ajrbyers?source=rss-d482fb5144d3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*c9Lm9vG0bzJcQ4Ku.jpeg</url>
            <title>Stories by Andy Byers on Medium</title>
            <link>https://medium.com/@ajrbyers?source=rss-d482fb5144d3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:01:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ajrbyers/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Django Custom Managers]]></title>
            <link>https://ajrbyers.medium.com/django-custom-managers-b54bce1193ab?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b54bce1193ab</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Wed, 28 Oct 2020 13:40:10 GMT</pubDate>
            <atom:updated>2020-10-28T13:40:10.600Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1X0-98EiQNkwBJj2vnTTqQ.jpeg" /></figure><p>Photo by <a href="https://unsplash.com/@cdr6934?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Chris Ried</a> on <a href="https://unsplash.com/s/photos/code?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p>We at the Open Library of Humanities and Birkbeck CTP have been working on a Repository system initially built to provide a space for Preprints. We came across an issue where once live data had been imported into the system the main dashboard began to slow down. This wasn’t unexpected — when you add a tonne of data sometimes things get a bit slower — but this was excruciating.</p><p>A little investigation with the Django Debug Toolbar showed that we were repeating a bunch of queries over and over again. This is quite easy to tidy up — we added some select_related() and prefetch_related() calls to limit the number of additional queries being made in the templates but due to the nature of one of our models the page remained relatively slow to load. The model looks like this:</p><pre>class PreprintAuthor(models.Model):<br>    preprint = models.ForeignKey(&#39;Preprint&#39;)<br>    author = models.ForeignKey(&#39;Author&#39;)<br>    order = models.PositiveIntegerField(default=0)</pre><p>When looping through a bunch of preprints on the template we wanted to display the name of the first preprint author. This can be done using the following in the template:</p><pre>{% for preprint in preprints %}<br>{{ preprint.preprintauthor_set.0.author.full_name }}<br>{% endfor %}</pre><p>We could add a property to get the first author for us but this wouldn’t stop the additional query from being executed. And we use select_related on preprintauthor_set already. To stop the template from executing additonal queries to fech the Author FK we can create a custom manager that will ensure that when a PreprintAuthor is fetched it will get the Author object as well.</p><pre>class PreprintAuthorManager(models.Manager):<br>    def get_queryset(self):<br>        return super().get_queryset().select_related(&#39;author&#39;)</pre><p>With this we pass the heavy lifting over to the SQL backend which is much faster than Python at dealing with this. Now all we need to do is add this to our PreprintAuthor model.</p><pre>class PreprintAuthor(models.Model):<br>    preprint = models.ForeignKey(&#39;Preprint&#39;)<br>    author = models.ForeignKey(&#39;Author&#39;)<br>    order = models.PositiveIntegerField(default=0)<br>    objects = PreprintAuthorManager()</pre><p>We reduced the number of queries running on the Dashbord to 17 (15 on a second load due to some cache hits!)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b54bce1193ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OLH’s Recent Downtime]]></title>
            <link>https://ajrbyers.medium.com/olhs-recent-downtime-2368d15bbd01?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2368d15bbd01</guid>
            <category><![CDATA[web-hosting]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Tue, 03 Apr 2018 08:56:15 GMT</pubDate>
            <atom:updated>2018-04-03T08:56:29.174Z</atom:updated>
            <content:encoded><![CDATA[<p>The Open Library of Humanities main site, and Orbit and IJWWE journal sites are all on Janeway and are hosted on Reclaim Hosting’s great <a href="https://reclaimhosting.com/shared-hosting/">Shared Hosting</a> service. Reclaim leverage <a href="https://www.digitalocean.com/">Digital Ocean</a>’s VPS and Block Storage services to provide this service, so when DO’s Frankfurt data center <a href="http://status.digitalocean.com/incidents/8sk3mbgp6jgl">fell to pieces</a> on the 1st of April (Apr 01, 2018–07:31 UTC) we were among the unfortunate victims.</p><p>Our sites were offline from 0731 on 01/04 to 1937 02/04. This length of downtime, we feel, isn’t okay so we are setting out to ensure it doesn’t happen again. We plan to:</p><ol><li>Setup a second Reclaim account in a different data center/region (London)</li><li>Register a VPS and setup a Haproxy in TCP mode to forward traffic to the live server (Frankfurt)</li><li>Setup MySQL Replication between Frankfurt and London</li><li>Sync the home folders of Frankfurt and London, bidirectionally, using unison</li><li>Sync SSL certs from Frankfurt to London</li><li>Implement simple switch to change the backend on the VPS from Frankfurt to London</li><li>Add heartbeat and automatic failover when Frankfurt fails</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2368d15bbd01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Migrations and UUID Fields]]></title>
            <link>https://ajrbyers.medium.com/django-migrations-and-uuid-fields-4e3b27701e4a?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e3b27701e4a</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[migration]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Tue, 27 Feb 2018 11:51:15 GMT</pubDate>
            <atom:updated>2018-02-27T11:51:15.004Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Recently I wanted to add a UUID field to an existing model called Institution, this model represents the Institutions that support the Open Library Humanities and the UUID field would represent a referral code. I added the following line to models.py and ran makemigrations.</p><pre>referral_code = models.UUIDField(default=uuid.uuid4)</pre><p>Unfortunately, this works perfectly for new instances of Institution, it will generate the same UUID for all of the existing objects. To get around this we need to alter the migration that has been generated.</p><pre># -*- coding: utf-8 -*-<br># Generated by Django 1.11.5 on 2018-02-26 19:29<br>from __future__ import unicode_literals<br><br>from django.db import migrations, models<br>import uuid<br><br><br>def create_uuid(apps, schema_editor):<br>    Institution = apps.get_model(&#39;consortial_billing&#39;, &#39;Institution&#39;)<br>    for inst in Institution.objects.all():<br>        inst.referral_code = uuid.uuid4()<br>        inst.save()<br><br><br>class Migration(migrations.Migration):<br><br>    dependencies = [<br>        (&#39;consortial_billing&#39;, &#39;0031_supportlevel_description&#39;),<br>    ]<br><br>    operations = [<br>        migrations.AddField(<br>            model_name=&#39;institution&#39;,<br>            name=&#39;referral_code&#39;,<br>            field=models.UUIDField(blank=True, null=True),<br>        ),<br>        migrations.RunPython(create_uuid),<br>        migrations.AlterField(<br>            model_name=&#39;institution&#39;,<br>            name=&#39;referral_code&#39;,<br>            field=models.UUIDField(default=uuid.uuid4, unique=True)<br>        )<br>    ]</pre><p>I’ve edited the original AddField statement so it makes a blank=True, null=True version of our field, then I’ve added a RunPython command that gets all off the existing Institution objects and assigns them a uuid4 before finally setting a default and making it unique.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e3b27701e4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Mime types in Django]]></title>
            <link>https://ajrbyers.medium.com/file-mime-types-in-django-ee9531f3035b?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee9531f3035b</guid>
            <category><![CDATA[mime]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Thu, 23 Nov 2017 12:08:08 GMT</pubDate>
            <atom:updated>2017-11-23T12:08:32.179Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Allowing people to upload files to your server can be fraught with peril, we don’t want people to upload malicious files or binaries. In some cases we want to limit uploads to very specific file types, PDF or DOCX for example.</p><p>Python has a mimetype package that can be used to check the mime of a file lets say we upload a new jpeg file:</p><pre>import mimetypes</pre><pre>file_mime = mimetypes.guess_type(&#39;a_file.jpg&#39;)</pre><pre>&gt;&gt; (&#39;image/jpeg&#39;, None)</pre><p>This is great! Python has guessed that the file is a JPEG. But what if we upload a file that is actually a pdf:</p><pre>import mimetypes</pre><pre>file_mime = mimetypes.guess_type(&#39;sneaky_pdf_file.jpg&#39;)</pre><pre>&gt;&gt; (&#39;image/jpeg&#39;, None)</pre><p>Yup. Mimetypes only uses the filename to guess its type, which okay, but not good enough. <a href="https://github.com/ahupp/python-magic">Python-Magic</a> to the rescue. Python magic is a wrapped for libmagic which you may need to install, python-magic can be installed with PIP:</p><pre>pip3 install python-magic</pre><p>And we can now check a file’s mimetype in various ways:</p><pre><em>def </em>file_path_mime(<em>file_path</em>):<br>    mime = magic.from_file(<em>file_path</em>, mime=<em>True</em>)<br>    <em>return </em>mime<br><br><br><em>def </em>check_in_memory_mime(<em>in_memory_file</em>):<br>    mime = magic.from_buffer(<em>in_memory_file</em>.read(), mime=<em>True</em>)<br>    <em>return </em>mime</pre><pre>file_path_mime(&#39;/path/to/sneaky_pdf_file.jpg&#39;)</pre><pre>&gt;&gt; &#39;application/pdf&#39;</pre><pre>file_path_mime(&#39;path/to/a_file.jpg&#39;):</pre><pre>&gt;&gt; &#39;image/jpg&#39;</pre><p>The check_in_memory_mime function works for Django file uploads pulled directly from request.FILES on POST.</p><p><em>This post was inspired by </em><a href="https://martineve.com/"><em>Martin Eve</em></a><em> who uploaded some arbitrary files to </em><a href="https://janeway.systems/"><em>Janeway</em></a><em> during testing of our new Preprints module</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee9531f3035b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Janeway Events]]></title>
            <link>https://ajrbyers.medium.com/on-janeway-events-273b7251e749?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/273b7251e749</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[events-framework]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[janeway]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Thu, 05 Oct 2017 10:59:40 GMT</pubDate>
            <atom:updated>2017-10-05T10:59:40.406Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Janeway (an open source publishing platform written in Python and using the Django framework) uses an event system that allows apps and plugins to register to be called when an event is fired. An example of this would be when a new submission is made.</p><pre>event_logic.Events.ON_ARTICLE_SUBMITTED</pre><p>This event is called whenever a new article is submitted, any app or plugin can register to have a function called when this event is triggered by the following method:</p><pre><em>from </em>events <em>import </em>logic <em>as </em>event_logic</pre><pre>event_logic.Events.register_for_event(event_logic.Events.ON_ARTICLE_SUBMITTED, plugins.my_submission_plugin.events.a_function)</pre><p>The above is obviously an example, but you get the picture. By default an Event passes a set of keyword arguments for your function to use and these are documented inside events.logic.Events</p><p>Janeway uses the Event framework to handle raising of emails and entering Logs during its workflow process.</p><p><em>All of the credit (and blame if you hate it) for the Events framework goes to </em><a href="https://twitter.com/martin_eve"><em>Martin P Eve</em></a><em>. More information on Janeway can be found on its </em><a href="https://janeway.systems/"><em>website</em></a><em> or </em><a href="https://github.com/BirkbeckCTP/janeway"><em>github</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=273b7251e749" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monkey-patching is Bad]]></title>
            <link>https://ajrbyers.medium.com/monkey-patching-is-bad-4a221215aadd?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a221215aadd</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Wed, 06 Sep 2017 10:30:42 GMT</pubDate>
            <atom:updated>2017-09-06T10:30:42.197Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Monkey-patching software is generally frowned upon, but there is a time and a place for everything, even monkey-patching.</p><p>Take <a href="https://github.com/birkbeckCTP/janeway">Janeway</a> for example, we were working nicely until we had a feature request from a developer who was thinking about using it: Could we handle multi-tenant journals without using multiple domains? It made sense, not every organisation who would be interested in using this software would have the in house capacity to manage domains and subdomains when they have tens of journals so we worked out how it could be done.</p><p>Currently we were using subdomains like:<br><em>ctp.localhost</em> and we needed to move to a path based identifier eg. <em>localhost/ctp/</em> so instead of using the domain itself as the identifier we needed to use the first path element, this required an updated of our SiteSettingsMiddleware:</p><pre>def set_journal(request, site):<br>    from journal import models as journal_models<br>    if settings.URL_CONFIG == &#39;path&#39;:<br>        journal_code = request.path.split(&#39;/&#39;)[1]<br>        request.journal = journal_models.Journal.objects.get(code=journal_code)<br>    else:<br>        request.journal = journal_models.Journal.objects.get(domain=site.domain)</pre><p>Basically, we now needed to insert the journal’s code into the URL structure and have it be passed around through <em>reverse </em>functions<em> </em>and <em>{% url %}</em> tags. This would require us to make changes to Django’s core. For the URL tag this is quite easy as we can grab the Request object from Context:</p><pre>class URLNode(Node):<br>    def __init__(self, view_name, args, kwargs, asvar):<br>        self.view_name = view_name<br>        self.args = args<br>        self.kwargs = kwargs<br>        self.asvar = asvar<br><br>    def render(self, context):<br>        from django.urls import reverse, NoReverseMatch<br>        args = [arg.resolve(context) for arg in self.args]<br>        kwargs = {<br>            force_text(k, &#39;ascii&#39;): v.resolve(context)<br>            for k, v in self.kwargs.items()<br>        }<br><br>        if settings.URL_CONFIG == &#39;path&#39;:<br>            request = context.get(&#39;request&#39;, None)<br>            if request:<br>                kwargs[&#39;journal_code&#39;] = request.journal.code if request.journal else &#39;press&#39;<br><br>        view_name = self.view_name.resolve(context)<br>        try:<br>            current_app = context.request.current_app<br>        except AttributeError:<br>            try:<br>                current_app = context.request.resolver_match.namespace<br>            except AttributeError:<br>                current_app = None<br>        # Try to look up the URL. If it fails, raise NoReverseMatch unless the<br>        # {% url ... as var %} construct is used, in which case return nothing.<br>        url = &#39;&#39;<br>        try:<br>            url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)<br>        except NoReverseMatch:<br>            if self.asvar is None:<br>                raise<br><br>        if self.asvar:<br>            context[self.asvar] = url<br>            return &#39;&#39;<br>        else:<br>            if context.autoescape:<br>                url = conditional_escape(url)<br>            return url</pre><p>It’s not ridiculously difficult for the reverse function either:</p><pre>def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):<br>    <em>&quot;&quot;&quot;<br>    This monkey patch will add the journal_code to reverse kwargs if the URL_CONFIG setting is set to &#39;patch&#39;<br>    &quot;&quot;&quot;<br><br>    </em>if not viewname.startswith(&#39;djdt&#39;):<br>        local_request = GlobalRequestMiddleware.get_current_request()<br><br>        if settings.URL_CONFIG == &#39;path&#39;:<br>            code = local_request.journal.code if local_request.journal else &#39;press&#39;<br>            if kwargs and not args:<br>                kwargs[&#39;journal_code&#39;] = code<br>            else:<br>                kwargs = {&#39;journal_code&#39;: code}<br><br>            # Drop kwargs if user is accessing admin site.<br>            if local_request.path.startswith(&#39;/admin/&#39;):<br>                kwargs.pop(&#39;journal_code&#39;)<br><br>            # Drop kwargs if we have args (most likely from the template<br>            if args:<br>                kwargs = None<br>                args = [code] + args<br><br>    url = django_reverse(viewname, urlconf, args, kwargs, current_app)<br><br>    # Ensure any unicode characters in the URL are escaped.<br>    return iri_to_uri(url)</pre><p>Both of these functions insert the request.journal.code either into args or kwargs as required and then carry on a redirect as expected, this is good as we want these functions to behave as a developer would expect.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a221215aadd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django FK on_delete defaults to CASCADE]]></title>
            <link>https://ajrbyers.medium.com/django-fk-on-delete-defaults-to-cascade-1c1506aae7c7?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c1506aae7c7</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Sun, 12 Mar 2017 21:45:53 GMT</pubDate>
            <atom:updated>2017-03-12T21:46:13.494Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>What does this mean!? Well, lets make an example.</p><pre>class Company(models.Model):<br>    name = models.CharField(max_length=100)<br>    logo = models.ForeignKey(File, null=True, blank=True)</pre><pre>class File(models.Model):<br>    filename = models.CharField(max_length=100)<br>    mime = models.CharField(max_length=100)</pre><p>Say we have an Company object and a File object. The file object is set to be the logo.</p><pre>company = models.Company.objects.create(name=&#39;A Company&#39;)<br>file = models.File.objects.create(filename=&#39;file.jpg&#39;, mime=&#39;jpeg&#39;)</pre><pre>company.logo = file<br>company.save()</pre><p>If we then delete the file</p><pre>file.delete()</pre><p>Then we will actually also delete the company object because by default django will, on delete, cascade. So, we have to set the on_delete attribute to avoid this.</p><pre>class Company(models.Model)<br>    name = models.CharField(max_length=100)<br>    logo = models.ForeignKey(File, null=True, blank=True,             on_delete=models.SET_NULL)</pre><p>If the File object is deleted nowm the logo will be set to NULL rather than deleting the object.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c1506aae7c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting GET Actions to POST]]></title>
            <link>https://ajrbyers.medium.com/converting-get-actions-to-post-628b8f12dfab?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/628b8f12dfab</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Tue, 07 Feb 2017 14:06:52 GMT</pubDate>
            <atom:updated>2017-02-07T14:08:30.678Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>I’m currently converting chunks of code that make data changes on GET requests to use POST within the Django environment and thought it might be useful to document how I did it here.</p><p>Here is a snippet of code using a GET request to change data using a query string to pass the id to be deleted.</p><pre># Link in the Template<br>&lt;a href={% url &#39;a_url&#39; %}?delete={{ item.pk }}&gt;Delete Me!&lt;/a&gt;</pre><pre># Code in View<br>if &#39;delete&#39; in request.GET:<br>    item_pk = <em>request</em>.GET.get(&#39;delete&#39;)<br>    item = get_object_or_404(models.Item, pk=item_pk)<br>    item.delete()<br>    <em>return </em>redirect(reverse(&#39;a_url&#39;))</pre><p>Converting this to use POST isn’t terribly difficult.</p><pre># We&#39;ve got a button in a form now<br>&lt;form method=&quot;POST&quot;&gt;<br>    {% csrf_token %}<br>    &lt;button type=&quot;submit&quot; name=&quot;delete&quot; value=&quot;delete&quot;&gt;Delete Me!&lt;/button&gt;<br>&lt;/form&gt;</pre><pre># Code in View<br>if &#39;delete&#39; in request.POST:<br>    item_pk = <em>request</em>.POST.get(&#39;delete&#39;)<br>    item = get_object_or_404(models.Item, pk=item_pk)<br>    item.delete()<br>    <em>return </em>redirect(reverse(&#39;a_url&#39;))</pre><p>If you are adding a button for multiple items, make sure you put the form outside the loop otherwise you’ll just have a tonne of forms that do the same thing taking up memory on the DOM. The CSRF_TOKEN tag will now provide us with protection from <a href="https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet">Cross-Site Request Forgery</a> attempts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=628b8f12dfab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving On]]></title>
            <link>https://ajrbyers.medium.com/moving-on-b0d7c929625c?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0d7c929625c</guid>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Thu, 22 Sep 2016 09:01:02 GMT</pubDate>
            <atom:updated>2016-09-22T14:00:19.795Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>On the 12th of October I will be moving on from my post as Technical Architect at Ubiquity Press. I’ve had a great time working on cutting edge publishing technology and working alongside the teams at UP and our partner presses to provide a great experience</p><p>During my tenure with Ubiquity we’ve developed a fair few Open Source projects (Rua, OJSSQLA, Toru) that can be found in the <a href="https://github.com/ubiquitypress">Ubiquity Press Github</a> account and brought 12 new presses/partners on boar including:</p><ul><li>UCP’s <a href="http://www.collabra.org/">Collabra</a> and <a href="http://www.luminosoa.org/">Luminos</a> projects</li><li><a href="http://www.sljol.info/">Sri Lankan Journals Online</a></li><li><a href="https://www.openlibhums.org/">Open Library of Humanities</a></li></ul><p>Including our partners we are now hosting 170 full journals as well as providing hosting services to 6 more including:</p><ul><li><a href="http://jlsc-pub.org/">Journal of Librarianship and Scholarly Communication</a></li><li><a href="http://www.pediatricneurologybriefs.com/">Paediatric Neurology Briefs</a></li><li><a href="http://www.inasp.info/en/work/journals-online/current-jols/">Banglajol, Camjol, Mongoliajol and Nepjol</a> with INASP</li></ul><p>We’ve also developed a Conference Proceedings System currently in use by <a href="http://scidatacon.org/">Sci Data Con/Codata</a>.</p><p>I’ve also had the chance to work with some great developers during my time, to whom much of the success of the UP platform belongs. UP are in the process of hiring a replacement who I’m sure will continue this work.</p><p>In the mean time I will be working on some FOSS projects in a freelance capacity before looking for a new post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0d7c929625c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Fundref via Fundref Widget]]></title>
            <link>https://ajrbyers.medium.com/integrating-fundref-via-fundref-widget-4d1a5b7c4a97?source=rss-d482fb5144d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d1a5b7c4a97</guid>
            <category><![CDATA[filtering]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[fundref]]></category>
            <dc:creator><![CDATA[Andy Byers]]></dc:creator>
            <pubDate>Thu, 08 Sep 2016 11:23:10 GMT</pubDate>
            <atom:updated>2016-09-08T11:30:20.671Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*97NRRlAJ5J5m2Kzm3z_hjA.png" /></figure><p>At Ubiquity Press our new Junior Developer, <a href="https://medium.com/@stuartjennings13">Stuart Jennings</a> is working to integrate Fundref with our submission platform, allowing authors to submit their Funding info so it can be published and deposited with Crossref.</p><p>We were informed of the Fundref Widget (<a href="http://labs.crossref.org/fundref/widget/#">info</a>, <a href="https://github.com/CrossRef/fundref-widget">github</a>), which we used as the basis of our integration, with a slight modifications so that we can get hold of the Funder ID as well as their official name (required for deposit) and to bind the funder names to the award numbers.</p><p>This all went fine until Stuart started noticing blank entries in our POST dictionary:</p><pre>&lt;QueryDict: {u&#39;abstract&#39;: [u&#39;&#39;], u&#39;title&#39;: [u&#39;d&#39;], u&#39;csrfmiddlewaretoken&#39;: [u&#39;iO4X7u8TAS6Ew6sTGu9mAEOr1QyH7d47&#39;], u&#39;has-funding&#39;: [u&#39;True&#39;], u&#39;has-competing&#39;: [u&#39;False&#39;], u&#39;funder-name-2&#39;: [u&#39;Cambridge University Hospitals&#39;], u&#39;funder-name-3&#39;: [u&#39;Fake Uni&#39;], u&#39;funder-name-0&#39;: [u&#39;&#39;], u&#39;funder-name-1&#39;: [u&#39;Oxford University Hospitals NHS Trust&#39;], u&#39;section_id&#39;: [u&#39;5&#39;], u&#39;funder-name-4&#39;: [u&#39;&#39;], u&#39;funder-name-5&#39;: [u&#39;&#39;], u&#39;award-number-3&#39;: [u&#39;&#39;, u&#39;&#39;], u&#39;award-number-4&#39;: [u&#39;&#39;, u&#39;&#39;], u&#39;award-number-5&#39;: [u&#39;&#39;, u&#39;1213&#39;], u&#39;award-number-2&#39;: [u&#39;&#39;, u&#39;Cam1&#39;, u&#39;Cam2&#39;, u&#39;&#39;], u&#39;award-number-0&#39;: [u&#39;&#39;], u&#39;award-number-1&#39;: [u&#39;&#39;, u&#39;Ox1&#39;, u&#39;Ox2&#39;, u&#39;Ox3&#39;]}&gt;<br></pre><p>After some post-processing</p><pre>award_numbers = {k: v for k, v in award_number_dict.iteritems() if v and k.startswith(&#39;award-number-&#39;)}</pre><p>we’re left with the much nicer looking:</p><pre>{<br>u&#39;award-number-0&#39;: [u&#39;&#39;],<br>u&#39;award-number-1&#39;: [u&#39;&#39;, u&#39;Ox1&#39;, u&#39;Ox2&#39;, u&#39;Ox3&#39;],<br>u&#39;award-number-2&#39;: [u&#39;&#39;, u&#39;Cam1&#39;, u&#39;Cam2&#39;, u&#39;&#39;],<br>u&#39;award-number-3&#39;: [u&#39;&#39;, u&#39;&#39;],<br>u&#39;award-number-4&#39;: [u&#39;&#39;, u&#39;&#39;],<br>u&#39;award-number-5&#39;: [u&#39;&#39;, u&#39;1213&#39;]<br>}</pre><p>In order to filter out these blanks in the list we simply need to filter them out, python has a neat little function called filter that does exactly this:</p><pre>award_numbers = {k: filter(None, v) for k, v in award_number_dict.iteritems() if v and k.startswith(&#39;award-number-&#39;)}</pre><p>Voila:</p><pre>{<br>u&#39;award-number-0&#39;: [],<br>u&#39;award-number-1&#39;: [u&#39;Ox1&#39;, u&#39;Ox2&#39;, u&#39;Ox3&#39;],<br>u&#39;award-number-2&#39;: [u&#39;Cam1&#39;, u&#39;Cam2&#39;],<br>u&#39;award-number-3&#39;: [],<br>u&#39;award-number-4&#39;: [],<br>u&#39;award-number-5&#39;: [u&#39;1213&#39;]<br>}</pre><p>After some investigation, it appears that the Fundref widget creates a set of invisible fields and clones these whenever it is asked to add a new row to the block.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d1a5b7c4a97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>