euscanwww: use maintainers names, not ids

Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
Corentin Chary 2012-10-29 12:47:32 +01:00
parent 808acfe13a
commit 5a8d7e8932
9 changed files with 57 additions and 42 deletions

View File

@ -97,8 +97,12 @@ class PackagesHandler(AnonymousBaseHandler):
herd = Herd.objects.get(herd=kwargs['herd']) herd = Herd.objects.get(herd=kwargs['herd'])
packages = Package.objects.for_herd(herd, last_versions=True) packages = Package.objects.for_herd(herd, last_versions=True)
data = {'herd': herd} data = {'herd': herd}
elif 'maintainer_id' in kwargs: elif 'maintainer_id' in kwargs or 'maintainer_email' in kwargs:
maintainer = Maintainer.objects.get(id=kwargs['maintainer_id']) if 'maintainer_id' in kwargs:
maintainer = Maintainer.objects.get(id=kwargs['maintainer_id'])
elif 'maintainer_email' in kwargs:
maintainer = Maintainer.objects.get(email=kwargs['maintainer_email'])
packages = Package.objects.for_maintainer( packages = Package.objects.for_maintainer(
maintainer, maintainer,
last_versions=True last_versions=True

View File

@ -24,6 +24,8 @@ urlpatterns = patterns('djeuscan.api.views',
url(r'^1.0/packages/by-maintainer/(?P<maintainer_id>\d+)\.(?P<emitter_format>.+)$', url(r'^1.0/packages/by-maintainer/(?P<maintainer_id>\d+)\.(?P<emitter_format>.+)$',
packages_handler, name='api.views.packages'), packages_handler, name='api.views.packages'),
url(r'^1.0/packages/by-maintainer/(?P<maintainer_email>[^/]+)\.(?P<emitter_format>.+)$',
packages_handler, name='api.views.packages'),
url(r'^1.0/packages/by-herd/(?P<herd>[\@\{\}\w+.-]*)\.(?P<emitter_format>.+)?$', url(r'^1.0/packages/by-herd/(?P<herd>[\@\{\}\w+.-]*)\.(?P<emitter_format>.+)?$',
packages_handler, name='api.views.packages'), packages_handler, name='api.views.packages'),
url(r'^1.0/packages/by-category/(?P<category>[\w+][\w+.-]*)\.(?P<emitter_format>.+)?$', url(r'^1.0/packages/by-category/(?P<category>[\w+][\w+.-]*)\.(?P<emitter_format>.+)?$',

View File

@ -146,9 +146,16 @@ class PackageFeed(BaseFeed):
class MaintainerFeed(BaseFeed): class MaintainerFeed(BaseFeed):
feed_type = Atom1Feed feed_type = Atom1Feed
def get_object(self, request, maintainer_id): def get_object(self, request, maintainer_id=None, maintainer_email=None):
print maintainer_id, maintainer_email
if maintainer_id:
obj = get_object_or_404(Maintainer, id=maintainer_id)
else:
obj = get_object_or_404(Maintainer, email=maintainer_email)
print obj
return { return {
"obj": get_object_or_404(Maintainer, id=maintainer_id), "obj": obj,
"options": request.GET, "options": request.GET,
} }
@ -159,8 +166,7 @@ class MaintainerFeed(BaseFeed):
return "Last changes for %s" % data["obj"] return "Last changes for %s" % data["obj"]
def link(self, data): def link(self, data):
return reverse('djeuscan.views.maintainer', return reverse('djeuscan.views.maintainer', args=[data["obj"].email])
kwargs={'maintainer_id': data["obj"].id})
def _items(self, data): def _items(self, data):
return VersionLog.objects.for_maintainer(data["obj"]), 50 return VersionLog.objects.for_maintainer(data["obj"]), 50

View File

@ -18,7 +18,7 @@
{% for maintainer in maintainers %} {% for maintainer in maintainers %}
<tr> <tr>
<td> <td>
<a href="{% url "maintainer" maintainer.maintainers__id %}"> <a href="{% url "maintainer" maintainer.maintainers__email %}">
{% if maintainer.maintainers__name != maintainer.maintainers__email %} {% if maintainer.maintainers__name != maintainer.maintainers__email %}
{{ maintainer.maintainers__name }} &lt;{{ maintainer.maintainers__email }}&gt; {{ maintainer.maintainers__name }} &lt;{{ maintainer.maintainers__email }}&gt;
{% else %} {% else %}
@ -31,8 +31,8 @@
{% if extras %} {% if extras %}
<td> <td>
<img src="{% url "chart_maintainer" maintainer.maintainers__id 'packages-monthly-small' %}" /> <img src="{% url "chart_maintainer" maintainer.maintainers__email 'packages-monthly-small' %}" />
<img src="{% url "chart_maintainer" maintainer.maintainers__id 'versions-monthly-small' %}" /> <img src="{% url "chart_maintainer" maintainer.maintainers__email 'versions-monthly-small' %}" />
</td> </td>
{% endif %} {% endif %}

View File

@ -33,12 +33,12 @@
{% for maintainer in package.maintainers.all %} {% for maintainer in package.maintainers.all %}
<p> <p>
{% if maintainer.name != maintainer.email %} {% if maintainer.name != maintainer.email %}
<a href="{% url "maintainer" maintainer.id %}"> <a href="{% url "maintainer" maintainer.email %}">
{{ maintainer.name }} {{ maintainer.name }}
</a> </a>
&lt;{{ maintainer.email }}&gt; &lt;{{ maintainer.email }}&gt;
{% else %} {% else %}
<a href="{% url "maintainer" maintainer.id %}"> <a href="{% url "maintainer" maintainer.email %}">
{{ maintainer.email }} {{ maintainer.email }}
</a> </a>
{% endif %} {% endif %}

View File

@ -75,7 +75,7 @@
Hot maintainers: Hot maintainers:
<ul> <ul>
{% for c in maintainers|slice:":3" %} {% for c in maintainers|slice:":3" %}
<li><a href="{% url "maintainer" c.maintainers__id %}">{{ c.maintainers__name }}</a> ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }})</li> <li><a href="{% url "maintainer" c.maintainers__email %}">{{ c.maintainers__name }}</a> ({{ c.n_versions|sub:c.n_packaged|sub:c.n_overlay }})</li>
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>

View File

@ -11,7 +11,7 @@
{{ block.super }} {{ block.super }}
<li> <li>
<img src="{{ STATIC_URL }}/img/feed.png" alt="feed" /> <img src="{{ STATIC_URL }}/img/feed.png" alt="feed" />
<a title="{{ maintainer.name }} Feed" href="{% url "maintainer_feed" maintainer.id %}"> <a title="{{ maintainer.name }} Feed" href="{% url "maintainer_feed" maintainer.email %}">
{{ maintainer.name|truncatechars:15 }} {{ maintainer.name|truncatechars:15 }}
</a> </a>
</li> </li>
@ -22,10 +22,10 @@
Maintainer: {{ maintainer.name }} &lt;{{ maintainer.email }}&gt; Maintainer: {{ maintainer.name }} &lt;{{ maintainer.email }}&gt;
{% if user.is_authenticated %} {% if user.is_authenticated %}
<span class="pull-right"> <span class="pull-right">
<button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_maintainer" maintainer.id %}"> <button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_maintainer" maintainer.email %}">
<img src="{{ STATIC_URL}}/img/watch-icon.png" alt="Watch" /> <img src="{{ STATIC_URL}}/img/watch-icon.png" alt="Watch" />
</button> </button>
<button class="btn unfavourite-button {% if not favourited %}hide{% endif %}" data-url="{% url "unfavourite_maintainer" maintainer.id %}"> <button class="btn unfavourite-button {% if not favourited %}hide{% endif %}" data-url="{% url "unfavourite_maintainer" maintainer.email %}">
<img src="{{ STATIC_URL}}/img/unwatch-icon.png" alt="Unwatch" /> <img src="{{ STATIC_URL}}/img/unwatch-icon.png" alt="Unwatch" />
</button> </button>
</span> </span>
@ -37,19 +37,19 @@
<h3>Statistics</h3> <h3>Statistics</h3>
<h4>Current statistics</h4> <h4>Current statistics</h4>
<p> <p>
<img alt="pie versions" src="{% url "chart_maintainer" maintainer.id 'pie-versions' %}" /> <img alt="pie versions" src="{% url "chart_maintainer" maintainer.email 'pie-versions' %}" />
<img alt="pie packages" src="{% url "chart_maintainer" maintainer.id 'pie-packages' %}" /> <img alt="pie packages" src="{% url "chart_maintainer" maintainer.email 'pie-packages' %}" />
</p> </p>
<h4>All Time</h4> <h4>All Time</h4>
<p> <p>
<img alt="version weekly" src="{% url "chart_maintainer" maintainer.id 'versions-weekly' %}" /> <img alt="version weekly" src="{% url "chart_maintainer" maintainer.email 'versions-weekly' %}" />
<img alt="versions monthly" src="{% url "chart_maintainer" maintainer.id 'versions-monthly' %}" /> <img alt="versions monthly" src="{% url "chart_maintainer" maintainer.email 'versions-monthly' %}" />
</p> </p>
<p> <p>
<img alt="packages weekly" src="{% url "chart_maintainer" maintainer.id 'packages-weekly' %}" /> <img alt="packages weekly" src="{% url "chart_maintainer" maintainer.email 'packages-weekly' %}" />
<img alt="packages monthly" src="{% url "chart_maintainer" maintainer.id 'packages-monthly' %}" /> <img alt="packages monthly" src="{% url "chart_maintainer" maintainer.email 'packages-monthly' %}" />
</p> </p>
<script type="text/javascript"> <script type="text/javascript">
@ -77,9 +77,9 @@ $(document).ready(function () {
<div class="menu rounded notfirst-menu"> <div class="menu rounded notfirst-menu">
<dl> <dl>
<dt>Versions</dt> <dt>Versions</dt>
<dd><img alt="versions" src="{% url "chart_maintainer" maintainer.id 'versions-monthly-small' %}" /></dd> <dd><img alt="versions" src="{% url "chart_maintainer" maintainer.email 'versions-monthly-small' %}" /></dd>
<dt>Packages</dt> <dt>Packages</dt>
<dd><img alt="packages" src="{% url "chart_maintainer" maintainer.id 'packages-monthly-small' %}" /></dd> <dd><img alt="packages" src="{% url "chart_maintainer" maintainer.email 'packages-monthly-small' %}" /></dd>
</dl> </dl>
</div> </div>

View File

@ -55,16 +55,13 @@ herds_patterns = patterns('djeuscan.views',
url(r'^$', 'herds', name="herds"), url(r'^$', 'herds', name="herds"),
) )
prefix = '^((?P<maintainer_id>\d+)|(?P<maintainer_email>[^/]+))'
maintainers_patterns = patterns('djeuscan.views', maintainers_patterns = patterns('djeuscan.views',
url(r'^(?P<maintainer_id>\d+)/(view/)?$', 'maintainer', name="maintainer"), url(prefix + r'/(view/)?$', 'maintainer', name="maintainer"),
url(r'^(?P<maintainer_id>\d+)/feed/$', MaintainerFeed(), url(prefix + r'/feed/$', MaintainerFeed(), name='maintainer_feed'),
name='maintainer_feed'), url(prefix + r'/charts/(?P<chart>[\w\-]+).png$', 'chart_maintainer', name="chart_maintainer"),
url(r'^(?P<maintainer_id>\d+)/charts/(?P<chart>[\w\-]+).png$', url(prefix + r'/favourite/$', 'favourite_maintainer', name="favourite_maintainer"),
'chart_maintainer', name="chart_maintainer"), url(prefix + r'/unfavourite/$', 'unfavourite_maintainer', name="unfavourite_maintainer"),
url(r'^(?P<maintainer_id>\d+)/favourite/$',
'favourite_maintainer', name="favourite_maintainer"),
url(r'^(?P<maintainer_id>\d+)/unfavourite/$',
'unfavourite_maintainer', name="unfavourite_maintainer"),
url(r'^$', 'maintainers', name="maintainers"), url(r'^$', 'maintainers', name="maintainers"),
) )

View File

@ -122,9 +122,15 @@ def maintainers(request):
return {'maintainers': maintainers, 'last_scan': last_scan} return {'maintainers': maintainers, 'last_scan': last_scan}
def get_maintainer_or_404(id=None, email=None):
if id:
return get_object_or_404(Maintainer, pk=id)
else:
return get_object_or_404(Maintainer, email=email)
@render_to('euscan/maintainer.html') @render_to('euscan/maintainer.html')
def maintainer(request, maintainer_id): def maintainer(request, maintainer_id=None, maintainer_email=None):
maintainer = get_object_or_404(Maintainer, pk=maintainer_id) maintainer = get_maintainer_or_404(maintainer_id, maintainer_email)
packages = Package.objects.for_maintainer(maintainer, last_versions=True) packages = Package.objects.for_maintainer(maintainer, last_versions=True)
try: try:
@ -337,10 +343,10 @@ def chart(request, **kwargs):
chart = kwargs['chart'] if 'chart' in kwargs else None chart = kwargs['chart'] if 'chart' in kwargs else None
if 'maintainer_id' in kwargs: if 'maintainer_id' in kwargs or 'maintainer_email' in kwargs:
kwargs['maintainer'] = get_object_or_404( kwargs['maintainer'] = get_maintainer_or_404(
Maintainer, kwargs.get('maintainer_id'),
id=kwargs['maintainer_id'] kwargs.get('maintainer_email')
) )
if 'herd' in kwargs: if 'herd' in kwargs:
kwargs['herd'] = get_object_or_404(Herd, herd=kwargs['herd']) kwargs['herd'] = get_object_or_404(Herd, herd=kwargs['herd'])
@ -550,8 +556,8 @@ def unfavourite_herd(request, herd):
@login_required @login_required
@require_POST @require_POST
@ajax_request @ajax_request
def favourite_maintainer(request, maintainer_id): def favourite_maintainer(request, maintainer_id=None, maintainer_email=None):
obj = get_object_or_404(Maintainer, pk=maintainer_id) obj = get_maintainer_or_404(maintainer_id, maintainer_email)
get_profile(request.user).maintainers.add(obj) get_profile(request.user).maintainers.add(obj)
return {"success": True} return {"success": True}
@ -559,8 +565,8 @@ def favourite_maintainer(request, maintainer_id):
@login_required @login_required
@require_POST @require_POST
@ajax_request @ajax_request
def unfavourite_maintainer(request, maintainer_id): def unfavourite_maintainer(request, maintainer_id=None, maintainer_email=None):
maintainer = get_object_or_404(Maintainer, pk=maintainer_id) obj = get_maintainer_or_404(maintainer_id, maintainer_email)
get_profile(request.user).maintainers.remove(maintainer) get_profile(request.user).maintainers.remove(maintainer)
return {"success": True} return {"success": True}