Navigation Menu

Skip to content

Commit

Permalink
Fixed ampersand encoding in XML and version ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Feb 19, 2014
1 parent ef81da4 commit f88418e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
13 changes: 8 additions & 5 deletions qgis-app/plugins/models.py
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-

import datetime, os, re

from django.db import models
# import auth users for owners
from django.contrib.auth.models import User
Expand All @@ -7,7 +10,6 @@
# For permalinks
from django.core.urlresolvers import reverse
from django.conf import settings
import datetime, os, re
from djangoratings.fields import AnonymousRatingField

# Tagging
Expand Down Expand Up @@ -374,19 +376,20 @@ def vjust(str, level=3, delim='.', bitsize=3, fillchar=' ', force_zero=False):
return delim.join([ v.rjust(bitsize,fillchar) for v in str.split(delim)[:level+1] ])



class VersionField(models.CharField) :

description = 'Field to store version strings ("a.b.c.d") in a way it is sortable'

__metaclass__ = models.SubfieldBase

def get_prep_value(self, value):
return vjust(value,fillchar=' ')
return vjust(value, fillchar='#')

def to_python(self, value):
if not value:
return ''
return re.sub('\.+$','',value.replace(' ',''))
return re.sub('#+|\.#+(\.|$)', '', value)


class QGVersionZeroForcedField(models.CharField) :
Expand All @@ -397,12 +400,12 @@ class QGVersionZeroForcedField(models.CharField) :
__metaclass__ = models.SubfieldBase

def get_prep_value(self, value):
return vjust(value,fillchar=' ',level=2,force_zero=True)
return vjust(value,fillchar='#',level=2,force_zero=True)

def to_python(self, value):
if not value:
return ''
return re.sub('\.+$','',value.replace(' ',''))
return re.sub('#+|\.#+(\.|$)', '', value)


