Пример #1
0
    def get_table(self, **kwargs):
        # set some custom attributes for template rendering
        table = super(LogsIndexView, self).get_table(**kwargs)
        table.title = Tag(tag='i', attrs={"class": [IconEnum.LOGS.value]
                                          }) + _(' Logs')

        render_helper = RenderHelper(user_permissions=list(
            filter(None, self.request.user.get_all_permissions())),
                                     update_url_qs=get_current_view_args(
                                         self.request))

        # append export links
        query_trailer_sign = "?"
        if self.request.GET:
            query_trailer_sign = "&"
        csv_download_link = Link(url=self.request.get_full_path() +
                                 f"{query_trailer_sign}_export=csv",
                                 content=".csv")
        json_download_link = Link(url=self.request.get_full_path() +
                                  f"{query_trailer_sign}_export=json",
                                  content=".json")

        dropdown = Dropdown(btn_value=Tag(
            tag='i', attrs={"class": [IconEnum.DOWNLOAD.value]}) +
                            _(" Export as"),
                            items=[csv_download_link, json_download_link],
                            needs_perm=PermissionEnum.CAN_ACCESS_LOGS.value)
        table.actions = [render_helper.render_item(item=dropdown)]
        return table
Пример #2
0
 def show_pending_requests(self):
     icon = Tag(tag='i', attrs={
         "class": [IconEnum.PUBLISHERS.value]
     }).render()
     count = Badge(
         content=f" {PublishRequest.objects.filter(group=self).count()}",
         color=BadgeColorEnum.SECONDARY).render()
     st_text = Tag(tag='div',
                   attrs={
                       "class": ['d-lg-none']
                   },
                   content=icon + count).render()
     gt_text = Tag(tag='div',
                   attrs={
                       "class": ['d-none', 'd-lg-block']
                   },
                   content=icon + _(' pending requests').__str__() +
                   count).render()
     return LinkButton(
         url=
         f"{reverse('structure:publish_request_overview')}?group={self.pk}",
         content=f"{st_text}{gt_text}",
         color=ButtonColorEnum.INFO,
         tooltip=_(f"see pending requests for {self}"),
         needs_perm=PermissionEnum.CAN_REQUEST_TO_BECOME_PUBLISHER.value)
Пример #3
0
 def status_icons(self):
     json_description = json.loads(self.description)
     if 'ERROR' in json_description.get('phase', ""):
         status = [Tag(tag='i', attrs={"class": [IconEnum.ERROR.value, TextColorEnum.DANGER.value]},
                       tooltip='This task stopped with error.', )]
     else:
         status = [Tag(tag='i', attrs={"class": [IconEnum.PLAY.value, TextColorEnum.SUCCESS.value]},
                       tooltip='This task is still running.', )]
     return status
Пример #4
0
 def get_add_action(cls):
     icon = Tag(tag='i', attrs={"class": [IconEnum.ADD.value]}).render()
     st_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=icon).render()
     gt_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                   content=icon + _(' new group invitation').__str__()).render()
     return LinkButton(content=st_text + gt_text,
                       color=ButtonColorEnum.SUCCESS,
                       url=reverse('structure:group_invitation_request_new'),
                       needs_perm=PermissionEnum.CAN_ADD_USER_TO_GROUP.value)
Пример #5
0
 def get_add_action(cls):
     icon = Tag(tag='i', attrs={"class": [IconEnum.ADD.value]}).render()
     st_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=icon).render()
     gt_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                   content=icon + _(' new publisher request').__str__()).render()
     return LinkButton(content=st_text + gt_text,
                       color=ButtonColorEnum.SUCCESS,
                       url=reverse('structure:publish_request_new'),
                       needs_perm=PermissionEnum.CAN_REQUEST_TO_BECOME_PUBLISHER.value)
Пример #6
0
 def new_publisher_request_action(self):
     add_icon = Tag(tag='i', attrs={"class": [IconEnum.ADD.value]}).render()
     st_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=add_icon).render()
     gt_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']}, content=add_icon + _(' become publisher').__str__()).render()
     return LinkButton(url=self.new_publisher_requesst_uri,
                       content=st_text + gt_text,
                       color=ButtonColorEnum.SUCCESS,
                       tooltip=_("Become rights to publish"),
                       needs_perm=PermissionEnum.CAN_REQUEST_TO_BECOME_PUBLISHER.value)
