source: main/trunk/openPLM/urls.py @ 466

Revision 466, 7.7 KB checked in by pcosquer, 8 years ago (diff)

fix #43

Line 
1############################################################################
2# openPLM - open source PLM
3# Copyright 2010 Philippe Joulaud, Pierre Cosquer
4#
5# This file is part of openPLM.
6#
7#    openPLM is free software: you can redistribute it and/or modify
8#    it under the terms of the GNU General Public License as published by
9#    the Free Software Foundation, either version 3 of the License, or
10#    (at your option) any later version.
11#
12#    openPLM is distributed in the hope that it will be useful,
13#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#    GNU General Public License for more details.
16#
17#    You should have received a copy of the GNU General Public License
18#    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
19#
20# Contact :
21#    Philippe Joulaud : ninoo.fr@gmail.com
22#    Pierre Cosquer : pierre.cosquer@insa-rennes.fr
23################################################################################
24
25import sys
26
27from django.conf import settings
28
29# import custom application models
30for app in settings.INSTALLED_APPS:
31    if app.startswith("openPLM"):
32        __import__("%s.models" % app, globals(), locals(), [], -1)
33
34from django.conf.urls.defaults import include, patterns
35from openPLM.plmapp.views import *
36import openPLM.plmapp.views.api as api
37from django.contrib.auth.views import login, logout
38from openPLM.plmapp.csvimport import IMPORTERS
39
40from django.contrib import admin
41admin.autodiscover()
42
43# just a hack to prevent a KeyError
44from haystack.models import SearchResult
45def get_state(self):
46    ret_dict = self.__dict__.copy()
47    if 'searchsite' in ret_dict:
48        del(ret_dict['searchsite'])
49    del(ret_dict['log'])
50    return ret_dict
51SearchResult.__getstate__ = get_state
52
53
54urlpatterns = patterns('')
55# add custom application urls
56for app in settings.INSTALLED_APPS:
57    if app.startswith("openPLM"):
58        try:
59            __import__("%s.urls" % app, globals(), locals(), [], -1)
60            mod_patterns = getattr(sys.modules["%s.urls" % app], "urlpatterns")
61            urlpatterns += mod_patterns
62        except ImportError:
63            pass
64
65def patterns2(view_prefix, url_prefix, *urls):
66    urls2 = []
67    for u in urls:
68        u2 = list(u)
69        u2[0] = url_prefix + u2[0]
70        urls2.append(tuple(u2))
71    return patterns(view_prefix, *urls2)
72
73object_pattern = '(?P<obj_type>\w+)/(?P<obj_ref>%(x)s)/(?P<obj_revi>%(x)s)/' % {'x' : r'[^/?#\t\r\v\f]+'}
74
75object_url = r'^object/' + object_pattern
76user_url = r'^user/(?P<obj_ref>[^/]+)/'
77group_url = r'^group/(?P<obj_ref>[^/]+)/'
78user_dict = {'obj_type':'User', 'obj_revi':'-'}
79group_dict = {'obj_type':'Group', 'obj_revi':'-'}
80
81import_url = r'^import/(?P<target>%s)/' % ("|".join(IMPORTERS.keys()))
82
83urlpatterns += patterns('',
84    (r'^admin/', include(admin.site.urls)),
85    (r'^i18n/', include('django.conf.urls.i18n')),
86
87    (r'^(?:home/)?$', display_home_page),
88    (r'^accounts/?$', login, {'template_name': 'DisplayLoginPage.htm', 'redirect_field_name': 'next'}),
89    (r'^(?:accounts/)?login/', login, {'template_name': 'DisplayLoginPage.htm', 'redirect_field_name': 'next'}),
90    (r'^(?:accounts/)?logout/', logout, {'next_page': '/login/', }),
91    (r'^object/create/$', create_object),
92    (r'^comments/', include('django.contrib.comments.urls')),
93    (import_url + '$', import_csv_init),
94    (import_url + '(?P<filename>[\w]+)/(?P<encoding>[\w]+)/$',
95        import_csv_apply),
96    ('^import/done/$', import_csv_done),
97    )
98
99urlpatterns += patterns2('', 'ajax/',
100    (r'search/$', ajax_search_form),
101    (r'complete/(?P<obj_type>\w+)/(?P<field>\w+)/$', ajax_autocomplete),
102    (r'thumbnails/%s?$' % object_pattern, ajax_thumbnails),
103    (r'navigate/%s?$' % object_pattern, ajax_navigate),
104    (r'add_child/(?P<part_id>\d+)/?', ajax_add_child),
105    (r'can_add_child/(?P<part_id>\d+)/?', ajax_can_add_child),
106    (r'attach/(?P<plmobject_id>\d+)/?', ajax_attach),
107    (r'can_attach/(?P<plmobject_id>\d+)/?', ajax_can_attach),
108)
109
110urlpatterns += patterns2('', object_url,
111    (r'$', display_object),
112    (r'attributes/$', display_object_attributes),
113    (r'lifecycle/$', display_object_lifecycle),
114    (r'revisions/$', display_object_revisions),
115    (r'history/$', display_object_history),
116    (r'BOM-child/$', display_object_child),
117    (r'BOM-child/edit/$', edit_children),
118    (r'BOM-child/add/$', add_children),
119    (r'parents/$', display_object_parents),
120    (r'doc-cad/$', display_object_doc_cad),
121    (r'doc-cad/add/$', add_doc_cad),
122    (r'parts/$', display_related_part),
123    (r'parts/add/$', add_rel_part),
124    (r'files/$', display_files),
125    (r'files/add/$', add_file),
126    (r'files/checkin/(?P<file_id_value>[^/]+)/$', checkin_file),
127    (r'files/checkout/(?P<docfile_id>[^/]+)/$', checkout_file),
128    (r'modify/$', modify_object),
129    (r'management/$', display_management),
130    (r'management/add/$', add_management),
131    (r'management/replace/(?P<link_id>\d+)/$', replace_management),
132    (r'management/delete/$', delete_management),
133    (r'navigate/$', navigate),
134)
135
136
137urlpatterns += patterns2('', user_url,
138    (r'$', display_object, user_dict),
139    (r'attributes/$', display_object_attributes, user_dict),
140    (r'history/$', display_object_history, user_dict),
141    (r'parts-doc-cad/$', display_related_plmobject, user_dict),
142    (r'delegation/$', display_delegation),
143    (r'delegation/sponsor/$', sponsor),
144    (r'delegation/delegate/(?P<role>[^/]+)/$', delegate,
145                    {'sign_level':'none'}),
146    (r'delegation/delegate/(?P<role>[^/]+)/(?P<sign_level>\d+|all)/$', delegate),
147    (r'modify/$', modify_user),
148    (r'password/$', change_user_password),
149    (r'navigate/$', navigate, user_dict),
150    (r'groups/$', display_groups),
151)
152
153urlpatterns += patterns2('', group_url,
154    (r'$', display_object, group_dict),
155    (r'attributes/$', display_object_attributes, group_dict),
156    (r'history/$', display_object_history, group_dict),
157    (r'objects/$', display_plmobjects),
158    (r'users/$', display_users),
159    (r'users/add/$', group_add_user),
160    (r'users/join/$', group_ask_to_join),
161    (r'invitation/accept/(?P<token>\d+)/$', accept_invitation),
162    (r'invitation/refuse/(?P<token>\d+)/$', refuse_invitation),
163    #(r'navigate/$', navigate, group_dict),
164)
165urlpatterns += patterns('',
166        # In order to take into account the css file
167    (r'^media/(?P<path>.*)$', 'django.views.static.serve',
168        {'document_root' : 'media/'}),   
169    (r'^file/(?P<docfile_id>\d+)/$', download),
170    (r'^file/(?P<docfile_id>\d+)/(?P<filename>.*)$', download),
171)
172
173# urls related to the api
174api_url = r'^api/object/(?P<doc_id>\d+)/'
175urlpatterns += patterns2('', '^api/',
176    (r'login/', api.api_login),
177    (r'needlogin/', api.need_login),
178    (r'testlogin/', api.test_login),
179    (r'types/$', api.get_all_types),
180    (r'parts/$', api.get_all_parts),
181    (r'doc(?:ument)?s/$', api.get_all_docs),
182    (r'search/$', api.search),
183    (r'search/(?P<editable_only>true|false)/$', api.search),
184    (r'search/(?P<editable_only>true|false)/(?P<with_file_only>true|false)/$',
185     api.search),
186    (r'create/$', api.create),
187    (r'search_fields/(?P<typename>[\w_]+)/$', api.get_search_fields),
188    (r'creation_fields/(?P<typename>[\w_]+)/$', api.get_creation_fields),
189    )
190
191urlpatterns += patterns2('', api_url,
192    (r'files/$', api.get_files),
193    (r'files/(?P<all_files>all)/$', api.get_files),
194    (r'revise/$', api.revise),
195    (r'add_file/$', api.add_file),
196    (r'attach_to_part/(?P<part_id>\d+)/$', api.attach_to_part),
197    (r'next_?revision/$', api.next_revision),
198    (r'is_?revisable/$', api.is_revisable),
199    (r'(?:lock|checkout)/(?P<df_id>\d+)/$', api.check_out),
200    (r'unlock/(?P<df_id>\d+)/$', api.unlock),
201    (r'is_?locked/(?P<df_id>\d+)/$', api.is_locked),
202    (r'checkin/(?P<df_id>\d+)/$', api.check_in),
203    (r'add_thumbnail/(?P<df_id>\d+)/$', api.add_thumbnail),
204)
205
Note: See TracBrowser for help on using the repository browser.