Ticket #41: 0001-Implement-simple-media-detail-page.patch

File 0001-Implement-simple-media-detail-page.patch, 11.7 KB (added by Sebastian Spaeth, 13 years ago)

0001-Implement-simple-media-detail-page.patch

  • mediagoblin/routing.py

    From 4e3160f0a3106165d3fd721499155d0e9ad20732 Mon Sep 17 00:00:00 2001
    From: Sebastian Spaeth <Sebastian@SSpaeth.de>
    Date: Sun, 8 May 2011 20:35:54 +0200
    Subject: [PATCH] Implement simple media detail page
    
    This patch creates a "homepage" for each media. The URL is
    /u/<username>/m/<objID>.
    
    On it we display the media and some details. It is ugly and lacking some
    stuff but it works. The only thing left to do is to throw an 404 error
    if the <username> and the media uploader don't correspond.
    
    - Also create a user "home page" while at it. It is merely a place
      holder for now though.
    
    - Link from the entries on the homepage, to the media pages, so we
    actually find them.
    
    Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
    ---
     mediagoblin/routing.py                             |    3 +-
     .../templates/mediagoblin/media_details.html       |   34 +++++++++++++
     mediagoblin/templates/mediagoblin/root.html        |    6 ++-
     .../templates/mediagoblin/user_pages/media.html    |   41 +++++++++++++++
     .../templates/mediagoblin/user_pages/user.html     |   26 ++++++++++
     mediagoblin/user_pages/routing.py                  |   24 +++++++++
     mediagoblin/user_pages/views.py                    |   52 ++++++++++++++++++++
     mediagoblin/views.py                               |    4 +-
     8 files changed, 185 insertions(+), 5 deletions(-)
     create mode 100644 mediagoblin/templates/mediagoblin/media_details.html
     create mode 100644 mediagoblin/templates/mediagoblin/user_pages/media.html
     create mode 100644 mediagoblin/templates/mediagoblin/user_pages/user.html
     create mode 100644 mediagoblin/user_pages/__init__.py
     create mode 100644 mediagoblin/user_pages/routing.py
     create mode 100644 mediagoblin/user_pages/views.py
    
    diff --git a/mediagoblin/routing.py b/mediagoblin/routing.py
    index b47bec8..356ef67 100644
    a b from routes import Mapper  
    1818
    1919from mediagoblin.auth.routing import auth_routes
    2020from mediagoblin.submit.routing import submit_routes
    21 
     21from mediagoblin.user_pages.routing import user_routes
    2222
    2323def get_mapper():
    2424    mapping = Mapper()
    def get_mapper():  
    3030
    3131    mapping.extend(auth_routes, '/auth')
    3232    mapping.extend(submit_routes, '/submit')
     33    mapping.extend(user_routes, '/u')
    3334
    3435    return mapping
  • new file mediagoblin/templates/mediagoblin/media_details.html

    diff --git a/mediagoblin/templates/mediagoblin/media_details.html b/mediagoblin/templates/mediagoblin/media_details.html
    new file mode 100644
    index 0000000..a00354b
    - +  
     1{#
     2# GNU MediaGoblin -- federated, autonomous media hosting
     3# Copyright (C) 2011 Free Software Foundation, Inc
     4#
     5# This program is free software: you can redistribute it and/or modify
     6# it under the terms of the GNU Affero General Public License as published by
     7# the Free Software Foundation, either version 3 of the License, or
     8# (at your option) any later version.
     9#
     10# This program is distributed in the hope that it will be useful,
     11# but WITHOUT ANY WARRANTY; without even the implied warranty of
     12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13# GNU Affero General Public License for more details.
     14#
     15# You should have received a copy of the GNU Affero General Public License
     16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17#}
     18{% extends "mediagoblin/base.html" %}
     19{% block mediagoblin_content %}
     20
     21  {# temporarily, an "image gallery" that isn't one really ;) #}
     22  {% if media %}
     23  <h2>Media details for {{media.title}}</h2>
     24  <div>
     25    <img src="{{ request.app.public_store.file_url(
     26                  media.media_files.main) }}" />
     27
     28          <br/>Uploaded: {{ media.created}}
     29          <br/>Description: {{media.description}}
     30  </div>
     31  {% else %}
     32  <p>Sorry, no such media found.<p/>
     33  {% endif %}
     34{% endblock %}   
  • mediagoblin/templates/mediagoblin/root.html

    diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html
    index 06a89f3..2cb0a9c 100644
    a b  
    4343    <ul>
    4444      {% for entry in media_entries %}
    4545        <li>
    46           <img src="{{ request.app.public_store.file_url(
    47                            entry['media_files']['thumb']) }}" />
     46          <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
     47                   user= entry.uploader.username, m_id= entry._id) }}">
     48            <img src="{{ request.app.public_store.file_url(
     49                      entry['media_files']['thumb']) }}" /></a>
    4850        </li>
    4951      {% endfor %}
    5052    </ul>
  • new file mediagoblin/templates/mediagoblin/user_pages/media.html

    diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html
    new file mode 100644
    index 0000000..08cc925
    - +  
     1{#
     2# GNU MediaGoblin -- federated, autonomous media hosting
     3# Copyright (C) 2011 Free Software Foundation, Inc
     4#
     5# This program is free software: you can redistribute it and/or modify
     6# it under the terms of the GNU Affero General Public License as published by
     7# the Free Software Foundation, either version 3 of the License, or
     8# (at your option) any later version.
     9#
     10# This program is distributed in the hope that it will be useful,
     11# but WITHOUT ANY WARRANTY; without even the implied warranty of
     12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13# GNU Affero General Public License for more details.
     14#
     15# You should have received a copy of the GNU Affero General Public License
     16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17#}
     18{% extends "mediagoblin/base.html" %}
     19{% block mediagoblin_content %}
     20
     21  {# temporarily, an "image gallery" that isn't one really ;) #}
     22  {% if media %}
     23  <h2>Media details for <a
     24             href="{{ request.urlgen('mediagoblin.user_pages.user_home',
     25             user= media.uploader.username) }}">{{media.uploader.username}}</a>
     26             / {{media.title}}
     27  </h2>
     28  <div>
     29    <img src="{{ request.app.public_store.file_url(
     30                  media.media_files.main) }}" />
     31
     32          <br/>Uploaded on {{ "%4d-%02d-%02d"|format(media.created.year,
     33             media.created.month,media.created.day)}} by <a
     34             href="{{ request.urlgen('mediagoblin.user_pages.user_home',
     35                   user= media.uploader.username) }}">{{media.uploader.username}}</a>
     36          <br/>Description: {{media.description}}
     37  </div>
     38  {% else %}
     39  <p>Sorry, no such media found.<p/>
     40  {% endif %}
     41{% endblock %}   
  • new file mediagoblin/templates/mediagoblin/user_pages/user.html

    diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html
    new file mode 100644
    index 0000000..4ad34f5
    - +  
     1{#
     2# GNU MediaGoblin -- federated, autonomous media hosting
     3# Copyright (C) 2011 Free Software Foundation, Inc
     4#
     5# This program is free software: you can redistribute it and/or modify
     6# it under the terms of the GNU Affero General Public License as published by
     7# the Free Software Foundation, either version 3 of the License, or
     8# (at your option) any later version.
     9#
     10# This program is distributed in the hope that it will be useful,
     11# but WITHOUT ANY WARRANTY; without even the implied warranty of
     12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13# GNU Affero General Public License for more details.
     14#
     15# You should have received a copy of the GNU Affero General Public License
     16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17#}
     18{% extends "mediagoblin/base.html" %}
     19{% block mediagoblin_content -%}
     20  {% if user %}
     21  <h2>User page for '{{user.username}}'</h2>
     22  {{user}}
     23  {% else %}
     24  <p>Sorry, no such user found.<p/>
     25  {% endif %}
     26{% endblock %}   
  • new file mediagoblin/user_pages/routing.py

    diff --git a/mediagoblin/user_pages/__init__.py b/mediagoblin/user_pages/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py
    new file mode 100644
    index 0000000..10ecd4f
    - +  
     11# GNU MediaGoblin -- federated, autonomous media hosting
     2# Copyright (C) 2011 Free Software Foundation, Inc
     3#
     4# This program is free software: you can redistribute it and/or modify
     5# it under the terms of the GNU Affero General Public License as published by
     6# the Free Software Foundation, either version 3 of the License, or
     7# (at your option) any later version.
     8#
     9# This program is distributed in the hope that it will be useful,
     10# but WITHOUT ANY WARRANTY; without even the implied warranty of
     11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12# GNU Affero General Public License for more details.
     13#
     14# You should have received a copy of the GNU Affero General Public License
     15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16
     17from routes.route import Route
     18
     19user_routes = [
     20    Route('mediagoblin.user_pages.user_home', "/{user}",
     21        controller="mediagoblin.user_pages.views:user_home"),
     22    Route('mediagoblin.user_pages.media_home', r'/{user}/m/{m_id}',
     23        requirements=dict(m_id="[0-9a-fA-F]{24}"),
     24        controller="mediagoblin.user_pages.views:media_home")]
  • new file mediagoblin/user_pages/views.py

    diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
    new file mode 100644
    index 0000000..b1a301d
    - +  
     1# GNU MediaGoblin -- federated, autonomous media hosting
     2# Copyright (C) 2011 Free Software Foundation, Inc
     3#
     4# This program is free software: you can redistribute it and/or modify
     5# it under the terms of the GNU Affero General Public License as published by
     6# the Free Software Foundation, either version 3 of the License, or
     7# (at your option) any later version.
     8#
     9# This program is distributed in the hope that it will be useful,
     10# but WITHOUT ANY WARRANTY; without even the implied warranty of
     11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12# GNU Affero General Public License for more details.
     13#
     14# You should have received a copy of the GNU Affero General Public License
     15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16
     17from webob import Response
     18from mongokit import ObjectId
     19import wtforms
     20#from mongokit import ObjectId
     21
     22def user_home(request):
     23    """'Homepage' of a User()"""
     24    user = request.db.User.find_one(
     25        {'username': request.matchdict['user']})
     26
     27    medias = request.db.MediaEntry.find()
     28
     29    template = request.template_env.get_template(
     30        'mediagoblin/user_pages/user.html')
     31    return Response(
     32        template.render(
     33            {'request': request,
     34             'user': user,
     35             'medias': medias}))
     36
     37def media_home(request):
     38    """'Homepage' of a MediaEntry()"""
     39    media = request.db.MediaEntry.find_one(
     40        ObjectId(request.matchdict['m_id']))
     41
     42    #check that media uploader and user correspondent
     43    if media['uploader'].get('username') != request.matchdict['user']:
     44        #TODO: How do I throw an error 404?
     45        pass
     46
     47    template = request.template_env.get_template(
     48        'mediagoblin/user_pages/media.html')
     49    return Response(
     50        template.render(
     51            {'request': request,
     52             'media': media}))
  • mediagoblin/views.py

    diff --git a/mediagoblin/views.py b/mediagoblin/views.py
    index 3728d4a..f4c0598 100644
    a b import datetime  
    1818
    1919from webob import Response, exc
    2020import wtforms
    21 
     21from mongokit import ObjectId
    2222from mediagoblin import models
    2323
    2424def root_view(request):
    2525    media_entries = request.db.MediaEntry.find(
    2626        {u'state': u'processed'})
    27 
     27   
    2828    template = request.template_env.get_template(
    2929        'mediagoblin/root.html')
    3030    return Response(