Пример #7
0
 def render_health_state_code(self, value):
     if value == HealthStateEnum.WARNING.value:
         icon = Tag(
             tag='i',
             attrs={
                 "class":
                 [TextColorEnum.WARNING.value, IconEnum.WARNING.value]
             },
             tooltip=_('This is a warning reason.'))
     elif value == HealthStateEnum.CRITICAL.value:
         icon = Tag(
             tag='i',
             attrs={
                 "class":
                 [TextColorEnum.DANGER.value, IconEnum.CRITICAL.value]
             },
             tooltip=_('This is a critical reason.'))
     elif value == HealthStateEnum.UNAUTHORIZED.value:
         icon = Tag(
             tag='i',
             attrs={
                 "class":
                 [TextColorEnum.INFO.value, IconEnum.PASSWORD.value]
             },
             tooltip=
             _('This check runs without getting state relevant results, cause the service needs an authentication for this request.'
               ))
     else:
         icon = Tag(tag='i',
                    attrs={
                        "class":
                        [TextColorEnum.SUCCESS.value, IconEnum.OK.value]
                    },
                    tooltip=_('Good standing health.'))
     return icon.render(safe=True)
Пример #8
0
 def get_actions(self):
     return [LinkButton(url=self.get_edit_view_url(),
                        content=Tag(tag='i', attrs={"class": [IconEnum.EDIT.value]}).render(),
                        color=ButtonColorEnum.WARNING,
                        size=ButtonSizeEnum.SMALL,
                        tooltip=_l(f"Edit subscription"), ),
             LinkButton(url=self.get_delete_view_url(),
                        content=Tag(tag='i', attrs={"class": [IconEnum.DELETE.value]}).render(),
                        color=ButtonColorEnum.DANGER,
                        size=ButtonSizeEnum.SMALL,
                        tooltip=_l(f"Delete subscription"), )]
Пример #9
0
    def render_related_objects(self, value):
        link_list = []
        for metadata in value:
            if metadata.metadata_type == MetadataEnum.FEATURETYPE.value:
                kind_of_resource_icon = IconEnum.FEATURETYPE.value
                kind_of_resource = "Featuretype"
            elif metadata.metadata_type == MetadataEnum.LAYER.value:
                kind_of_resource_icon = IconEnum.LAYER.value
                kind_of_resource = "Layer"
            else:
                kind_of_resource_icon = ""
                kind_of_resource = ""
            kind_of_resource_icon = Tag(
                tag='i',
                attrs={
                    "class": [kind_of_resource_icon]
                },
            ).render()

            link_list.append(
                Link(
                    url=metadata.detail_view_uri,
                    content=format_html(kind_of_resource_icon +
                                        f" {metadata.title} [{metadata.id}]"),
                    tooltip=
                    _(f'Click to open the detail view of related {kind_of_resource} <strong>{metadata.title} [{metadata.id}]"</strong>'
                      ),
                ), )
        return format_html(
            self.render_helper.render_list_coherent(items=link_list))
Пример #10
0
 def render_metadatas__all(self, value):
     links = []
     for metadata in value:
         links.append(
             Tag(tag='span',
                 attrs={"class": ['mr-1']},
                 content=Link(url=metadata.get_absolute_url(),
                              content=metadata).render() + ','))
     return format_html(
         self.render_helper.render_list_coherent(items=links))
Пример #11
0
    def get_table(self, **kwargs):
        # set some custom attributes for template rendering
        table = super(AllowedOperationTableView, self).get_table(**kwargs)

        table.title = Tag(tag='i', attrs={"class": [IconEnum.ACCESS.value]}).render() + f' Allowed Operations for {self.root_metadata}'

        render_helper = RenderHelper(user_permissions=list(filter(None, self.request.user.get_all_permissions())),
                                     update_url_qs=get_current_view_args(self.request))
        #table.actions = [render_helper.render_item(item=Metadata.get_add_resource_action())]
        return table
