source: main/trunk/openPLM/plmapp/views.py @ 61

Revision 61, 32.7 KB checked in by pcosquer, 11 years ago (diff)

PartController? :

+ attach/detach document

tests:

+ login user

views:

+ fix a bug: create_non_modifyable_attributes is not a view function

  • Property svn:executable set to *
Line 
1from django.shortcuts import render_to_response, get_object_or_404
2import datetime
3from operator import attrgetter
4
5import openPLM.plmapp.models as models
6from openPLM.plmapp.controllers import PLMObjectController, get_controller, DocumentController
7
8from django.db.models import Q
9from django.http import HttpResponseRedirect, QueryDict, HttpResponse
10
11from openPLM.plmapp.forms import *
12from openPLM.plmapp.utils import get_next_revision
13
14from django.contrib import auth
15from django.contrib.auth.decorators import login_required
16
17##########################################################################################
18def replace_white_spaces(Chain):
19    """ Replace all whitespace characteres by %20 in order to be compatible with an URL"""
20    return Chain.replace(" ","%20")
21
22##########################################################################################
23def get_obj(object_type_value, object_reference_value, object_revision_value):
24    """ Get Type, Reference and Revision and return an object """
25    obj = get_object_or_404(models.PLMObject, type=object_type_value,
26                            reference=object_reference_value,
27                            revision=object_revision_value)
28    # guess what kind of PLMObject (Part, Document) obj is
29    cls = models.PLMObject
30    find = True
31    while find:
32        find = False
33        for c in cls.__subclasses__():
34            if hasattr(obj, c.__name__.lower()):
35                cls  = c
36                obj = getattr(obj, c.__name__.lower())
37                find = True
38    user = models.User.objects.all()[0]
39    controller_cls = get_controller(object_type_value)
40    return controller_cls(obj, user)
41
42##########################################################################################
43def init_context_dict(init_type_value, init_reference_value, init_revision_value):
44    """ Initiate context_dict we used after to transfer parameters to html pages"""
45    now = datetime.datetime.now()
46    return {
47        'current_date': now,
48        'object_reference': init_reference_value,
49        'object_revision': init_revision_value,
50        'object_type': init_type_value,
51        }
52
53##########################################################################################
54###                   Manage html pages for Home Page                                  ###
55##########################################################################################
56
57def display_global_page(request_dict):
58    """ Get a request and return a dictionnary with elements common to all pages """
59    log_in_person="pjoulaud"
60    context_dict = {'log_in_person' : request_dict.user}
61    query_dict = {}
62    type_form_instance = type_form()
63    attributes_form_instance = attributes_form()
64    extra_attributes_form_instance = get_search_form()
65    results=[]
66    if request_dict.GET and "type" in request_dict.GET:
67        type_form_instance = type_form(request_dict.GET)
68        attributes_form_instance = attributes_form(request_dict.GET)
69        for key, value in request_dict.GET.items():
70            request_dict.session[key] = value
71        if attributes_form_instance.is_valid():
72            cls = models.get_all_plmobjects()[attributes_form_instance.cleaned_data["type"]]
73            extra_attributes_form_instance = get_search_form(cls, request_dict.GET)
74            for field, value in attributes_form_instance.cleaned_data.items():
75                if value and field != "type":
76                    query_dict["%s__icontains"%field]=value
77            results = cls.objects.filter(**query_dict)
78            request_dict.session["results"] = results
79            query_dict = {}
80            if extra_attributes_form_instance.is_valid():
81                for field, value in extra_attributes_form_instance.cleaned_data.items():
82                    if value:
83                        query_dict[field]=value
84                results = extra_attributes_form_instance.search(results)
85                request_dict.session["results"] = results
86    elif request_dict.session:
87        type_form_instance = type_form(request_dict.session)
88        attributes_form_instance = attributes_form(request_dict.session)
89        request_dict.session.update(request_dict.session)
90        if attributes_form_instance.is_valid():
91            cls = models.get_all_plmobjects()[attributes_form_instance.cleaned_data["type"]]
92            extra_attributes_form_instance = get_search_form(cls, request_dict.session)
93            for field, value in attributes_form_instance.cleaned_data.items():
94                if value:
95                    query_dict["%s__icontains"%field]=value
96            results = cls.objects.filter(**query_dict)
97            query_dict = {}
98            if extra_attributes_form_instance.is_valid():
99                for field, value in extra_attributes_form_instance.cleaned_data.items():
100                    if value:
101                        query_dict[field]=value
102                results = extra_attributes_form_instance.search(results)
103     
104    context_dict.update({'results': results, 'type_form': type_form_instance, 'attributes_form': attributes_form_instance, 'extra_attributes_form': extra_attributes_form_instance})
105
106    return context_dict, request_dict.session
107#    return render_to_response('display_home_page.htm', context_dict)
108
109##########################################################################################
110###                    Function which manage the html login page                        ###
111##########################################################################################
112
113def display_login_page(request):
114    if request.method == 'POST':
115        if request.POST:
116            username_value = request.POST['username']
117            password_value = request.POST['password']
118            user = auth.authenticate(username=username_value, password=password_value)
119            if user is not None and user.is_active:
120                auth.login(request, user)
121                return HttpResponseRedirect("/home/")
122            else:
123                return HttpResponse('Mauvais login, mauvais mot de passe ou compte inactif')
124        else:
125            return HttpResponse('mauvaise requete post')
126    else:
127        return render_to_response('DisplayLoginPage.htm', {})
128
129##########################################################################################
130###                    Function which manage the html home page                        ###
131##########################################################################################
132@login_required
133def display_home_page(request):
134    now = datetime.datetime.now()
135    context_dict, SessionDictionnary= display_global_page(request)
136    class_for_div="NavigateBox4Part"
137    context_dict.update({'class4div': class_for_div, 'current_date': now,})
138    request.session.update(SessionDictionnary)
139    return render_to_response('DisplayHomePage.htm', context_dict)
140
141##########################################################################################
142###     All functions which manage the different html pages related to a part          ###
143##########################################################################################
144@login_required
145def display_object(request, object_type_value, object_reference_value, object_revision_value):
146    """ Manage html page for attributes """
147    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
148    if isinstance(obj, DocumentController):
149        class_for_div="NavigateBox4Doc"
150    else:
151        class_for_div="NavigateBox4Part"
152    menu_list = obj.menu_items
153    object_attributes_list = []
154    for attr in obj.attributes:
155        item = obj._meta.get_field(attr).verbose_name
156        object_attributes_list.append((item, getattr(obj, attr)))
157    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
158    context_dict.update({'current_page':'attributes', 'class4div': class_for_div, 'object_menu': menu_list, 'object_attributes': object_attributes_list})
159    var_dict, request_dict = display_global_page(request)
160    request.session.update(request_dict)
161    print request.user
162    context_dict.update(var_dict)
163    return render_to_response('DisplayObject.htm', context_dict)
164
165##########################################################################################
166@login_required
167def display_object_lifecycle(request, object_type_value, object_reference_value, object_revision_value):
168    """ Manage html page for Lifecycle """
169    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
170    if isinstance(obj, DocumentController):
171        class_for_div="NavigateBox4Doc"
172    else:
173        class_for_div="NavigateBox4Part"
174    if request.method == 'POST':
175        if request.POST["action"] == "DEMOTE":
176            obj.demote()
177        elif request.POST["action"] == "PROMOTE":
178            obj.promote()
179    menu_list = obj.menu_items
180    state = obj.state.name
181    lifecycle = obj.lifecycle
182    object_lifecycle_list = []
183    for st in lifecycle:
184        object_lifecycle_list.append((st, st == state))
185    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
186    context_dict.update({'current_page':'lifecycle', 'class4div': class_for_div, 'object_menu': menu_list, 'object_lifecycle': object_lifecycle_list})
187    var_dict, request_dict = display_global_page(request)
188    request.session.update(request_dict)
189    context_dict.update(var_dict)
190    return render_to_response('DisplayObjectLifecycle.htm', context_dict)
191
192##########################################################################################
193@login_required
194def display_object_revisions(request, object_type_value, object_reference_value, object_revision_value):
195    """Manage html page for revisions"""
196    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
197    if isinstance(obj, DocumentController):
198        class_for_div="NavigateBox4Doc"
199    else:
200        class_for_div="NavigateBox4Part"
201    menu_list = obj.menu_items
202    if obj.is_revisable():
203        if request.method == "POST" and request.POST:
204            add_form = AddRevisionForm(request.POST)
205            if add_form.is_valid():
206                obj.revise(add_form.cleaned_data["revision"])
207        else:
208            add_form = AddRevisionForm({"revision" : get_next_revision(object_revision_value)})
209    else:
210        add_form = None
211    revisions = obj.get_all_revisions()
212    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
213    context_dict.update({'current_page':'revisions', 'class4div': class_for_div, 'object_menu': menu_list, 'revisions': revisions,
214                         'add_revision_form' : add_form})
215    var_dict, request_dict = display_global_page(request)
216    request.session.update(request_dict)
217    context_dict.update(var_dict)
218    return render_to_response('DisplayObjectRevisions.htm', context_dict)
219
220##########################################################################################
221@login_required
222def display_object_history(request, object_type_value, object_reference_value, object_revision_value):
223    """Manage html page for history"""
224    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
225    if isinstance(obj, DocumentController):
226        class_for_div="NavigateBox4Doc"
227    else:
228        class_for_div="NavigateBox4Part"
229    menu_list = obj.menu_items
230    histos = models.History.objects.filter(plmobject=obj.object).order_by('date')
231    object_history_list = []
232    for histo in histos:
233        object_history_list.append((histo.date, histo.action, histo.details))
234    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
235    context_dict.update({'current_page':'history', 'class4div': class_for_div, 'object_menu': menu_list, 'object_history': object_history_list})
236    var_dict, request_dict = display_global_page(request)
237    request.session.update(request_dict)
238    context_dict.update(var_dict)
239    return render_to_response('DisplayObjectHistory.htm', context_dict)
240
241##########################################################################################
242@login_required
243def display_object_child(request, object_type_value, object_reference_value, object_revision_value):
244    """ Manage html page for BOM and children of the part """
245    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
246    if isinstance(obj, DocumentController):
247        class_for_div="NavigateBox4Doc"
248    else:
249        class_for_div="NavigateBox4Part"
250    menu_list = obj.menu_items
251    if not hasattr(obj, "get_children"):
252        # TODO
253        raise TypeError()
254    date = None
255    level = "first"
256    if request.GET:
257        display_form = DisplayChildrenForm(request.GET)
258        if display_form.is_valid():
259            date = display_form.cleaned_data["date"]
260            level = display_form.cleaned_data["level"]
261    else:
262        display_form = DisplayChildrenForm(initial={"date" : datetime.datetime.now(),
263                                                    "level" : "first"})
264    max_level = 1 if level == "first" else -1
265    children = obj.get_children(max_level, date=date)
266    if level == "last" and children:
267        maximum = max(children, key=attrgetter("level")).level
268        children = (c for c in children if c.level == maximum)
269    # convert level to html space
270    children = ((" " * 2 * (level-1), link) for level, link in children)
271
272    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
273    context_dict.update({'current_page':'BOM-child', 'class4div': class_for_div, 'object_menu': menu_list, 'obj' : obj,
274                                 'children': children, "display_form" : display_form})
275    var_dict, request_dict = display_global_page(request)
276    request.session.update(request_dict)
277    context_dict.update(var_dict)
278    return render_to_response('DisplayObjectChild.htm', context_dict)
279
280##########################################################################################
281@login_required
282def edit_children(request, object_type_value, object_reference_value, object_revision_value):
283    """ Manage html page for BOM and children of the part : edition"""
284    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
285    if isinstance(obj, DocumentController):
286        class_for_div="NavigateBox4Doc"
287    else:
288        class_for_div="NavigateBox4Part"
289    menu_list = obj.menu_items
290    if not hasattr(obj, "get_children"):
291        # TODO
292        raise TypeError()
293    if request.method == "POST":
294        if request.POST.get("action", "Undo") == "Undo":
295            return HttpResponseRedirect("..")
296        formset = get_children_formset(obj, request.POST)
297        if formset.is_valid():
298            obj.update_children(formset)
299            return HttpResponseRedirect("..")
300    else:
301        formset = get_children_formset(obj)
302    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
303    context_dict.update({'current_page':'BOM-child', 'class4div': class_for_div, 'object_menu': menu_list, 'obj' : obj,
304                                 'children_formset': formset, })
305    var_dict, request_dict = display_global_page(request)
306    request.session.update(request_dict)
307    context_dict.update(var_dict)
308    return render_to_response('DisplayObjectChildEdit.htm', context_dict)
309
310##########################################################################################   
311@login_required
312def add_children(request, object_type_value, object_reference_value, object_revision_value):
313    """ Manage html page for BOM and children of the part : add new link"""
314    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
315    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
316    if isinstance(obj, DocumentController):
317        class_for_div="NavigateBox4Doc"
318    else:
319        class_for_div="NavigateBox4Part"
320    menu_list = obj.menu_items
321    var_dict, request_dict = display_global_page(request)
322    request.session.update(request_dict)
323    context_dict.update(var_dict)
324    if request.POST:
325        add_child_form_instance = add_child_form(request.POST)
326        if add_child_form_instance.is_valid():
327            child_obj = get_obj(add_child_form_instance.cleaned_data["type"], \
328                        add_child_form_instance.cleaned_data["reference"], \
329                        add_child_form_instance.cleaned_data["revision"])
330            obj.add_child(child_obj, \
331                            add_child_form_instance.cleaned_data["quantity"], \
332                            add_child_form_instance.cleaned_data["order"])
333            context_dict.update({'object_menu': menu_list, 'add_child_form': add_child_form_instance, })
334            return HttpResponseRedirect("/object/%s/%s/%s/BOM-child/" \
335                                        % (object_type_value, object_reference_value, object_revision_value) )
336        else:
337            add_child_form_instance = add_child_form(request.POST)
338            context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_child_form': add_child_form_instance, })
339            return render_to_response('DisplayObjectChildAdd.htm', context_dict)
340    else:
341        add_child_form_instance = add_child_form()
342        context_dict.update({'current_page':'BOM-child', 'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_child_form': add_child_form_instance, })
343        return render_to_response('DisplayObjectChildAdd.htm', context_dict)
344   
345##########################################################################################   
346@login_required
347def display_object_parents(request, object_type_value, object_reference_value, object_revision_value):
348    """ Manage html page for "where is used / parents" of the part """
349    obj = get_obj( object_type_value, object_reference_value, object_revision_value)
350    if isinstance(obj, DocumentController):
351        class_for_div="NavigateBox4Doc"
352    else:
353        class_for_div="NavigateBox4Part"
354    menu_list = obj.menu_items
355    if not hasattr(obj, "get_parents"):
356        # TODO
357        raise TypeError()
358    date = None
359    level = "first"
360    if request.GET:
361        display_form = DisplayChildrenForm(request.GET)
362        if display_form.is_valid():
363            date = display_form.cleaned_data["date"]
364            level = display_form.cleaned_data["level"]
365    else:
366        display_form = DisplayChildrenForm(initial={"date" : datetime.datetime.now(),
367                                                    "level" : "first"})
368    max_level = 1 if level == "first" else -1
369    parents = obj.get_parents(max_level, date=date)
370    if level == "last" and parents:
371        maximum = max(parents, key=attrgetter("level")).level
372        parents = (c for c in parents if c.level == maximum)
373
374    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
375    context_dict.update({'current_page':'parents', 'class4div': class_for_div, 'object_menu': menu_list, 'parents' :  parents,
376                                 'display_form' : display_form, 'obj': obj})
377    var_dict, request_dict = display_global_page(request)
378    request.session.update(request_dict)
379    context_dict.update(var_dict)
380    return render_to_response('DisplayObjectParents.htm', context_dict)
381
382##########################################################################################
383@login_required
384def display_object_doc_cad(request, object_type_value, object_reference_value, object_revision_value):
385    """ Manage html page for related documents and CAD of the part"""
386    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
387    if isinstance(obj, DocumentController):
388        class_for_div="NavigateBox4Doc"
389    else:
390        class_for_div="NavigateBox4Part"
391    menu_list = obj.menu_items
392    object_doc_cad_list = [
393        (["Type", "Reference", "Revision", "Name", "Status"], ""),
394        (["Rapport essais", "Doc0045", "a", "Essais de compatibilite electro-magnetique", "official"], replace_white_spaces("/object/Rapport essais/Doc0045/a/")),
395        (["Incident Qualite", "Doc0066", "b", "Probleme de casse chaine", "obsolete"], replace_white_spaces("/object/Incident Qualite/Doc0066/b/")),
396        (["CatDrawing", "Cad00123", "a", "Vue d'ensemble", "official"], replace_white_spaces("/object/CatDrawing/Cad00123/a/")),
397        ]
398    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
399    context_dict.update({'current_page':'doc-cad', 'class4div': class_for_div, 'object_menu': menu_list, 'object_doc_cad': object_doc_cad_list})
400    var_dict, request_dict = display_global_page(request)
401    request.session.update(request_dict)
402    context_dict.update(var_dict)
403    return render_to_response('DisplayObjectDocCad.htm', context_dict)
404
405##########################################################################################   
406@login_required
407def add_doc_cad(request, object_type_value, object_reference_value, object_revision_value):
408    """ Manage html page for BOM and children of the part : add new link"""
409    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
410    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
411    if isinstance(obj, DocumentController):
412        class_for_div="NavigateBox4Doc"
413    else:
414        class_for_div="NavigateBox4Part"
415    menu_list = obj.menu_items
416    var_dict, request_dict = display_global_page(request)
417    request.session.update(request_dict)
418    context_dict.update(var_dict)
419    if request.POST:
420        add_doc_cad_form_instance = add_doc_cad_form(request.POST)
421        if add_doc_cad_form_instance.is_valid():
422            doc_cad_obj = get_obj(add_doc_cad_form_instance.cleaned_data["type"], \
423                        add_doc_cad_form_instance.cleaned_data["reference"], \
424                        add_doc_cad_form_instance.cleaned_data["revision"])
425            obj.add_doc_cad(doc_cad_obj)
426            context_dict.update({'object_menu': menu_list, 'add_doc_cad_form': add_doc_cad_form_instance, })
427            return HttpResponseRedirect("/object/%s/%s/%s/doc-cad/" \
428                                        % (object_type_value, object_reference_value, object_revision_value) )
429        else:
430            add_doc_cad_form_instance = add_doc_cad_form(request.POST)
431            context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_doc_cad_form': add_doc_cad_form_instance, })
432            return render_to_response('DisplayDocCadAdd.htm', context_dict)
433    else:
434        add_doc_cad_form_instance = add_doc_cad_form()
435        context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_doc_cad_form': add_doc_cad_form_instance, })
436        return render_to_response('DisplayDocCadAdd.htm', context_dict)
437   
438##########################################################################################
439@login_required
440def display_related_part(request, object_type_value, object_reference_value, object_revision_value):
441    """ Manage html page for related parts of the document"""
442    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
443    if isinstance(obj, DocumentController):
444        class_for_div="NavigateBox4Doc"
445    else:
446        class_for_div="NavigateBox4Part"
447    menu_list = obj.menu_items
448
449    if not hasattr(obj, "get_attached_parts"):
450        # TODO
451        raise TypeError()
452    if request.method == "POST":
453        print request.POST.items()
454        formset = get_rel_part_formset(obj, request.POST)
455        if formset.is_valid():
456            obj.update_rel_part(formset)
457            return HttpResponseRedirect(".")
458    else:
459        formset = get_rel_part_formset(obj)
460
461    object_rel_part_list = obj.get_attached_parts()
462    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
463    context_dict.update({'current_page':'parts', 'class4div': class_for_div, 'object_menu': menu_list, 'object_rel_part': object_rel_part_list, 'rel_part_formset': formset})
464    var_dict, request_dict = display_global_page(request)
465    request.session.update(request_dict)
466    context_dict.update(var_dict)
467    return render_to_response('DisplayObjectRelPart.htm', context_dict)
468
469##########################################################################################   
470@login_required
471def add_rel_part(request, object_type_value, object_reference_value, object_revision_value):
472    """ Manage html page for related part of the document : add new link"""
473    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
474    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
475    if isinstance(obj, DocumentController):
476        class_for_div="NavigateBox4Doc"
477    else:
478        class_for_div="NavigateBox4Part"
479    menu_list = obj.menu_items
480    var_dict, request_dict = display_global_page(request)
481    request.session.update(request_dict)
482    context_dict.update(var_dict)
483    if request.POST:
484        add_rel_part_form_instance = AddRelPartForm(request.POST)
485        if add_rel_part_form_instance.is_valid():
486            part_obj = get_obj(add_rel_part_form_instance.cleaned_data["type"], \
487                        add_rel_part_form_instance.cleaned_data["reference"], \
488                        add_rel_part_form_instance.cleaned_data["revision"])
489            obj.attach_to_part(part_obj)
490            context_dict.update({'object_menu': menu_list, 'add_rel_part_form': add_rel_part_form_instance, })
491            return HttpResponseRedirect("/object/%s/%s/%s/parts/" \
492                                        % (object_type_value, object_reference_value, object_revision_value) )
493        else:
494            add_rel_part_form_instance = add_rel_part_form(request.POST)
495            context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_rel_part_form': add_rel_part_form_instance, })
496            return render_to_response('DisplayRelPartAdd.htm', context_dict)
497    else:
498        add_rel_part_form_instance = AddRelPartForm()
499        context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_rel_part_form': add_rel_part_form_instance, })
500        return render_to_response('DisplayRelPartAdd.htm', context_dict)
501
502##########################################################################################
503@login_required
504def display_files(request, object_type_value, object_reference_value, object_revision_value):
505    """ Manage html page for files contained by the document"""
506    obj = get_obj(object_type_value, object_reference_value, object_revision_value)
507    if isinstance(obj, DocumentController):
508        class_for_div="NavigateBox4Doc"
509    else:
510        class_for_div="NavigateBox4Part"
511    menu_list = obj.menu_items
512    object_files_list = [('essais-endurance.pdf', 120, False), ('rapport-essais.odf', 45, True)]
513    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
514    context_dict.update({'current_page':'files', 'class4div': class_for_div, 'object_menu': menu_list, 'object_files': object_files_list})
515    var_dict, request_dict = display_global_page(request)
516    request.session.update(request_dict)
517    context_dict.update(var_dict)
518    return render_to_response('DisplayObjectFiles.htm', context_dict)
519
520
521##########################################################################################
522###             Manage html pages for part creation / modification                     ###
523##########################################################################################
524def create_non_modifyable_attributes_list(Classe=models.PLMObject):
525    """ Create a list of an object's attributes we can't modify' and set them a value """
526    non_modifyable_fields_list = Classe.excluded_creation_fields()
527    non_modifyable_attributes_list=[]
528    non_modifyable_attributes_list.append((non_modifyable_fields_list[0], 'Person'))
529    non_modifyable_attributes_list.append((non_modifyable_fields_list[1], 'Person'))
530    non_modifyable_attributes_list.append((non_modifyable_fields_list[2], 'Date'))
531    non_modifyable_attributes_list.append((non_modifyable_fields_list[3], 'Date'))
532    return non_modifyable_attributes_list
533
534##########################################################################################
535@login_required
536def create_object(request):
537    """ Manage html page for the part creation """
538    now = datetime.datetime.now()
539    context_dict = {'current_date': now}
540    var_dict, request_dict = display_global_page(request)
541    request.session.update(request_dict)
542    context_dict.update(var_dict)
543    log_in_person="pjoulaud"
544    context_dict.update({'log_in_person' : log_in_person})
545    if request.method == 'GET':
546        if request.GET:
547            type_form_instance = type_form(request.GET)
548            if type_form_instance.is_valid():
549                cls = models.get_all_plmobjects()[type_form_instance.cleaned_data["type"]]
550                if issubclass(cls, models.Document):
551                    class_for_div="NavigateBox4Doc"
552                else:
553                    class_for_div="NavigateBox4Part"
554                creation_form_instance = get_creation_form(cls, {'revision':'a', 'lifecycle': str(models.get_default_lifecycle()), }, True)
555                non_modifyable_attributes_list = create_non_modifyable_attributes_list(cls)
556    elif request.method == 'POST':
557        if request.POST:
558            type_form_instance = type_form(request.POST)
559            if type_form_instance.is_valid():
560                type_name = type_form_instance.cleaned_data["type"]
561                cls = models.get_all_plmobjects()[type_name]
562                if issubclass(cls, models.Document):
563                    class_for_div="NavigateBox4Doc"
564                else:
565                    class_for_div="NavigateBox4Part"
566                non_modifyable_attributes_list = create_non_modifyable_attributes_list(cls)
567                creation_form_instance = get_creation_form(cls, request.POST)
568                if creation_form_instance.is_valid():
569                    user = models.User.objects.get(username=context_dict['log_in_person'])
570                    controller_cls = get_controller(type_name)
571                    controller = PLMObjectController.create_from_form(creation_form_instance, user)
572                    return HttpResponseRedirect("/object/%s/%s/%s/" % (controller.type, controller.reference, controller.revision) )
573    context_dict.update({'class4div': class_for_div, 'creation_form': creation_form_instance, 'object_type': type_form_instance.cleaned_data["type"], 'non_modifyable_attributes': non_modifyable_attributes_list })
574    return render_to_response('DisplayObject4creation.htm', context_dict)
575
576##########################################################################################
577@login_required
578def modify_object(request, object_type_value, object_reference_value, object_revision_value):
579    """ Manage html page for part modification """
580    log_in_person="pjoulaud"
581    now = datetime.datetime.now()
582    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value)
583    context_dict.update({'log_in_person' : log_in_person})
584    cls = models.get_all_plmobjects()[object_type_value]
585    non_modifyable_attributes_list = create_non_modifyable_attributes_list(cls)
586    current_object = get_obj(object_type_value, object_reference_value, object_revision_value)
587    if isinstance(obj, DocumentController):
588        class_for_div="NavigateBox4Doc"
589    else:
590        class_for_div="NavigateBox4Part"
591    if request.method == 'POST':
592        if request.POST:
593            modification_form_instance = get_modification_form(cls, request.POST)
594            if modification_form_instance.is_valid():
595                user = models.User.objects.get(username=log_in_person)
596                current_object.update_from_form(modification_form_instance)
597                return HttpResponseRedirect("/object/%s/%s/%s/" % (current_object.type, current_object.reference, current_object.revision) )
598            else:
599                pass
600        else:
601            modification_form_instance = get_modification_form(cls, instance = current_object.object)
602    else:
603        modification_form_instance = get_modification_form(cls, instance = current_object.object)
604    var_dict, request_dict = display_global_page(request)
605    request.session.update(request_dict)
606    context_dict.update(var_dict)
607    context_dict.update({'class4div': class_for_div, 'modification_form': modification_form_instance, 'non_modifyable_attributes': non_modifyable_attributes_list})
608    return render_to_response('DisplayObject4modification.htm', context_dict)
609   
610##########################################################################################
611def display_bollox(request):
612    context_dict={}
613    return render_to_response('bollox.htm', context_dict)
614   
615   
616   
617   
618   
619   
620   
621   
622   
Note: See TracBrowser for help on using the repository browser.