コード例 #1
0
ファイル: config.py プロジェクト: nursix/eden
    def customise_dc_target_resource(r, tablename):

        from gluon import IS_EMPTY_OR, URL
        from s3 import IS_ISO639_2_LANGUAGE_CODE, S3SQLCustomForm, S3TextFilter

        from templates.UCCE.controllers import dc_target_list_layout
        from templates.UCCE.controllers import text_filter_formstyle

        current.response.s3.crud_strings[tablename] = Storage(
            label_create = T("Create Survey"),
            title_display = T("Survey Details"),
            #title_list = T("Surveys"),
            title_list = "",
            title_update = T("Edit Survey"),
            #title_upload = T("Import Surveys"),
            label_list_button = T("List Surveys"),
            label_delete_button = T("Delete Survey"),
            msg_record_created = T("Survey added"),
            msg_record_modified = T("Survey updated"),
            msg_record_deleted = T("Survey deleted"),
            msg_list_empty = T("No Surveys currently registered"))

        s3db = current.s3db

        # Lift mandatory link to template so that we can create the template onaccept
        #s3db.dc_target.template_id.requires

        s3db.dc_target_l10n.language.requires = IS_EMPTY_OR(IS_ISO639_2_LANGUAGE_CODE(select = l10n_options,
                                                                                      sort = True,
                                                                                      translate = False,
                                                                                      zero = "",
                                                                                      ))

        # Custom Component
        s3db.add_components("dc_target",
                            dc_target_l10n = {"joinby": "target_id",
                                              "multiple": False,
                                              },
                            )

        s3db.configure("dc_target",
                       create_next = URL(c="dc", f="template", vars={"target_id": "[id]"}),
                       crud_form = S3SQLCustomForm((T("Survey name"), "name"),
                                                   (T("Translation"), "target_l10n.language"),
                                                   postprocess = dc_target_postprocess,
                                                   ),
                       listadd = False,
                       list_fields = ["name",
                                      #"status",
                                      "project_target.project_id",
                                      ],
                       list_layout = dc_target_list_layout,
                       ondelete = dc_target_ondelete,
                       filter_widgets = [S3TextFilter(["name",
                                                       "project.name",
                                                       ],
                                                      formstyle = text_filter_formstyle,
                                                      label = "",
                                                      _placeholder = T("Search project or survey"),
                                                      ),
                                         ],
                       )
コード例 #2
0
        def custom_prep(r):
            # Call standard prep
            if callable(standard_prep):
                result = standard_prep(r)
                if not result:
                    return False

            s3db = current.s3db

            # Hack to provide additional languages for L10n location names
            # without activating them in the GUI
            l10n_languages = dict(settings.L10n.languages)
            l10n_languages["ky"] = "Kyrgyz"
            l10n_languages["ru"] = "Russian"
            l10n_languages["hy"] = "Armenian"
            l10n_languages["az"] = "Azerbaijani"
            l10n_languages["ka"] = "Georgian"
            l10n_languages["kk"] = "Kazakh"
            l10n_languages["tg"] = "Tajik"
            l10n_languages["tk"] = "Turkmen"
            l10n_languages["uk"] = "Ukraine"
            l10n_languages["uz"] = "Uzbek"
            from s3 import IS_ISO639_2_LANGUAGE_CODE
            s3db.gis_location_name.language.requires = IS_ISO639_2_LANGUAGE_CODE(
                select=l10n_languages)

            if r.interactive or r.representation == "aadata":
                if r.vars.get("location.level__ne"):
                    s3.crud_strings["gis_location"] = Storage(
                        title_list=T("Administrative Areas"), )
                else:
                    s3.crud_strings["gis_location"] = Storage(
                        #label_create = T("Record Disaster"),
                        #title_display = T("Disaster Details"),
                        title_list=T("Locations"))

                    # Remove level column & filter
                    list_fields = s3db.get_config("gis_location",
                                                  "list_fields")
                    list_fields.remove("level")

                    filter_widgets = s3db.get_config("gis_location",
                                                     "filter_widgets")
                    # NB Fragile: dependent on filters defined in gis/location controller
                    filter_widgets.pop(1)
            if r.method != "import":
                table = s3db.gis_location
                # Custom filtered components for custom list_fields
                s3db.add_components(
                    "gis_location",
                    gis_location_name={
                        "name": "name_ru",
                        "joinby": "location_id",
                        "filterby": "language",
                        "filterfor": ("ru", ),
                    },
                    gis_location_tag=(
                        {
                            "name": "pcode",
                            "joinby": "location_id",
                            "filterby": "tag",
                            "filterfor": ("PCode", ),
                        },
                        {
                            "name": "lat_lon_source",
                            "joinby": "location_id",
                            "filterby": "tag",
                            "filterfor": ("LatLon Source", ),
                        },
                        {
                            "name": "lat_lon_date",
                            "joinby": "location_id",
                            "filterby": "tag",
                            "filterfor": ("LatLon Date", ),
                        },
                    ),
                )

                from s3 import S3MultiSelectWidget, S3SQLCustomForm, S3SQLInlineComponent
                table.parent.widget = S3MultiSelectWidget(multiple=False)

                crud_form = S3SQLCustomForm(
                    "name",
                    #"name_ru.name_l10n",
                    S3SQLInlineComponent(
                        "name_ru",
                        label=T("Russian Name"),
                        multiple=False,
                        fields=[("", "name_l10n")],
                    ),
                    "level",
                    S3SQLInlineComponent(
                        "pcode",
                        label=T("PCode"),
                        multiple=False,
                        fields=[("", "value")],
                    ),
                    S3SQLInlineComponent(
                        "lat_lon_source",
                        label=T("Lat/Lon Source"),
                        multiple=False,
                        fields=[("", "value")],
                    ),
                    S3SQLInlineComponent(
                        "lat_lon_date",
                        label=T("Lat/Lon Date"),
                        multiple=False,
                        fields=[("", "value")],
                    ),
                    #"pcode.value",
                    "parent",
                )

                NONE = current.messages["NONE"]
                levels = current.gis.get_location_hierarchy()
                table.level.represent = lambda l: levels[l] if l else NONE

                #field = table.inherited
                #field.label =  T("Mapped?")
                #field.represent =  lambda v: T("No") if v else T("Yes")

                filter_widgets = s3db.get_config("gis_location",
                                                 "filter_widgets")
                # Remove L2 & L3 filters
                # NB Fragile: dependent on filters defined in gis/location controller
                filter_widgets.pop()
                filter_widgets.pop()

                s3db.configure(
                    "gis_location",
                    crud_form=crud_form,
                    filter_widgets=filter_widgets,
                    list_fields=[
                        "name",
                        # @ToDo: Investigate whether we can support this style & hence not need to define custom components
                        #(T("Russian Name"), "name.name_l10n?location_name.language=ru"),
                        #("PCode", "tag.value?location_tag.tag=PCode"),
                        (T("Russian Name"), "name_ru.name_l10n"),
                        "level",
                        ("PCode", "pcode.value"),
                        "L0",
                        "L1",
                        "L2",
                        "inherited",
                    ])
            return True
