Languages

Previous versions

1.2
1.1

Source code for plmapp.navigate

############################################################################
# openPLM - open source PLM
# Copyright 2010 Philippe Joulaud, Pierre Cosquer
#
# This file is part of openPLM.
#
#    openPLM is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    openPLM is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with openPLM.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact :
#    Philippe Joulaud : ninoo.fr@gmail.com
#    Pierre Cosquer : pcosquer@linobject.com
################################################################################

"""
This module provides :class:`NavigationGraph` which is used to generate
the navigation's graph in :func:`~plmapp.views.navigate`.
"""

import re
import datetime
import warnings
import cStringIO as StringIO
import xml.etree.cElementTree as ET
from collections import defaultdict

from django.conf import settings
from django.contrib.auth.models import User
from django.template.loader import render_to_string
from django.utils.html import linebreaks
from django.utils.encoding import iri_to_uri
from django.forms.util import from_current_timezone

import pygraphviz as pgv

from openPLM.plmapp import models
from openPLM.plmapp.controllers import PLMObjectController, GroupController
from openPLM.plmapp.controllers.user import UserController


#: limit of objects displayed per link category
OBJECTS_LIMIT = 100

# just a shortcut
OSR = "only_search_results"

TIME_FORMAT = "%Y-%m-%d:%H:%M:%S/"

[docs]def get_id_card_data(doc_ids, date=None): """ Get informations to display in the id-cards of all Document which id is in doc_ids :param doc_ids: list of Document ids to treat :return: a Dictionnary which contains the following informations * ``thumbnails`` list of tuple (document,thumbnail) * ``num_files`` list of tuple (document, number of file) """ ctx = { "thumbnails" : {}, "num_files" : {} } if doc_ids: thumbnails = models.DocumentFile.objects.filter(deprecated=False, document__in=doc_ids, thumbnail__isnull=False).exclude(thumbnail="") ctx["thumbnails"].update(thumbnails.values_list("document", "thumbnail")) num_files = dict.fromkeys(doc_ids, 0) for doc_id in models.DocumentFile.objects.filter(deprecated=False, document__in=doc_ids).values_list("document", flat=True): num_files[doc_id] += 1 ctx["num_files"] = num_files return ctx
[docs]class FrozenAGraph(pgv.AGraph): ''' A frozen AGraph :param data: representation of the graph in dot format ''' def __init__(self, data): pgv.AGraph.__init__(self, data) self.data = data
[docs] def write(self, path): if hasattr(path, "write"): path.write(self.data.encode("utf-8")) else: with file(path, "w") as f: f.write(self.data)
[docs]def get_path(obj): if hasattr(obj, "type"): if obj.type == "ECR": return u"ECR/%s" % obj.reference return u"/".join((obj.type, obj.reference, obj.revision)) elif hasattr(obj, 'name'): return u"Group/%s/-/" % obj.name else: return u"User/%s/-/" % obj.username
_attrs = ("id", "type", "reference", "revision", "name", "state", "lifecycle") _plmobjects_attrs = ["plmobject__" + x for x in _attrs] _parts_attrs = ["part__" + x for x in _attrs] _documents_attrs = ["document__" + x for x in _attrs]
[docs]def is_part(plmobject): return plmobject["type"] in models.get_all_parts()