source: main/branches/3D/openPLM/urls.py @ 662

Revision 662, 7.5 KB checked in by pcosquer, 9 years ago (diff)

3D branch: merge changes from trunk (rev [661])

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
34import openPLM.plmapp.search_indexes
35
36from django.conf.urls.defaults import include, patterns
37from openPLM.plmapp.views import *
38import openPLM.plmapp.views.api as api
39from django.contrib.auth.views import login, logout
40from openPLM.plmapp.csvimport import IMPORTERS
41
42from django.contrib import admin
43admin.autodiscover()
44
45
46urlpatterns = patterns('')
47# add custom application urls
48for app in settings.INSTALLED_APPS:
49    if app.startswith("openPLM"):
50        try:
51            __import__("%s.urls" % app, globals(), locals(), [], -1)
52            mod_patterns = getattr(sys.modules["%s.urls" % app], "urlpatterns")
53            urlpatterns += mod_patterns
54        except ImportError:
55            pass
56
57def patterns2(view_prefix, url_prefix, *urls):
58    urls2 = []
59    for u in urls:
60        u2 = list(u)
61        u2[0] = url_prefix + u2[0]
62        urls2.append(tuple(u2))
63    return patterns(view_prefix, *urls2)
64
65object_pattern = '(?P<obj_type>\w+)/(?P<obj_ref>%(x)s)/(?P<obj_revi>%(x)s)/' % {'x' : r'[^/?#\t\r\v\f]+'}
66
67object_url = r'^object/' + object_pattern
68user_url = r'^user/(?P<obj_ref>[^/]+)/'
69group_url = r'^group/(?P<obj_ref>[^/]+)/'
70user_dict = {'obj_type':'User', 'obj_revi':'-'}
71group_dict = {'obj_type':'Group', 'obj_revi':'-'}
72
73import_url = r'^import/(?P<target>%s)/' % ("|".join(IMPORTERS.keys()))
74
75urlpatterns += patterns('',
76    (r'^admin/', include(admin.site.urls)),
77    (r'^i18n/', include('django.conf.urls.i18n')),
78
79    (r'^(?:home/)?$', display_home_page),
80    (r'^accounts/?$', login, {'template_name': 'DisplayLoginPage.htm', 'redirect_field_name': 'next'}),
81    (r'^(?:accounts/)?login/', login, {'template_name': 'DisplayLoginPage.htm', 'redirect_field_name': 'next'}),
82    (r'^(?:accounts/)?logout/', logout, {'next_page': '/login/', }),
83    (r'^object/create/$', create_object),
84    (r'^comments/', include('django.contrib.comments.urls')),
85    (import_url + '$', import_csv_init),
86    (import_url + '(?P<filename>[\w]+)/(?P<encoding>[\w]+)/$',
87        import_csv_apply),
88    ('^import/done/$', import_csv_done),
89    )
90
91urlpatterns += patterns2('', 'ajax/',
92    (r'search/$', ajax_search_form),
93    (r'complete/(?P<obj_type>\w+)/(?P<field>\w+)/$', ajax_autocomplete),
94    (r'thumbnails/%s?$' % object_pattern, ajax_thumbnails),
95    (r'navigate/%s?$' % object_pattern, ajax_navigate),
96    (r'add_child/(?P<part_id>\d+)/?', ajax_add_child),
97    (r'can_add_child/(?P<part_id>\d+)/?', ajax_can_add_child),
98    (r'attach/(?P<plmobject_id>\d+)/?', ajax_attach),
99    (r'can_attach/(?P<plmobject_id>\d+)/?', ajax_can_attach),
100)
101
102urlpatterns += patterns2('', object_url,
103    (r'$', display_object),
104    (r'attributes/$', display_object_attributes),
105    (r'lifecycle/$', display_object_lifecycle),
106    (r'revisions/$', display_object_revisions),
107    (r'history/$', display_object_history),
108    (r'BOM-child/$', display_object_child),
109    (r'BOM-child/edit/$', edit_children),
110    (r'BOM-child/add/$', add_children),
111    (r'parents/$', display_object_parents),
112    (r'doc-cad/$', display_object_doc_cad),
113    (r'doc-cad/add/$', add_doc_cad),
114    (r'parts/$', display_related_part),
115    (r'parts/add/$', add_rel_part),
116    (r'files/$', display_files),
117    (r'files/add/$', add_file),
118    (r'files/checkin/(?P<file_id_value>[^/]+)/$', checkin_file),
119    (r'files/checkout/(?P<docfile_id>[^/]+)/$', checkout_file),
120    (r'modify/$', modify_object),
121    (r'management/$', display_management),
122    (r'management/add/$', add_management),
123    (r'management/replace/(?P<link_id>\d+)/$', replace_management),
124    (r'management/delete/$', delete_management),
125    (r'navigate/$', navigate),
126    (r'(?:files/|doc-cad/)?archive/$', download_archive),
127)
128
129
130urlpatterns += patterns2('', user_url,
131    (r'$', display_object, user_dict),
132    (r'attributes/$', display_object_attributes, user_dict),
133    (r'history/$', display_object_history, user_dict),
134    (r'parts-doc-cad/$', display_related_plmobject, user_dict),
135    (r'delegation/$', display_delegation),
136    (r'delegation/sponsor/$', sponsor),
137    (r'delegation/delegate/(?P<role>[^/]+)/$', delegate,
138                    {'sign_level':'none'}),
139    (r'delegation/delegate/(?P<role>[^/]+)/(?P<sign_level>\d+|all)/$', delegate),
140    (r'modify/$', modify_user),
141    (r'password/$', change_user_password),
142    (r'navigate/$', navigate, user_dict),
143    (r'groups/$', display_groups),
144)
145
146urlpatterns += patterns2('', group_url,
147    (r'$', display_object, group_dict),
148    (r'attributes/$', display_object_attributes, group_dict),
149    (r'history/$', display_object_history, group_dict),
150    (r'objects/$', display_plmobjects),
151    (r'users/$', display_users),
152    (r'users/add/$', group_add_user),
153    (r'users/join/$', group_ask_to_join),
154    (r'invitation/accept/(?P<token>\d+)/$', accept_invitation),
155    (r'invitation/refuse/(?P<token>\d+)/$', refuse_invitation),
156    #(r'navigate/$', navigate, group_dict),
157)
158urlpatterns += patterns('',
159        # In order to take into account the css file
160    (r'^media/(?P<path>.*)$', 'django.views.static.serve',
161        {'document_root' : 'media/'}),   
162    (r'^file/(?P<docfile_id>\d+)/$', download),
163    (r'^file/(?P<docfile_id>\d+)/(?P<filename>.*)$', download),
164)
165
166# urls related to the api
167api_url = r'^api/object/(?P<doc_id>\d+)/'
168urlpatterns += patterns2('', '^api/',
169    (r'login/', api.api_login),
170    (r'needlogin/', api.need_login),
171    (r'testlogin/', api.test_login),
172    (r'types/$', api.get_all_types),
173    (r'parts/$', api.get_all_parts),
174    (r'doc(?:ument)?s/$', api.get_all_docs),
175    (r'search/$', api.search),
176    (r'search/(?P<editable_only>true|false)/$', api.search),
177    (r'search/(?P<editable_only>true|false)/(?P<with_file_only>true|false)/$',
178     api.search),
179    (r'create/$', api.create),
180    (r'search_fields/(?P<typename>[\w_]+)/$', api.get_search_fields),
181    (r'creation_fields/(?P<typename>[\w_]+)/$', api.get_creation_fields),
182    )
183
184urlpatterns += patterns2('', api_url,
185    (r'files/$', api.get_files),
186    (r'files/(?P<all_files>all)/$', api.get_files),
187    (r'revise/$', api.revise),
188    (r'add_file/$', api.add_file),
189    (r'attach_to_part/(?P<part_id>\d+)/$', api.attach_to_part),
190    (r'next_?revision/$', api.next_revision),
191    (r'is_?revisable/$', api.is_revisable),
192    (r'(?:lock|checkout)/(?P<df_id>\d+)/$', api.check_out),
193    (r'unlock/(?P<df_id>\d+)/$', api.unlock),
194    (r'is_?locked/(?P<df_id>\d+)/$', api.is_locked),
195    (r'checkin/(?P<df_id>\d+)/$', api.check_in),
196    (r'add_thumbnail/(?P<df_id>\d+)/$', api.add_thumbnail),
197)
198
Note: See TracBrowser for help on using the repository browser.