Changeset 297 in main


Ignore:
Timestamp:
09/16/11 14:37:41 (8 years ago)
Author:
pcosquer
Message:

clean up

File:
1 edited

Legend:

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

    r295 r297  
    4646""" 
    4747 
    48 import os 
    4948import re 
    5049import datetime 
    51 import pygraphviz as pgv 
    5250from operator import attrgetter 
    5351from mimetypes import guess_type 
     
    5654from django.conf import settings 
    5755from django.shortcuts import render_to_response, get_object_or_404 
    58 from django.db.models import Q 
    59 from django.http import HttpResponseRedirect, QueryDict, HttpResponse,\ 
     56from django.http import HttpResponseRedirect, HttpResponse,\ 
    6057                        HttpResponsePermanentRedirect, HttpResponseForbidden, \ 
    6158                        HttpResponseServerError, Http404 
    62 from django.contrib import auth 
    6359from django.contrib.auth.decorators import login_required 
    6460from django.contrib.auth.models import User 
     
    7268from openPLM.plmapp.exceptions import ControllerError 
    7369import openPLM.plmapp.models as models 
    74 from openPLM.plmapp.controllers import PLMObjectController, get_controller, DocumentController, PartController 
     70from openPLM.plmapp.controllers import PLMObjectController, get_controller, DocumentController 
    7571from openPLM.plmapp.user_controller import UserController 
    7672from openPLM.plmapp.utils import level_to_sign_str, get_next_revision 
    7773from openPLM.plmapp.forms import * 
    78 from openPLM.plmapp.api import get_obj_by_id 
    7974from openPLM.plmapp.navigate import NavigationGraph 
    8075 
     
    145140 
    146141########################################################################################## 
    147 def init_context_dict(init_type_value, init_reference_value, init_revision_value): 
     142def init_context_dict(init_type_, init_reference, init_revision): 
    148143    """ 
    149144    Initiate the context dictionnary we used to transfer parameters to html pages. 
     
    162157         'object_type': 'BiosOs'} 
    163158     
    164     :param init_type_value: type of the object 
    165     :type init_type_value: str 
    166     :param init_reference_value: reference of the object 
    167     :type init_reference_value: str 
    168     :param init_revision_value: revision of the object 
    169     :type init_revision_value: str 
     159    :param init_type_: type of the object 
     160    :type init_type_: str 
     161    :param init_reference: reference of the object 
     162    :type init_reference: str 
     163    :param init_revision: revision of the object 
     164    :type init_revision: str 
    170165    :return: a dictionnary 
    171166    """ 
     
    173168    return { 
    174169        'current_date': now, 
    175         'object_reference': init_reference_value, 
    176         'object_revision': init_revision_value, 
    177         'object_type': init_type_value, 
     170        'object_reference': init_reference, 
     171        'object_revision': init_revision, 
     172        'object_type': init_type_, 
    178173        'THUMBNAILS_URL' : settings.THUMBNAILS_URL, 
    179174        'LANGUAGES' : settings.LANGUAGES, 
     
    184179########################################################################################## 
    185180 
    186 def display_global_page(request_dict, type_value='-', reference_value='-', revision_value='-'): 
     181def display_global_page(request_dict, type_='-', reference='-', revision='-'): 
    187182    """ 
    188183    Get a request and return a controller, a context dictionnary with elements common to all pages 
     
    191186     
    192187    :param request_dict: :class:`django.http.QueryDict` 
    193     :param type_value: :attr:`.PLMObject.type` 
    194     :type type_value: str 
    195     :param reference_value: :attr:`.PLMObject.reference` 
    196     :type reference_value: str 
    197     :param revision_value: :attr:`.PLMObject.revision` 
    198     :type revision_value: str 
     188    :param type_: :attr:`.PLMObject.type` 
     189    :type type_: str 
     190    :param reference: :attr:`.PLMObject.reference` 
     191    :type reference: str 
     192    :param revision: :attr:`.PLMObject.revision` 
     193    :type revision: str 
    199194    :return: a :class:`PLMObjectController` or a :class:`UserController` 
    200195    :return: context_dict 
     
    203198    :type request_dict.session: dic 
    204199    """ 
    205     context_dict = init_context_dict(type_value, reference_value, revision_value) 
     200    context_dict = init_context_dict(type_, reference, revision) 
    206201    # This case happens when we create an object (and therefore can't get a controller) 
    207     if type_value=='-' and reference_value=='-' and revision_value=='-': 
     202    if type_ == reference == revision == '-': 
    208203        selected_object = request_dict.user 
    209204    else: 
    210         selected_object = get_obj(type_value, reference_value, revision_value, request_dict.user) 
     205        selected_object = get_obj(type_, reference, revision, request_dict.user) 
    211206    # Defines a variable for background color selection 
    212207    if isinstance(selected_object, UserController): 
     
    14081403regex_pattern = re.compile(r'top:(\d+)px;left:(\d+)px;width:(\d+)px;height:(\d+)px;') 
    14091404 
    1410 @handle_errors 
    1411 def navigate(request, obj_type, obj_ref, obj_revi, navigate_bool): 
     1405 
     1406def get_navigate_data(request, obj_type, obj_ref, obj_revi): 
     1407 
     1408    pass 
     1409 
     1410@handle_errors 
     1411def navigate(request, obj_type, obj_ref, obj_revi): 
    14121412    """ 
    14131413    Manage html page which displays a graphical picture the different links 
     
    14151415    This function uses Graphviz (http://graphviz.org/). 
    14161416    Some filters let user defines which type of links he/she wants to display. 
    1417     It computes a context dictionnary based on 
     1417    It computes a context dictionary based on 
    14181418     
    14191419    :param request: :class:`django.http.QueryDict` 
     
    14291429    request.session.update(request_dict) 
    14301430    if isinstance(obj, UserController): 
    1431         FilterObjectFormFunction = FilterObjectForm4User 
     1431        filterForm = FilterObjectForm4User 
    14321432    elif isinstance(obj, DocumentController): 
    1433         FilterObjectFormFunction = FilterObjectForm4Doc 
    1434     else: 
    1435         FilterObjectFormFunction = FilterObjectForm4Part 
    1436     session_bool = False 
    1437     for field in FilterObjectFormFunction.base_fields.keys(): 
    1438         session_bool = session_bool or request.session.get(field) 
     1433        filterForm = FilterObjectForm4Doc 
     1434    else: 
     1435        filterForm = FilterObjectForm4Part 
     1436    has_session = any(field in request.session for field in filterForm.base_fields) 
    14391437    if request.method == 'POST' and request.POST: 
    1440         form = FilterObjectFormFunction(request.POST) 
     1438        form = filterForm(request.POST) 
    14411439        if form.is_valid(): 
    14421440            request.session.update(form.cleaned_data) 
    1443     elif session_bool: 
    1444         form = FilterObjectFormFunction(request.session) 
    1445     else: 
    1446         initial = dict((k, bool(v.initial)) for k,v in FilterObjectFormFunction.base_fields.items()) 
    1447         form = FilterObjectFormFunction(initial) 
     1441    elif has_session: 
     1442        form = filterForm(request.session) 
     1443    else: 
     1444        initial = dict((k, v.initial) for k, v in filterForm.base_fields.items()) 
     1445        form = filterForm(initial) 
    14481446        request.session.update(initial) 
    14491447    if not form.is_valid(): 
     
    14641462                         'x_img_position': x_img_position_corrected, 
    14651463                         'y_img_position': y_img_position_corrected, 
    1466                          'navigate_bool': navigate_bool}) 
     1464                         'navigate_bool': True}) 
    14671465    return render_to_response('Navigate.htm', context_dict,  
    14681466                              context_instance=RequestContext(request)) 
     
    15381536 
    15391537 
     1538@login_required 
     1539def ajax_show_docs(request, obj_type, obj_ref, obj_revi): 
     1540    """ 
     1541    Ajax view to get files and thumbnails of a document. 
     1542 
     1543    :param request: :class:`django.http.QueryDict` 
     1544    :param obj_type: :attr:`.PLMObject.type` 
     1545    :type obj_type: str 
     1546    :param obj_ref: :attr:`.PLMObject.reference` 
     1547    :type obj_ref: str 
     1548    :param obj_revi: :attr:`.PLMObject.revision` 
     1549    :type obj_revi: str 
     1550    """ 
     1551    obj = get_obj(obj_type, obj_ref, obj_revi, request.user) 
     1552    files = [] 
     1553    doc = "|".join((obj_type, obj_ref, obj_revi)) 
     1554    for f in obj.files: 
     1555        if f.thumbnail: 
     1556            img = "/media/thumbnails/%s" % f.thumbnail  
     1557        else: 
     1558            img = "/media/img/image-missing.png" 
     1559        files.append((f.filename, "/file/%d/" % f.id, img)) 
     1560    json = JSONEncoder().encode(dict(files=files, doc=doc)) 
     1561    return HttpResponse(json, mimetype='application/json') 
     1562 
     1563 
Note: See TracChangeset for help on using the changeset viewer.