Changeset 315 in main


Ignore:
Timestamp:
09/22/11 09:41:53 (8 years ago)
Author:
pcosquer
Message:

clean up urls

Location:
trunk/openPLM
Files:
2 edited

Legend:

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

    r313 r315  
    10151015############################################################################################# 
    10161016@handle_errors 
    1017 def modify_user(request, obj_type, obj_ref, obj_revi): 
     1017def modify_user(request, obj_ref): 
    10181018    """ 
    10191019    Manage html page for the modification of the selected :class:`~django.contrib.auth.models.User`. 
     
    10291029    :return: a :class:`django.http.HttpResponse` 
    10301030    """ 
    1031     obj, ctx, request_dict = get_generic_data(request, obj_type, obj_ref, obj_revi) 
    1032     current_object = get_obj(obj_type, obj_ref, obj_revi, request.user) 
     1031    obj, ctx, request_dict = get_generic_data(request, "User", obj_ref) 
    10331032    class_for_div="ActiveBox4User" 
    10341033    if request.method == 'POST': 
     
    10361035            modification_form = OpenPLMUserChangeForm(request.POST) 
    10371036            if modification_form.is_valid(): 
    1038                 current_object.update_from_form(modification_form) 
    1039                 return HttpResponseRedirect("/user/%s/" % current_object.username) 
     1037                obj.cupdate_from_form(modification_form) 
     1038                return HttpResponseRedirect("/user/%s/" % obj.username) 
    10401039            else: 
    10411040                modification_form = OpenPLMUserChangeForm(request.POST) 
    10421041    else: 
    1043         modification_form = OpenPLMUserChangeForm(instance=current_object.object) 
     1042        modification_form = OpenPLMUserChangeForm(instance=obj.object) 
    10441043    request.session.update(request_dict) 
    10451044    ctx.update({'class4div': class_for_div, 'modification_form': modification_form}) 
     
    10481047########################################################################################## 
    10491048@handle_errors 
    1050 def change_user_password(request, obj_type, obj_ref, obj_revi): 
     1049def change_user_password(request, obj_ref): 
    10511050    """ 
    10521051    Manage html page for the modification of the selected :class:`~django.contrib.auth.models.User` password. 
     
    10641063    if request.user.username=='test': 
    10651064        return HttpResponseRedirect("/user/%s/attributes/" % request.user) 
    1066     current_object, ctx, request_dict = get_generic_data(request, obj_type, obj_ref, obj_revi) 
     1065    obj, ctx, request_dict = get_generic_data(request, "User", obj_ref) 
    10671066    class_for_div="ActiveBox4User" 
    10681067    if request.method == 'POST': 
    10691068        if request.POST: 
    1070             modification_form = PasswordChangeForm(current_object, request.POST) 
     1069            modification_form = PasswordChangeForm(obj, request.POST) 
    10711070            if modification_form.is_valid(): 
    1072                 current_object.set_password(modification_form.cleaned_data['new_password2']) 
    1073                 current_object.save() 
    1074                 return HttpResponseRedirect("/user/%s/" % current_object.username) 
     1071                obj.set_password(modification_form.cleaned_data['new_password2']) 
     1072                obj.save() 
     1073                return HttpResponseRedirect("/user/%s/" % obj.username) 
    10751074            else: 
    1076                 #assert False 
    1077                 modification_form = PasswordChangeForm(current_object, request.POST) 
    1078     else: 
    1079         modification_form = PasswordChangeForm(current_object) 
     1075                modification_form = PasswordChangeForm(obj, request.POST) 
     1076    else: 
     1077        modification_form = PasswordChangeForm(obj) 
    10801078    request.session.update(request_dict) 
    10811079    ctx.update({'class4div': class_for_div, 'modification_form': modification_form}) 
     
    11101108############################################################################################# 
    11111109@handle_errors 
    1112 def display_delegation(request, obj_type, obj_ref, obj_revi): 
     1110def display_delegation(request, obj_ref): 
    11131111    """ 
    11141112    Manage html page which displays the delegations of (:class:`DelegationLink` with) the selected :class:`~django.contrib.auth.models.User`. 
     
    11241122    :return: a :class:`django.http.HttpResponse` 
    11251123    """ 
    1126     obj, ctx, request_dict = get_generic_data(request, obj_type, obj_ref, obj_revi) 
     1124    obj, ctx, request_dict = get_generic_data(request, "User", obj_ref) 
    11271125     
    11281126    if not hasattr(obj, "get_user_delegation_links"): 
     
    11401138##########################################################################################     
    11411139@handle_errors 
    1142 def delegate(request, obj_type, obj_ref, obj_revi, role, sign_level): 
     1140def delegate(request, obj_ref, role, sign_level): 
    11431141    """ 
    11441142    Manage html page for delegations modification of (:class:`DelegationLink` with) the selected :class:`~django.contrib.auth.models.User`. 
     
    11581156    :return: a :class:`django.http.HttpResponse` 
    11591157    """ 
    1160     obj, ctx, request_dict = get_generic_data(request, obj_type, obj_ref, obj_revi) 
     1158    obj, ctx, request_dict = get_generic_data(request, "User", obj_ref) 
    11611159     
    11621160    if request.method == "POST": 
     
    11931191##########################################################################################     
    11941192@handle_errors 
    1195 def stop_delegate(request, obj_type, obj_ref, obj_revi, role, sign_level): 
     1193def stop_delegate(request, obj_ref, role, sign_level): 
    11961194    """ 
    11971195    Manage html page to stop delegations of (:class:`DelegationLink` with) the selected :class:`~django.contrib.auth.models.User`. 
     
    12111209    :return: a :class:`django.http.HttpResponse` 
    12121210    """ 
    1213     obj, ctx, request_dict = get_generic_data(request, obj_type, obj_ref, obj_revi) 
     1211    obj, ctx, request_dict = get_generic_data(request, "User", obj_ref) 
    12141212     
    12151213    if request.method == "POST": 
  • trunk/openPLM/urls.py

    r311 r315  
    3232        __import__("%s.models" % app, globals(), locals(), [], -1) 
    3333 
    34 from django.conf.urls.defaults import * 
     34from django.conf.urls.defaults import include, patterns 
    3535from openPLM.plmapp.views import * 
    3636import openPLM.plmapp.api as api 
     
    5151            pass 
    5252 
    53 object_url = r'^object/(?P<obj_type>\w+)/(?P<obj_ref>%(x)s)/(?P<obj_revi>%(x)s)/' % {'x' : r'[^/?#\t\r\v\f]+'} 
     53def patterns2(view_prefix, url_prefix, *urls): 
     54    urls2 = [] 
     55    for u in urls: 
     56        u2 = list(u) 
     57        u2[0] = url_prefix + u2[0] 
     58        urls2.append(tuple(u2)) 
     59    return patterns(view_prefix, *urls2) 
     60 
     61object_pattern = '(?P<obj_type>\w+)/(?P<obj_ref>%(x)s)/(?P<obj_revi>%(x)s)/' % {'x' : r'[^/?#\t\r\v\f]+'} 
     62 
     63object_url = r'^object/' + object_pattern 
    5464user_url = r'^user/(?P<obj_ref>[^/]+)/' 
    5565user_dict = {'obj_type':'User', 'obj_revi':'-'} 
     
    6373    (r'^home/', display_home_page), 
    6474    (r'^object/create/$', create_object), 
    65      
    66     (r'ajax/search/$', ajax_search_form), 
    67     (r'ajax/complete/(?P<obj_type>\w+)/(?P<field>\w+)/$', ajax_autocomplete), 
    68     (r'ajax/thumbnails/(?P<obj_type>\w+)/(?P<obj_ref>%(x)s)/(?P<obj_revi>%(x)s)/?$' % {'x' : r'[^/?#\t\r\v\f]+'}, ajax_thumbnails), 
    69     (r'ajax/navigate/(?P<obj_type>\w+)/(?P<obj_ref>%(x)s)/(?P<obj_revi>%(x)s)/?$' % {'x' : r'[^/?#\t\r\v\f]+'}, ajax_navigate), 
    70     (r'ajax/add_child/(?P<part_id>\d+)/?', ajax_add_child), 
    71     (r'ajax/can_add_child/(?P<part_id>\d+)/?', ajax_can_add_child), 
    72     (r'ajax/attach/(?P<plmobject_id>\d+)/?', ajax_attach), 
    73     (r'ajax/can_attach/(?P<plmobject_id>\d+)/?', ajax_can_attach), 
     75    ) 
    7476 
    75     (object_url + r'$', display_object), 
    76     (object_url + r'attributes/$', display_object_attributes), 
    77     (object_url + r'lifecycle/$', display_object_lifecycle), 
    78     (object_url + r'revisions/$', display_object_revisions), 
    79     (object_url + r'history/$', display_object_history), 
    80     (object_url + r'BOM-child/$', display_object_child), 
    81     (object_url + r'BOM-child/edit/$', edit_children), 
    82     (object_url + r'BOM-child/add/$', add_children), 
    83     (object_url + r'parents/$', display_object_parents), 
    84     (object_url + r'doc-cad/$', display_object_doc_cad), 
    85     (object_url + r'doc-cad/add/$', add_doc_cad), 
    86     (object_url + r'parts/$', display_related_part), 
    87     (object_url + r'parts/add/$', add_rel_part), 
    88     (object_url + r'files/$', display_files), 
    89     (object_url + r'files/add/$', add_file), 
    90     (object_url + r'files/checkin/(?P<file_id_value>[^/]+)/$', checkin_file), 
    91     (object_url + r'files/checkout/(?P<docfile_id>[^/]+)/$', checkout_file), 
    92     (object_url + r'modify/$', modify_object), 
    93     (object_url + r'management/$', display_management), 
    94     (object_url + r'management/add/$', add_management), 
    95     (object_url + r'management/replace/(?P<link_id>\d+)/$', replace_management), 
    96     (object_url + r'management/delete/$', delete_management), 
    97     (object_url + r'navigate/$', navigate), 
     77urlpatterns += patterns2('', 'ajax/',  
     78    (r'search/$', ajax_search_form), 
     79    (r'complete/(?P<obj_type>\w+)/(?P<field>\w+)/$', ajax_autocomplete), 
     80    (r'thumbnails/%s?$' % object_pattern, ajax_thumbnails), 
     81    (r'navigate/%s?$' % object_pattern, ajax_navigate), 
     82    (r'add_child/(?P<part_id>\d+)/?', ajax_add_child), 
     83    (r'can_add_child/(?P<part_id>\d+)/?', ajax_can_add_child), 
     84    (r'attach/(?P<plmobject_id>\d+)/?', ajax_attach), 
     85    (r'can_attach/(?P<plmobject_id>\d+)/?', ajax_can_attach), 
     86) 
    9887 
    99     (user_url + r'$', display_object, user_dict), 
    100     (user_url + r'attributes/$', display_object_attributes, user_dict), 
    101     (user_url + r'history/$', display_object_history, user_dict), 
    102     (user_url + r'parts-doc-cad/$', display_related_plmobject, user_dict), 
    103     (user_url + r'delegation/$', display_delegation, user_dict), 
    104     (user_url + r'delegation/delegate/(?P<role>[^/]+)/$', delegate,\ 
    105                     {'obj_type':'User', 'obj_revi':'-', 'sign_level':'none'}), 
    106     (user_url + r'delegation/delegate/(?P<role>[^/]+)/(?P<sign_level>\d+|all)/$', delegate,\ 
    107                     {'obj_type':'User', 'obj_revi':'-'}), 
    108     (user_url + r'delegation/stop_delegate/(?P<role>[^/]+)/$', stop_delegate,\ 
    109                     {'obj_type':'User', 'obj_revi':'-', 'sign_level':'none'}), 
    110     (user_url + r'delegation/stop_delegate/(?P<role>[^/]+)/(?P<sign_level>\d+|all)/$', stop_delegate,\ 
    111                     {'obj_type':'User', 'obj_revi':'-'}), 
    112     (user_url + r'modify/$', modify_user, user_dict), 
    113     (user_url + r'password/$', change_user_password, user_dict), 
    114     (user_url + r'navigate/$', navigate, user_dict), 
    115      
     88urlpatterns += patterns2('', object_url, 
     89    (r'$', display_object), 
     90    (r'attributes/$', display_object_attributes), 
     91    (r'lifecycle/$', display_object_lifecycle), 
     92    (r'revisions/$', display_object_revisions), 
     93    (r'history/$', display_object_history), 
     94    (r'BOM-child/$', display_object_child), 
     95    (r'BOM-child/edit/$', edit_children), 
     96    (r'BOM-child/add/$', add_children), 
     97    (r'parents/$', display_object_parents), 
     98    (r'doc-cad/$', display_object_doc_cad), 
     99    (r'doc-cad/add/$', add_doc_cad), 
     100    (r'parts/$', display_related_part), 
     101    (r'parts/add/$', add_rel_part), 
     102    (r'files/$', display_files), 
     103    (r'files/add/$', add_file), 
     104    (r'files/checkin/(?P<file_id_value>[^/]+)/$', checkin_file), 
     105    (r'files/checkout/(?P<docfile_id>[^/]+)/$', checkout_file), 
     106    (r'modify/$', modify_object), 
     107    (r'management/$', display_management), 
     108    (r'management/add/$', add_management), 
     109    (r'management/replace/(?P<link_id>\d+)/$', replace_management), 
     110    (r'management/delete/$', delete_management), 
     111    (r'navigate/$', navigate), 
     112) 
     113 
     114 
     115urlpatterns += patterns2('', user_url,  
     116    (r'$', display_object, user_dict), 
     117    (r'attributes/$', display_object_attributes, user_dict), 
     118    (r'history/$', display_object_history, user_dict), 
     119    (r'parts-doc-cad/$', display_related_plmobject, user_dict), 
     120    (r'delegation/$', display_delegation), 
     121    (r'delegation/delegate/(?P<role>[^/]+)/$', delegate, 
     122                    {'sign_level':'none'}), 
     123    (r'delegation/delegate/(?P<role>[^/]+)/(?P<sign_level>\d+|all)/$', delegate), 
     124    (r'delegation/stop_delegate/(?P<role>[^/]+)/$', stop_delegate,\ 
     125                    {'sign_level':'none'}), 
     126    (r'delegation/stop_delegate/(?P<role>[^/]+)/(?P<sign_level>\d+|all)/$', 
     127                    stop_delegate), 
     128    (r'modify/$', modify_user), 
     129    (r'password/$', change_user_password), 
     130    (r'navigate/$', navigate, user_dict), 
     131) 
     132 
     133urlpatterns += patterns('', 
    116134        # In order to take into account the css file 
    117     (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root' : 'media/'}),     
     135    (r'^media/(?P<path>.*)$', 'django.views.static.serve', 
     136        {'document_root' : 'media/'}),     
    118137    (r'^file/(?P<docfile_id>\d+)/$', download), 
    119138    (r'^file/(?P<docfile_id>\d+)/(?P<filename>.*)$', download), 
    120     #(r'^docs/(?P<path>.*)$', 'django.views.static.serve', {'document_root' : 'docs/'}),     
    121  
    122139) 
    123140 
    124141# urls related to the api 
    125142api_url = r'^api/object/(?P<doc_id>\d+)/' 
    126 urlpatterns += patterns('', 
    127     (r'^api/login/', api.api_login), 
    128     (r'^api/needlogin/', api.need_login), 
    129     (r'^api/testlogin/', api.test_login), 
    130     (r'^api/types/$', api.get_all_types), 
    131     (r'^api/parts/$', api.get_all_parts), 
    132     (r'^api/doc(?:ument)?s/$', api.get_all_docs), 
    133     (r'^api/search/$', api.search), 
    134     (r'^api/search/(?P<editable_only>true|false)/$', api.search), 
    135     (r'^api/search/(?P<editable_only>true|false)/(?P<with_file_only>true|false)/$', 
     143urlpatterns += patterns('api/', 
     144    (r'^login/', api.api_login), 
     145    (r'^needlogin/', api.need_login), 
     146    (r'^testlogin/', api.test_login), 
     147    (r'^types/$', api.get_all_types), 
     148    (r'^parts/$', api.get_all_parts), 
     149    (r'^doc(?:ument)?s/$', api.get_all_docs), 
     150    (r'^search/$', api.search), 
     151    (r'^search/(?P<editable_only>true|false)/$', api.search), 
     152    (r'^search/(?P<editable_only>true|false)/(?P<with_file_only>true|false)/$', 
    136153     api.search), 
    137     (r'^api/create/$', api.create), 
    138     (r'^api/search_fields/(?P<typename>[\w_]+)/$', api.get_search_fields), 
    139     (r'^api/creation_fields/(?P<typename>[\w_]+)/$', api.get_creation_fields), 
    140     (api_url + r'files/$', api.get_files), 
    141     (api_url + r'files/(?P<all_files>all)/$', api.get_files), 
    142     (api_url + r'revise/$', api.revise), 
    143     (api_url + r'add_file/$', api.add_file), 
    144     (api_url + r'attach_to_part/(?P<part_id>\d+)/$', api.attach_to_part), 
    145     (api_url + r'next_?revision/$', api.next_revision), 
    146     (api_url + r'is_?revisable/$', api.is_revisable), 
    147     (api_url + r'(?:lock|checkout)/(?P<df_id>\d+)/$', api.check_out), 
    148     (api_url + r'unlock/(?P<df_id>\d+)/$', api.unlock), 
    149     (api_url + r'is_?locked/(?P<df_id>\d+)/$', api.is_locked), 
    150     (api_url + r'checkin/(?P<df_id>\d+)/$', api.check_in), 
    151     (api_url + r'add_thumbnail/(?P<df_id>\d+)/$', api.add_thumbnail), 
     154    (r'^create/$', api.create), 
     155    (r'^search_fields/(?P<typename>[\w_]+)/$', api.get_search_fields), 
     156    (r'^creation_fields/(?P<typename>[\w_]+)/$', api.get_creation_fields), 
     157    ) 
     158 
     159urlpatterns += patterns(api_url, 
     160    (r'files/$', api.get_files), 
     161    (r'files/(?P<all_files>all)/$', api.get_files), 
     162    (r'revise/$', api.revise), 
     163    (r'add_file/$', api.add_file), 
     164    (r'attach_to_part/(?P<part_id>\d+)/$', api.attach_to_part), 
     165    (r'next_?revision/$', api.next_revision), 
     166    (r'is_?revisable/$', api.is_revisable), 
     167    (r'(?:lock|checkout)/(?P<df_id>\d+)/$', api.check_out), 
     168    (r'unlock/(?P<df_id>\d+)/$', api.unlock), 
     169    (r'is_?locked/(?P<df_id>\d+)/$', api.is_locked), 
     170    (r'checkin/(?P<df_id>\d+)/$', api.check_in), 
     171    (r'add_thumbnail/(?P<df_id>\d+)/$', api.add_thumbnail), 
    152172) 
    153173 
Note: See TracChangeset for help on using the changeset viewer.