Пример #12
0
class GroupPublishRightsForTableView(DependingListView, GroupDetailContextMixin, CustomSingleTableMixin, FilterView):
    model = Organization
    depending_model = MrMapGroup
    table_class = PublishesForTable
    filterset_fields = {'organization_name': ['icontains']}
    template_name = 'MrMap/detail_views/table_tab.html'
    object = None
    title = Tag(tag='i', attrs={"class": [IconEnum.PUBLISHERS.value]}) + _(' Publish for list')

    def get_queryset(self):
        return self.object.publish_for_organizations.all()
Пример #13
0
class OrganizationMembersTableView(DependingListView, OrganizationDetailContextMixin, CustomSingleTableMixin, FilterView):
    model = MrMapUser
    depending_model = Organization
    table_class = OrganizationMemberTable
    filterset_fields = {'username': ['icontains']}
    template_name = 'MrMap/detail_views/table_tab.html'
    object = None
    title = Tag(tag='i', attrs={"class": [IconEnum.PENDING_TASKS.value]}) + _(' Members')

    def get_queryset(self):
        return self.object.primary_users.all()

    def get_table_kwargs(self):
        return {'organization': self.object}
Пример #14
0
    def get_actions(self):
        add_icon = Tag(tag='i', attrs={"class": [IconEnum.ADD.value]}).render()
        st_pub_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=add_icon).render()
        gt_pub_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                          content=add_icon + _(' become publisher').__str__()).render()
        edit_icon = Tag(tag='i', attrs={"class": [IconEnum.EDIT.value]}).render()
        st_edit_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=edit_icon).render()
        gt_edit_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                           content=edit_icon + _(' edit').__str__()).render()
        actions = [
            LinkButton(url=f"{reverse('structure:publish_request_new',)}?organization={self.id}",
                       content=st_pub_text + gt_pub_text,
                       color=ButtonColorEnum.SUCCESS,
                       size=ButtonSizeEnum.SMALL,
                       tooltip=format_html(
                           _(f"Become publisher for organization <strong>{self.organization_name} [{self.id}]</strong>")),
                       tooltip_placement=TooltipPlacementEnum.LEFT,
                       needs_perm=PermissionEnum.CAN_REQUEST_TO_BECOME_PUBLISHER.value),
            LinkButton(url=self.edit_view_uri,
                       content=st_edit_text + gt_edit_text,
                       color=ButtonColorEnum.WARNING,
                       size=ButtonSizeEnum.SMALL,
                       tooltip=format_html(_(f"Edit <strong>{self.organization_name} [{self.id}]</strong> organization")),
                       tooltip_placement=TooltipPlacementEnum.LEFT,
                       needs_perm=PermissionEnum.CAN_EDIT_ORGANIZATION.value),
        ]

        if not self.is_auto_generated:
            remove_icon = Tag(tag='i', attrs={"class": [IconEnum.DELETE.value]}).render()
            st_remove_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=remove_icon).render()
            gt_remove_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                                 content=remove_icon + _(' remove').__str__()).render()
            actions.append(LinkButton(url=self.remove_view_uri,
                                      content=st_remove_text + gt_remove_text,
                                      color=ButtonColorEnum.DANGER,
                                      size=ButtonSizeEnum.SMALL,
                                      tooltip=format_html(_(f"Remove <strong>{self.organization_name} [{self.id}]</strong> organization")),
                                      tooltip_placement=TooltipPlacementEnum.LEFT,
                                      needs_perm=PermissionEnum.CAN_DELETE_ORGANIZATION.value))
        return actions
Пример #15
0
 def render_actions(self, record):
     return Modal(
         fetch_url=reverse('editor:restrict-access-spatially',
                           args=(
                               self.related_metadata.id,
                               record.id,
                           )),
         btn_attrs={
             "class": [ButtonColorEnum.INFO.value]
         },
         btn_content=Tag(tag='i', attrs={
             "class": [IconEnum.EDIT.value]
         }).render(),
         size=ModalSizeEnum.LARGE,
         needs_perm=PermissionEnum.CAN_EDIT_METADATA,
         btn_tooltip=format_html(
             _(f"Edit access for group <strong>{record.name}</strong>"),
         )).render(safe=True)