class PluginVersion (models.Model):
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/plugins/templates/plugins/plugin_list.html
Expand Up @@ -91,7 +91,7 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}</h2>
{% if not user.is_anonymous %}<td>{% if object.approved %}<img src="/static/images/tick_16.png" />{% else %}&mdash;{% endif %}</td>{% endif %}
<td>{% if object.featured%}<img src="/static/images/tick_16.png" />{% else %}&mdash;{% endif %}</td>
<td>{{ object.downloads }}</td>
<td><a title="{% trans "See all plugins by"%} {{ object.author }}" href="{% url "author_plugins" object.author|urlencode %}">{{ object.author }}</a></td>
<td><a title="{% trans "See all plugins by"%} {{ object.author }}" href="{% url "author_plugins" object.author %}">{{ object.author }}</a></td>
<!--
<td>{{ object.modified_on|naturalday }}</td>
-->
Expand Down
14 changes: 7 additions & 7 deletions qgis-app/plugins/templates/plugins/plugins.xml
Expand Up @@ -6,21 +6,21 @@
<version>{{ version.version }}</version>
<qgis_minimum_version>{{ version.min_qg_version }}</qgis_minimum_version>
<qgis_maximum_version>{{ version.max_qg_version }}</qgis_maximum_version>
<homepage>{% if version.plugin.homepage %}{{ version.plugin.homepage }}{% else %}{% if request.is_secure %}https{% else %}http{% endif %}://{{ request.get_host }}{{ version.plugin.get_absolute_url }}{% endif %}</homepage>
<homepage><![CDATA[{% if version.plugin.homepage %}{{ version.plugin.homepage }}{% else %}{% if request.is_secure %}https{% else %}http{% endif %}://{{ request.get_host }}{{ version.plugin.get_absolute_url }}{% endif %}]]></homepage>
<file_name>{{ version.download_file_name }}</file_name>
<icon>{% if version.plugin.icon %}{{ version.plugin.icon.url }}{% endif %}</icon>
<author_name>{% firstof version.plugin.author version.plugin.created_by %}</author_name>
<author_name><![CDATA[{% firstof version.plugin.author version.plugin.created_by %}]]></author_name>
<download_url>{% if request.is_secure %}https{% else %}http{% endif %}://{{ request.get_host }}{{ version.get_download_url }}</download_url>
<uploaded_by>{{ version.created_by }}</uploaded_by>
<uploaded_by><![CDATA[{{ version.created_by }}]]></uploaded_by>
<create_date>{{ version.created_on.isoformat }}</create_date>
<update_date>{{ version.created_on.isoformat }}</update_date>
<experimental>{% if version.experimental %}True{% else%}False{% endif %}</experimental>
<deprecated>{{ version.plugin.deprecated }}</deprecated>
<tracker>{{ version.plugin.tracker }}</tracker>
<repository>{{ version.plugin.repository }}</repository>
<tags>{% for tag in version.plugin.tags.all %}{{ tag }}{% if not forloop.last %},{% endif %}{% endfor %}</tags>
<tracker><![CDATA[{{ version.plugin.tracker }}]]></tracker>
<repository><![CDATA[{{ version.plugin.repository }}]]></repository>
<tags><![CDATA[{% for tag in version.plugin.tags.all %}{{ tag }}{% if not forloop.last %},{% endif %}{% endfor %}]]></tags>
<downloads>{{version.plugin.downloads}}</downloads>
<average_vote>{{version.plugin.avg_vote}}</average_vote>
<rating_votes>{{version.plugin.rating_votes}}</rating_votes>
</pyqgis_plugin>{% endfor %}
</pyqgis_plugin>{% endfor %}
</plugins>
2 changes: 1 addition & 1 deletion qgis-app/plugins/templates/plugins/tagcloud_include.html
Expand Up @@ -11,4 +11,4 @@
<a style="font-size:{{tag.weight|floatformat:0}}px" href="{% url "tags_plugins" tag.name %}">{{tag}}</a>
{% endfor %}
<div style="clear:both"></div>
</div>
</div>
17 changes: 12 additions & 5 deletions qgis-app/plugins/views.py
Expand Up @@ -27,7 +27,7 @@
from django.core.mail import send_mail
from django.contrib.sites.models import Site
import logging

import urllib
import copy

# Decorator
Expand Down Expand Up @@ -382,6 +382,7 @@ class PluginsList(ListView):
queryset = Plugin.approved_objects.all()
title = _('All plugins')
additional_context = {}

def get_context_data(self, **kwargs):
context = super(PluginsList, self).get_context_data(**kwargs)
context.update({
Expand All @@ -393,23 +394,27 @@ def get_context_data(self, **kwargs):


class MyPluginsList(PluginsList):

def get_queryset(self):
return Plugin.base_objects.filter(owners=self.request.user).distinct() | Plugin.objects.filter(created_by=self.request.user).distinct()


class UserPluginsList(PluginsList):

def get_queryset(self):
user = get_object_or_404(User, username=self.kwargs['username'])
return Plugin.approved_objects.filter(created_by=user)


class AuthorPluginsList(PluginsList):

def get_queryset(self):
return Plugin.approved_objects.filter(author=self.kwargs['author'])
return Plugin.approved_objects.filter(author=urllib.unquote(self.kwargs['author']))

def get_context_data(self, **kwargs):
context = super(AuthorPluginsList, self).get_context_data(**kwargs)
context.update({
'title' : _('Plugins by %s') % self.kwargs['author'],
'title' : _('Plugins by %s') % urllib.unquote(self.kwargs['author']),
})
return context

Expand Down Expand Up @@ -437,12 +442,14 @@ def get_context_data(self, **kwargs):


class TagsPluginsList(PluginsList):

def get_queryset(self):
return Plugin.approved_objects.filter(tagged_items__tag__name=self.kwargs['tags'])
return Plugin.approved_objects.filter(tagged_items__tag__name=urllib.unquote(self.kwargs['tags']))

def get_context_data(self, **kwargs):
context = super(TagsPluginsList, self).get_context_data(**kwargs)
context.update({
'title' : _('Plugins tagged with: %s') % self.kwargs['tags'],
'title' : _('Plugins tagged with: %s') % urllib.unquote(self.kwargs['tags']),
})
return context

Expand Down

0 comments on commit f88418e

Please sign in to comment.