Changeset 1172 in main


Ignore:
Timestamp:
06/05/12 11:54:57 (7 years ago)
Author:
pcosquer
Message:

publication: adds the view of a pulished object
TODO:

  • add button to publish/unpublish an object
  • documentation
  • tests
Location:
trunk/openPLM
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/views/main.py

    r1171 r1172  
    5858from django.contrib.auth.forms import PasswordChangeForm 
    5959from django.contrib.auth.models import User 
     60from django.contrib.auth.views import redirect_to_login 
    6061from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger 
    6162from django.db.models import F 
    6263from django.forms import HiddenInput 
    63 from django.http import HttpResponseRedirect, HttpResponse, \ 
     64from django.http import HttpResponseRedirect, HttpResponse, Http404, \ 
    6465                        HttpResponsePermanentRedirect, HttpResponseForbidden 
    6566from django.shortcuts import render_to_response 
     
    7879import openPLM.plmapp.forms as forms 
    7980from openPLM.plmapp.archive import generate_archive 
    80 from openPLM.plmapp.base_views import get_obj, get_obj_from_form, \ 
     81from openPLM.plmapp.base_views import init_ctx, get_obj, get_obj_from_form, \ 
    8182    get_obj_by_id, handle_errors, get_generic_data, get_navigate_data, \ 
    8283    get_creation_view, register_creation_view 
     
    15521553    ctrl = get_obj_by_id(int(doc_file.document.id), request.user) 
    15531554    ctrl.check_readable() 
     1555    return serve(ctrl, doc_file, filename) 
     1556 
     1557def public_download(request, docfile_id, filename=""): 
     1558    """ 
     1559    View to download a published document file. 
     1560     
     1561    :param request: :class:`django.http.QueryDict` 
     1562    :param docfile_id: :attr:`.DocumentFile.id` 
     1563    :type docfile_id: str 
     1564    :return: a :class:`django.http.HttpResponse` 
     1565    """ 
     1566    doc_file = models.DocumentFile.objects.get(id=docfile_id) 
     1567    ctrl = get_obj_by_id(int(doc_file.document.id), request.user) 
     1568    if not ctrl.published: 
     1569        return HttpResponseForbidden() 
     1570    return serve(ctrl, doc_file, filename) 
     1571 
     1572 
     1573def serve(ctrl, doc_file, filename): 
    15541574    name = doc_file.filename.encode("utf-8", "ignore") 
    15551575    mimetype = guess_type(name, False)[0] 
     
    19872007    return r2r("browse.html", ctx, request) 
    19882008 
     2009def public(request, obj_type, obj_ref, obj_revi): 
     2010    """ 
     2011    .. versionadded:: 1.1 
     2012 
     2013    Public view of the given object, this view is accessible to anonymous 
     2014    users. The object must be a published part or document. 
     2015 
     2016    Redirects to the login page if the object is not published and the user 
     2017    is not authenticated. 
     2018 
     2019    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/public/` 
     2020 
     2021    .. include:: views_params.txt  
     2022 
     2023    **Template:** 
     2024     
     2025    :file:`public.html` 
     2026 
     2027    **Context:** 
     2028 
     2029    ``RequestContext`` 
     2030 
     2031    ``obj`` 
     2032        the controller 
     2033     
     2034    ``object_attributes`` 
     2035        list of tuples(verbose attribute name, value) 
     2036 
     2037    ``revisions`` 
     2038        list of published related revisions 
     2039 
     2040    ``attached`` 
     2041        list of published attached documents and parts 
     2042    """ 
     2043    # do not call get_generic_data to avoid the overhead due 
     2044    # to a possible search and the update of the navigation history 
     2045    obj = get_obj(obj_type, obj_ref, obj_revi, request.user) 
     2046    if not (obj.is_part or obj.is_document): 
     2047        raise Http404 
     2048    if not obj.published and request.user.is_anonymous(): 
     2049        return redirect_to_login(request.get_full_path()) 
     2050    ctx = init_ctx(obj_type, obj_ref, obj_revi) 
     2051    attrs = obj.published_attributes 
     2052    object_attributes = [] 
     2053    for attr in attrs: 
     2054        item = obj.get_verbose_name(attr) 
     2055        object_attributes.append((item, getattr(obj, attr))) 
     2056    object_attributes.insert(4, (obj.get_verbose_name("state"), obj.state.name)) 
     2057    revisions = [rev for rev in obj.get_all_revisions() if rev.published] 
     2058    if obj.is_part: 
     2059        attached = [d.document for d in obj.get_attached_documents() 
     2060            if d.document.published] 
     2061    else: 
     2062        attached = [d.part for d in obj.get_attached_parts() if d.part.published] 
     2063 
     2064    ctx.update({ 
     2065        # a published object is always readable 
     2066        'is_readable' : True, 
     2067        # disable the menu and the navigation_history 
     2068        'object_menu' : [], 
     2069        'navigation_history' : [], 
     2070        'obj' : obj, 
     2071        'object_attributes': object_attributes, 
     2072        'revisions' : revisions, 
     2073        'attached' : attached, 
     2074    }) 
     2075 
     2076    return r2r("public.html", ctx, request) 
     2077 
  • trunk/openPLM/templates/blocks/user.html

    r1094 r1172  
    33 
    44{% get_current_language as LANGUAGE_CODE %} 
    5 <a href="/user/{{user|urlencode }}/">{{user.get_full_name}}</a> | {% now "D j N Y, G:i"%} 
     5 
     6{% if user.is_authenticated %} 
     7    <a href="/user/{{user|urlencode }}/">{{user.get_full_name}}</a> | {% now "D j N Y, G:i"%} 
     8{% else %} 
     9    <a href="{% url login %}?next={{request.get_full_path|urlencode }}">{% trans "Log in" %}</a> 
     10{% endif %} 
     11 
    612<form id="SetLangForm" action="/i18n/setlang/" method="post"> 
    713    <ul> 
     
    2127    </ul> 
    2228</form> 
    23 <a class="{{"Button small"|button}}"  href="/logout/"> 
    24     <span class="ui-button-text">{% trans "EXIT" %}</span> 
    25 </a> 
    2629 
     30{% if request.user.is_authenticated %} 
     31    <a class="{{"Button small"|button}}"  href="/logout/"> 
     32        <span class="ui-button-text">{% trans "EXIT" %}</span> 
     33    </a> 
     34{% endif %} 
     35 
  • trunk/openPLM/urls.py

    r1149 r1172  
    7979 
    8080    (r'^(?:home/)?$', display_home_page), 
    81     (r'^accounts/?$', login, {'template_name': 'login.html', 'redirect_field_name': 'next'}), 
     81    (r'^accounts/?$', login, {'template_name': 'login.html', 'redirect_field_name': 'next'}, 
     82        "login"), 
    8283    (r'^(?:accounts/)?login/', login, {'template_name': 'login.html', 'redirect_field_name': 'next'}), 
    8384    (r'^(?:accounts/)?logout/', logout, {'next_page': '/login/', }), 
     
    132133    (r'navigate/$', navigate), 
    133134    (r'(?:files/|doc-cad/)?archive/$', download_archive), 
     135    (r'public/$', public), 
    134136) 
    135137 
     
    171173    (r'^file/(?P<docfile_id>\d+)/$', download), 
    172174    (r'^file/(?P<docfile_id>\d+)/(?P<filename>.*)$', download), 
     175    (r'^file/public/(?P<docfile_id>\d+)/$', public_download), 
     176    (r'^file/public/(?P<docfile_id>\d+)/(?P<filename>.*)$', public_download), 
    173177) 
    174178 
Note: See TracChangeset for help on using the changeset viewer.