コード例 #3
0
ファイル: config.py プロジェクト: nursix/eden
    def customise_project_project_resource(r, tablename):

        from gluon import IS_EMPTY_OR, URL
        from s3 import IS_ISO639_2_LANGUAGE_CODE, S3SQLCustomForm, S3TextFilter

        from templates.UCCE.controllers import project_project_list_layout
        from templates.UCCE.controllers import text_filter_formstyle

        s3db = current.s3db

        s3db.project_l10n.language.requires = IS_EMPTY_OR(IS_ISO639_2_LANGUAGE_CODE(select = l10n_options,
                                                                                    sort = True,
                                                                                    translate = False,
                                                                                    zero = "",
                                                                                    ))

        # Custom Component
        s3db.add_components("project_project",
                            project_l10n = {"joinby": "project_id",
                                            "multiple": False,
                                            },
                            )

        current.response.s3.crud_strings[tablename] = Storage(
            label_create = T("New project"),
            #title_display = T("Project Details"),
            # Only used in /target/create?
            title_display = T("Editor"),
            #title_list = T("Projects"),
            title_list = "",
            title_update = T("Edit project name"),
            #title_upload = T("Import Projects"),
            label_list_button = T("List Projects"),
            label_delete_button = T("Delete Projects"),
            msg_record_created = T("Project added"),
            msg_record_modified = T("Project updated"),
            msg_record_deleted = T("Project deleted"),
            msg_list_empty = T("No Projects currently registered")
        )

        user = current.auth.user
        organisation_id = user and user.organisation_id
        if organisation_id:
            f = s3db.project_project.organisation_id
            f.default = organisation_id
            f.readable = f.writable = False

        s3db.configure("project_project",
                       create_next = URL(args="datalist"),
                       # No need to chain as default one not relevant for this usecase:
                       create_onaccept = project_project_onaccept,
                       crud_form = S3SQLCustomForm((T("Organization"), "organisation_id"),
                                                   (T("New project name"), "name"),
                                                   (T("Default Translation"), "l10n.language"),
                                                   ),
                       # Ignored here as set in Prep in default controller
                       #list_fields = ["name",
                       #               "project_target.target_id",
                       #               ],
                       list_layout = project_project_list_layout,
                       ondelete = project_project_ondelete,
                       filter_widgets = [S3TextFilter(["name",
                                                       "target.name",
                                                       ],
                                                      formstyle = text_filter_formstyle,
                                                      label = "",
                                                      _placeholder = T("Search project or survey"),
                                                      ),
                                         ],
                       )

        s3db.configure("project_project_target",
                       create_onaccept = project_project_target_create_onaccept,
                       )