Пример #16
0
 def render_name(self, record):
     url = reverse('structure:group_details', args=(record.id, ))
     icon = ''
     tooltip = _(
         'Click to open the detail view of <strong>{}</strong>'.format(
             record.name))
     if record.is_public_group:
         icon = Tag(tag='i', attrs={
             "class": [IconEnum.PUBLIC.value]
         }).render()
         tooltip = _('This is the anonymous public user group.'
                     ) + " {}".format(tooltip)
     return Link(
         tooltip=tooltip,
         url=url,
         content=format_html("{} {}".format(icon, record.name)),
         needs_perm=None,
         open_in_new_tab=True,
     ).render(safe=True)
Пример #17
0
 def icon(self):
     return Tag(tag='i', attrs={"class": [IconEnum.MONITORING_RUN.value]}).render()
Пример #18
0
 def icon(self):
     return Tag(tag='i', attrs={"class": [IconEnum.HEARTBEAT.value]}).render()
Пример #19
0
 def get_add_action(cls):
     return LinkButton(content=Tag(tag='i', attrs={"class": [IconEnum.ADD.value]}) + _(' New run').__str__(),
                       color=ButtonColorEnum.SUCCESS,
                       url=reverse('monitoring:run_new'),
                       needs_perm=PermissionEnum.CAN_RUN_MONITORING.value)
Пример #20
0
    def get_actions(self, request: HttpRequest):
        actions = []
        if not self.is_permission_group:
            edit_icon = Tag(tag='i', attrs={"class": [IconEnum.EDIT.value]}).render()
            st_edit_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=edit_icon).render()
            gt_edit_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']}, content=edit_icon + _(' Edit').__str__()).render()
            actions.append(LinkButton(url=self.edit_view_uri,
                                      content=st_edit_text + gt_edit_text,
                                      color=ButtonColorEnum.WARNING,
                                      tooltip=_(f"Edit <strong>{self.name}</strong>"),
                                      needs_perm=PermissionEnum.CAN_EDIT_GROUP.value))
            delete_icon = Tag(tag='i', attrs={"class": [IconEnum.DELETE.value]}).render()
            st_delete_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=delete_icon).render()
            gt_delete_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']}, content=delete_icon + _(' Delete').__str__()).render()
            actions.append(LinkButton(url=self.remove_view_uri,
                                      content=st_delete_text + gt_delete_text,
                                      color=ButtonColorEnum.DANGER,
                                      tooltip=_(f"Remove <strong>{self.name}</strong>"),
                                      needs_perm=PermissionEnum.CAN_DELETE_GROUP.value))

            if request.user not in self.user_set.all():
                add_user_icon = Tag(tag='i', attrs={"class": [IconEnum.USER_ADD.value]}).render()
                st_add_user_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=add_user_icon).render()
                gt_add_user_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                                       content=delete_icon + _(' become member').__str__()).render()
                actions.append(LinkButton(url=f"{reverse('structure:group_invitation_request_new')}?group={self.pk}&user={request.user.id}",
                                          content=st_add_user_text + gt_add_user_text,
                                          color=ButtonColorEnum.SUCCESS,
                                          tooltip=_(f"Become member of  <strong>{self.name}</strong>")))
            elif self.user_set.count() > 1:
                from MrMap.utils import signal_last
                groups_querystring = "groups"
                groups_excluded_self = request.user.groups.exclude(pk=self.pk)
                if groups_excluded_self:
                    groups_querystring = ""
                    for is_last_element, group in signal_last(groups_excluded_self):
                        if is_last_element:
                            groups_querystring += f"groups={group.pk}"
                        else:
                            groups_querystring += f"groups={group.pk}&"

                leave_icon = Tag(tag='i', attrs={"class": [IconEnum.USER_REMOVE.value]}).render()
                st_leave_text = Tag(tag='div', attrs={"class": ['d-lg-none']}, content=leave_icon).render()
                gt_leave_text = Tag(tag='div', attrs={"class": ['d-none', 'd-lg-block']},
                                    content=delete_icon + _(' leave group').__str__()).render()
                actions.append(LinkButton(
                    url=f"{reverse('edit_profile')}?{groups_querystring}",
                    content=st_leave_text + gt_leave_text,
                    color=ButtonColorEnum.SUCCESS,
                    tooltip=_(f"Become member of  <strong>{self.name}</strong>")))
        return actions