[Mpuls-commits] r821 - wasko/branches/2.0/waskaweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Jan 22 11:35:50 CET 2010
Author: torsten
Date: 2010-01-22 11:35:49 +0100 (Fri, 22 Jan 2010)
New Revision: 821
Removed:
wasko/branches/2.0/waskaweb/controllers/agency_overview.py
Log:
Removed file from svn as it not used anywhere
Deleted: wasko/branches/2.0/waskaweb/controllers/agency_overview.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/agency_overview.py 2010-01-22 10:10:37 UTC (rev 820)
+++ wasko/branches/2.0/waskaweb/controllers/agency_overview.py 2010-01-22 10:35:49 UTC (rev 821)
@@ -1,492 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-#
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
-# Web-Anwendungs-Server fuer Kompetenzagenturen).
-#
-# mpuls WASKA is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or (at your
-# option) any later version.
-#
-# mpuls WASKA 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 Affero General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-#
-# mpuls WASKA has been developed on behalf of the
-# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
-# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
-# European Social Fund resources.
-#
-# Authors:
-# Torsten Irländer <torsten.irlaender at intevation.de>
-# Sascha L. Teichmann <teichmann at intevation.de>
-#
-
-import logging
-import formencode
-import paste
-
-from waskaweb.lib.csv import exportAsCSV
-from waskaweb.lib.base import *
-from waskaweb.lib.validators import AgencyBundleActionForm, SearchAgencyForm, CasePartSelectionForm
-from waskaweb.lib.security import checkRole
-from waskaweb.model.agency import AgencyOverview, AgencyFactory, AgencyBundle
-from waskaweb.model.case import CaseBundle
-
-from waskaweb.controllers.case_overview import EXPORT_SUCCESS, \
- EXPORT_SUCCESS_EXPLAINATION, \
- EXPORT_SUCCESS_XLS, \
- EXPORT_SUCCESS_XLS_EXPLAINATION, \
- EXPORT_SUCCESS_XML, \
- EXPORT_SUCCESS_XML_EXPLAINATION, \
- parseSearchOptions
-
-from waskaweb.lib.exportselection import CasePartsSelection
-
-
-FORM_DEFAULTS = {}
-
-log = logging.getLogger(__name__)
-
-DELETE_CONFIRM = u'''Fallakten der Einrichtung löschen?'''
-DELETE_CONFIRM_TEXT = u'''Wollen Sie wirklich die Fallakte der Einrichtung löschen und die Daten unwiederbringlich verlieren?'''
-
-DIALOG_EMPTY_SELECTION = u'''Keine Einrichtung ausgewählt'''
-DIALOG_EMPTY_SELECTION_EXPLAINATION = u'''Sie haben keine Einrichtungen ausgewählt für die Sie die gewählte Aktion ausführen können. Bitte klicken Sie auf "OK", um zur Einrichtungenübersicht zu gelangen und dort Einrichtungen auszuwählen.'''
-
-DIALOG_CONFIRM_EXPORT = u'''Fallakten als CSV-Datei exportieren?'''
-DIALOG_CONFIRM_EXPORT_EXPLAINATION = u'''Wollen Sie wirklich die Fallakten der folgenden Einrichtungen exportieren?%s'''
-
-DIALOG_CONFIRM_DELETE = u'''Fallakten löschen?'''
-DIALOG_CONFIRM_DELETE_EXPLAINATION = u'''Wollen Sie wirklich die Fallakten der folgenden Einrichtungen löschen?%s'''
-
-EXPORT_ERROR = u'''Es ist ein Fehler aufgetreten'''
-EXPORT_ERROR_EXPLAINATION = u'''Bei dem Exportieren der Fallakten ist ein Fehler aufgetreten. Klicken Sie auf "OK", um zur Einrichtungenübersicht zu gelangen.'''
-
-DELETE_SUCCSESS = u'''Fallakten erfolgreich gelöscht'''
-DELETE_SUCCSESS_EXPLAINATION = u'''Es wurden die Fallakten von %s Einrichtungen erfolgreich gelöscht. Klicken Sie auf "OK", um zur Einrichtungenübersicht zu gelangen.'''
-DELETE_ERROR = u'''Es ist ein Fehler aufgetreten'''
-DELETE_ERROR_EXPLAINATION = u'''Bei dem Löschen der Fallakten ist ein Fehler aufgetreten. Klicken Sie auf "OK", um zur Einrichtungenübersicht zu gelangen.'''
-
-DELETE_NOTIFICATION_EMPTYLIST = u'''Es wurden keine Fallakten gelöscht.'''
-
-SELECT_PARTS_FOR_EXPORT = u"Welche Bereiche der Fallakte(n) sollen exportiert werden?"
-
-class AgencyOverviewController(BaseController):
-
- @checkRole(('pb_ka', 'admin_ka'))
- def index(self):
- return self.overview()
-
- @checkRole(('pb_ka'))
- def overview_extended(self):
- extended = session.get('EXTENDED_SEARCH')
- if extended is not None:
- extended = not extended
- else:
- extended = True
- session['EXTENDED_SEARCH'] = extended
- session.save()
- return self.overview(0)
-
- @checkRole(('pb_ka'))
- def overview(self, reset=0, sort_field="fkz", sort_order="asc"):
- reset = self._checkBool(reset)
- if reset:
- session['CASE_OVERVIEW_SEARCHOPTIONS'] = {}
- session['CASE_OVERVIEW_SELECTION'] = {}
- session['EXTENDED_SEARCH'] = False
- session.save()
-
- c.extended_search = session.get('EXTENDED_SEARCH', False)
- user = session['USER_AUTHORIZED']
-
- ## editor or standin setting will be ignored for admin users. They will
- ## be overwritten in case-controller
- #ulo = UserListObject()
- #filter = [u.id for u in ulo.getAdminList()]
- #c.userlist = ulo.getUserList(filter)
-
- form_defaults = session.get('CASE_OVERVIEW_SEARCHOPTIONS') or FORM_DEFAULTS
- search_options = parseSearchOptions(form_defaults)
-
- # Sorting of the cases
- if sort_field == "fkz":
- search_options.append('sort_field:fkz')
- if sort_field == "num_cases":
- search_options.append('sort_field:anzahl')
- if sort_field == "zugriff":
- search_options.append('sort_field:zugriff')
-
- if sort_order == "desc":
- search_options.append('sort_order:desc')
- else:
- search_options.append('sort_order:asc')
-
- search_str = ";".join(search_options)
-
- c.agencys = AgencyOverview()
- c.agencys.search(search_str)
-
- ##count num of cases
- c.count_all = 0
- for x in c.agencys.getDatasets():
- c.count_all += x.num_cases
- ## Load case-selection and merge with default search options
- ## Ok please close your eyes now!!! This is.... well ugly
- form_defaults_copy = form_defaults.copy()
- form_defaults_copy.update(session.get('CASE_OVERVIEW_SELECTION', {}))
-
- overview = render('/casemanagement/agency_overview.mako')
- return formencode.htmlfill.render(unicode(overview, 'utf-8'),defaults=form_defaults_copy)
-
- @checkRole(('pb_ka'))
- def search(self):
- validator = SearchAgencyForm()
- c.form_result = {}
- c.form_errors = {}
- try:
- form_result = validator.to_python(request.params)
- except formencode.Invalid, error:
- form_result = error.value
- form_errors = error.error_dict or {}
- session['CASE_OVERVIEW_SEARCHOPTIONS'] = form_result
- session.save()
- return self.overview()
-
- @checkRole(('pb_ka'))
- def delete(self, id, confirmed):
- #id = self._checkInt(id)
- confirmed = self._checkBool(confirmed)
- if confirmed == 1:
- factory = AgencyFactory()
- agency = factory.loadByFkz(id)
- num = agency.delete() # delete all cases of this agency
- if num > 0:
- c.success_for = u'Fallakten der Einrichtung gelöscht!'
- c.success_text = u'Bitte klicken Sie "OK", um fortzufahren.'
- c.url_ok = h.url_for(controller="/agency_overview")
- return render('/casemanagement/dialogs/success_delete.mako')
- return "Error! Could not delete ds."
- else:
- c.context = "../main.mako"
- c.confirm_for = DELETE_CONFIRM
- c.question = DELETE_CONFIRM_TEXT
- c.url_yes = "/agency_overview/delete/%s/1" % id
- c.url_no = "/agency_overview/"
- return render('/casemanagement/dialogs/confirm_delete.mako')
-
- @checkRole(('pb_ka'))
- def bundleAction(self):
- validator = AgencyBundleActionForm()
- c.context = "../main.mako"
- c.url_ok = "/agency_overview"
- c.notification_for = DIALOG_EMPTY_SELECTION
- c.notification_text = DIALOG_EMPTY_SELECTION_EXPLAINATION
- try:
- data = formencode.variabledecode.variable_decode(request.params)
- form_result = validator.to_python(data)
- session['CASE_OVERVIEW_SELECTION'] = form_result
- session.save()
- action = form_result.get('action')
- if form_result.get('all_cases'):
- form_defaults = session.get('CASE_OVERVIEW_SEARCHOPTIONS') or FORM_DEFAULTS
- search_options = parseSearchOptions(form_defaults)
- # sql query fails if no sort order is given.
- search_options.append('sort_field:fkz')
- search_options.append('sort_order:asc')
- agency_ids = [a.fkz for a in AgencyOverview().search(";".join(search_options))]
- agency_bundle = AgencyBundle(agency_ids)
- else:
- agency_bundle = AgencyBundle(form_result.get('agency_id', []))
-
- if action == 'no_action':
- return self.overview()
- if agency_bundle.isEmpty():
- return render('/casemanagement/dialogs/bundle_noselection.mako')
-
- session['agencybundle'] = agency_bundle
- session.save()
-
- if action == 'delete':
- return self.deleteBundle(0)
- if action == 'exportCSV':
- # We do not need confirmation here i think as no data will be
- # modified.
- #return self.exportBundle(1)
- return self.downloadCSV()
- if action == 'exportXML':
- return self.downloadXML()
- if action == 'exportXLS':
- return self.downloadXLS()
- if action == 'evaluate':
- # fetch all case ids from the agency bundle
- case_ids = []
- for a in agency_bundle.getAgencys():
- case_ids.extend(a.getCaseBundle().listDatasetIds())
- # now build one huge case_bundle
- case_bundle = CaseBundle(case_ids)
- session['casebundle'] = case_bundle
- session['hide_search_option_on_eval'] = True
- session.save()
- redirect_to(controller='evaluate', action="evaluate", id=1);
- else:
- raise HTTPNotFound()
-
- except formencode.Invalid, error:
- c.form_result = error.value
- c.form_errors = error.error_dict or {}
- form = render('/casemanagement/agency_overview.mako')
- return htmlfill.render(unicode(form, 'utf-8'), c.form_result, c.form_errors, auto_insert_errors=False)
- return render('/casemanagement/agency_overview.mako')
-
- @checkRole(('pb_ka',))
- def downloadCSV(self):
- c.success_for = EXPORT_SUCCESS
- c.success_text = EXPORT_SUCCESS_EXPLAINATION
- c.selection_link = h.url_for(action="selectCSVParts");
- c.download_link = h.url_for(action="downloadCSVAction")
- c.overview_link = h.url_for(action="overview")
- return render('casemanagement/downloadCSV.mako')
-
- @checkRole(('pb_ka',))
- def selectCSVParts(self):
- selection_checker = self.__getSelectionChecker()
- c.selection_question = SELECT_PARTS_FOR_EXPORT
- c.store_action = h.url_for(action="storeSelectedCSVParts")
- c.back_url = h.url_for(controller='/agency_overview', action='downloadCSV', confirmed=1)
- c.back_title = "CSV Export"
- page = render('casemanagement/selectParts.mako')
- return formencode.htmlfill.render(unicode(page, 'utf-8'),defaults=selection_checker.selections)
-
- @checkRole(('pb_ka',))
- def storeSelectedCSVParts(self):
- validator = CasePartSelectionForm()
- selection_checker = self.__getSelectionChecker()
- try:
- params = validator.to_python(request.params)
- for key, value in params.iteritems():
- selection_checker.setChecked(key, value)
- session['selected_export_parts'] = selection_checker
- session.save()
- except formencode.Invalid, error:
- return selectCSVParts()
- return self.downloadCSV()
-
- @checkRole(('pb_ka',))
- def downloadXML(self):
- c.success_for = EXPORT_SUCCESS_XML
- c.success_text = EXPORT_SUCCESS_XML_EXPLAINATION
- selection_checker = self.__getSelectionChecker()
- c.is_all_selected = selection_checker.isAllSelected()
- case_parts_selection = session.get('case_parts_selection')
- c.selection_link = h.url_for(action="selectXMLParts")
- c.download_link = h.url_for(action="downloadXMLAction")
- c.overview_link = h.url_for(action="overview")
- return render('casemanagement/downloadXML.mako')
-
- def __getSelectionChecker(self):
- selection_checker = session.get('selected_export_parts')
- if not selection_checker:
- selection_checker = CasePartsSelection()
- session['selected_export_parts'] = selection_checker
- session.save()
- return selection_checker
-
- @checkRole(('pb_ka',))
- def selectXMLParts(self):
- selection_checker = self.__getSelectionChecker()
- c.selection_question = SELECT_PARTS_FOR_EXPORT
- c.back_title = "XML Export"
- c.back_url = h.url_for(controller='/agency_overview', action='downloadXML', confirmed=1)
- c.store_action = h.url_for(action="storeSelectedXMLParts")
- page = render('casemanagement/selectParts.mako')
- return formencode.htmlfill.render(unicode(page, 'utf-8'),defaults=selection_checker.selections)
- #c.selection_checker = self.__getSelectionChecker()
- #c.selection_question = SELECT_PARTS_FOR_EXPORT
- #c.store_action = h.url_for(action="storeSelectedXMLParts")
- #return render('casemanagement/selectParts.mako')
-
- @checkRole(('pb_ka',))
- def storeSelectedXMLParts(self):
- validator = CasePartSelectionForm()
- selection_checker = self.__getSelectionChecker()
- try:
- params = validator.to_python(request.params)
- for key, value in params.iteritems():
- selection_checker.setChecked(key, value)
- session['selected_export_parts'] = selection_checker
- session.save()
- except formencode.Invalid, error:
- return selectXMLParts()
- return self.downloadXML()
- #selection_checker = self.__getSelectionChecker()
- #params = request.params
- #for i in range(selection_checker.numItems()):
- # value = params.get("c%d" % i) and True or False
- # selection_checker.setChecked(i, value)
- #session['selected_export_parts'] = selection_checker
- #session.save()
- #return self.downloadXML()
-
- @checkRole(('pb_ka',))
- def downloadXLS(self):
- c.success_for = EXPORT_SUCCESS_XLS
- c.success_text = EXPORT_SUCCESS_XLS_EXPLAINATION
- selection_checker = self.__getSelectionChecker()
- c.is_all_selected = selection_checker.isAllSelected()
- c.selection_link = h.url_for(action="selectXLSParts")
- c.download_link = h.url_for(action="downloadXLSAction")
- c.overview_link = h.url_for(action="overview")
- return render('casemanagement/downloadXLS.mako')
-
- @checkRole(('pb_ka',))
- def selectXLSParts(self):
- selection_checker = self.__getSelectionChecker()
- c.selection_question = SELECT_PARTS_FOR_EXPORT
- c.store_action = h.url_for(action="storeSelectedXLSParts")
- c.back_url = h.url_for(controller='/agency_overview', action='downloadXLS', confirmed=1)
- c.back_title = "XLS Export"
- page = render('casemanagement/selectParts.mako')
- return formencode.htmlfill.render(unicode(page, 'utf-8'),defaults=selection_checker.selections)
-
- @checkRole(('pb_ka',))
- def storeSelectedXLSParts(self):
- validator = CasePartSelectionForm()
- selection_checker = self.__getSelectionChecker()
- try:
- params = validator.to_python(request.params)
- for key, value in params.iteritems():
- selection_checker.setChecked(key, value)
- session['selected_export_parts'] = selection_checker
- session.save()
- except formencode.Invalid, error:
- return selectXLSParts()
- return self.downloadXLS()
-
- @checkRole(('pb_ka'))
- def downloadCSVAction(self):
- agency_bundle = session.get('agencybundle')
- case_ids = []
- for agency in agency_bundle.getAgencys():
- case_ids.extend(agency.getCaseBundle().listDatasetIds())
- try:
- if case_ids:
- case_bundle = CaseBundle(case_ids)
- selection_checker = self.__getSelectionChecker()
- csv = case_bundle.exportAsCSV(selection_checker)
- data = paste.fileapp.DataApp(
- csv,
- content_type='text/comma-separated-values',
- content_disposition = 'attachment; filename="fallakten-export.csv"',
- content_encoding='Latin-1',
- cache_control='must-revalidate',
- pragma='public')
- return data(request.environ, self.start_response)
- except:
- return render('/tests/trace.mako')
-
- @checkRole(('pb_ka'))
- def downloadXMLAction(self):
- agency_bundle = session.get('agencybundle')
- case_ids = []
- for agency in agency_bundle.getAgencys():
- case_ids.extend(agency.getCaseBundle().listDatasetIds())
- try:
- if case_ids:
- case_bundle = CaseBundle(case_ids)
- selection_checker = self.__getSelectionChecker()
- xml = case_bundle.exportAsXML(selection_checker)
- data = paste.fileapp.DataApp(
- xml,
- content_type = 'application/xml',
- content_disposition = 'attachment; filename="fallakten-export.xml"',
- content_encoding = 'UTF-8',
- cache_control = 'must-revalidate',
- pragma = 'public')
- return data(request.environ, self.start_response)
- except:
- return render('/tests/trace.mako')
-
- @checkRole(('pb_ka',))
- def downloadXLSAction(self):
- agency_bundle = session.get('agencybundle')
- case_ids = []
- for agency in agency_bundle.getAgencys():
- case_ids.extend(agency.getCaseBundle().listDatasetIds())
- try:
- if case_ids:
- case_bundle = CaseBundle(case_ids)
- selection_checker = self.__getSelectionChecker()
- xls = case_bundle.exportAsXLS(selection_checker)
- data = paste.fileapp.DataApp(
- xls,
- content_type = 'application/msexcel',
- content_disposition = 'attachment; filename="fallakten-export.xls"',
- cache_control = 'must-revalidate',
- pragma = 'public')
- return data(request.environ, self.start_response)
- except:
- return render('/tests/trace.mako')
-
- #@checkRole(('pb_ka', 'cm_ka'))
- #def exportBundle(self, confirmed):
- # confirmed = self._checkBool(confirmed)
- # agency_bundle = session.get('agencybundle')
- # c.context = "../main.mako"
- # if confirmed == 1:
- # try:
- # c.success_for = EXPORT_SUCCESS
- # c.success_text = EXPORT_SUCCESS_EXPLAINATION
- # return render('/casemanagement/downloadCSV.mako')
- # except StandardError, err:
- # c.failed_for = EXPORT_ERROR
- # c.failed_test = EXPORT_ERROR_EXPLAINATION
- # c.url_ok = "/agency_overview/"
- # return render('/casemanagement/dialogs/failed_export_agency.mako')
- # else:
- # c.confirm_for = DIALOG_CONFIRM_EXPORT
- # c.question = DIALOG_CONFIRM_EXPORT_EXPLAINATION % "\n".join(self._buildAgencyList(agency_bundle))
- # c.url_yes = "/agency_overview/exportBundle/1"
- # c.url_no = "/agency_overview/"
- # return render('/casemanagement/dialogs/confirm.mako')
-
- @checkRole(('pb_ka'))
- def deleteBundle(self, confirmed):
- confirmed = self._checkBool(confirmed)
- agency_bundle = session.get('agencybundle')
- c.context = "../main.mako"
- if confirmed == 1:
- try:
- num = agency_bundle.delete()
- c.success_for = DELETE_SUCCSESS
- c.success_text = DELETE_SUCCSESS_EXPLAINATION % str(num)
- c.url_ok = "/agency_overview/"
- return render('/casemanagement/dialogs/success_delete_agency.mako')
- except StandardError, err:
- c.failed_for = DELETE_ERROR
- c.failed_text = DELETE_ERROR_EXPLAINATION
- c.url_ok = "/agency_overview/"
- return render('/casemanagement/dialogs/failed_delete_agency.mako')
- else:
- c.confirm_for = DIALOG_CONFIRM_DELETE
- c.question = DIALOG_CONFIRM_DELETE_EXPLAINATION % "\n".join(self._buildAgencyList(agency_bundle))
- c.url_yes = "/agency_overview/deleteBundle/1"
- c.url_no = "/agency_overview/"
- return render('/casemanagement/dialogs/confirm.mako')
-
- def _buildAgencyList(self, bundle):
- list = ["<ul>"]
- for agency in bundle.getAgencys():
- list.append("<li>%s</li>" % (agency.fkz))
- list.append("</ul>")
- return list
-
-# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
More information about the Mpuls-commits
mailing list