示例#1
0
 def get_buttons(self):
     return [
         bt.HyperlinkButton(endpoint="https://www.google.com",
                            label="Open Google"),
         bt.HyperlinkButton(endpoint="https://www.nytimes.com",
                            label="Open NYTimes"),
         bt.WidgetButton(key="self_endpoint", icon="wb-icon-data"),
     ]
示例#2
0
class RelatedModelTestButtonConfig(ButtonConfig):
    FSM_DROPDOWN = True
    CUSTOM_INSTANCE_BUTTONS = CUSTOM_LIST_INSTANCE_BUTTONS = {
        bt.DropDownButton(
            label="Dropdown",
            icon="wb-icon-triangle-down",
            buttons=(bt.DropDownButton(
                label="Dropdown",
                icon="wb-icon-triangle-down",
                buttons=(bt.ActionButton(
                    label="TestButton",
                    icon="wb-icon-trash",
                    endpoint="http://localhost:5000/relatedmodeltest/",
                    instance_display=dp.InstanceDisplay(sections=(dp.Section(
                        fields=dp.FieldSet(fields=("char_field",
                                                   "custom_field"))), )),
                    serializer=ActionButtonSerializer,
                ), ),
            ), ),
        ),
        bt.HyperlinkButton(key="html",
                           icon="wb-icon-trash",
                           label="Authenticated Subpage",
                           weight=1000),
    }

    CUSTOM_BUTTONS = {
        bt.ActionButton(
            label="TestButton",
            icon="wb-icon-trash",
            endpoint="http://localhost:5000/relatedmodeltest/",
            instance_display=dp.InstanceDisplay(sections=(dp.Section(
                fields=dp.FieldSet(fields=("char_field", "custom_field"))), )),
            serializer=ActionButtonSerializer,
        )
    }
 def something(self, instance, request, user):
     return [bt.HyperlinkButton(endpoint="https://www.google.com", icon="wb-icon-trash")]
示例#4
0
class StockModelViewSet(viewsets.ModelViewSet):
    DELETE_ENDPOINT = None
    ENDPOINT = 'djangoapp:stock-list'

    IDENTIFIER = "djangoapp:stock"
    INSTANCE_TITLE = "Stock : {{symbol}}"
    LIST_TITLE = "Stocks"
    CREATE_TITLE = "New Stock"

    LIST_DISPLAY = dp.ListDisplay(
        fields=[dp.Field(key="symbol", label="Symbol")], )

    INSTANCE_DISPLAY = dp.InstanceDisplay(sections=[
        dp.Section(fields=dp.FieldSet(fields=["symbol"])),
        dp.Section(title="Prices",
                   collapsed=True,
                   section_list=dp.SectionList(key="prices")),
    ])

    CUSTOM_LIST_INSTANCE_BUTTONS = CUSTOM_INSTANCE_BUTTONS = [
        bt.DropDownButton(
            label="Quick Action",
            icon=WBIcon.TRIANGLE_DOWN.value,
            buttons=[
                bt.WidgetButton(key="prices",
                                label="Prices",
                                icon=WBIcon.DOLLAR.value),
                bt.ActionButton(
                    method=RequestType.PATCH,
                    identifiers=["djangoapp:price"],
                    action_label="Modify Prices",
                    key="modifyprices",
                    title="Modify the Prices of a stock",
                    label="Modify Prices",
                    icon=WBIcon.CIRCLE_NO.value,
                    description_fields=
                    "<p> Do you want to modify the prices of {{symbol}}? </p>",
                    serializer=MultiplyPricesActionButtonSerializer,
                    confirm_config=bt.ButtonConfig(label="Confirm"),
                    cancel_config=bt.ButtonConfig(label="Cancel"),
                    instance_display=dp.InstanceDisplay(sections=[
                        dp.Section(fields=dp.FieldSet(
                            fields=["number_product"]))
                    ])),
                bt.WidgetButton(key="chartprices",
                                label="Prices Chart",
                                icon=WBIcon.STATS.value),
                bt.HyperlinkButton(endpoint="https://www.alphavantage.co/",
                                   label="AlphaVantage",
                                   icon=WBIcon.BANK.value),
            ])
    ]

    @action(methods=["PATCH"],
            permission_classes=[IsAuthenticated],
            detail=True)
    def modifyprices(self, request, pk=None):
        number_product = float(request.POST.get("number_product", 1))
        nbprice = Price.objects.filter(stock__id=pk).update(price=F('price') *
                                                            number_product)
        stock = Stock.objects.get(pk=pk)
        #print("Stock: " +str(stock)+ " -> nb of price: " + str(nbprice))
        if nbprice > 0:
            #print("Stock: " + str(stock) + " -> successful modify stock -> price multiplied by " + str(number_product))
            Notification.objects.create(
                title=f'Stock: {stock.symbol} Modify Prices',
                message=
                f'successful You have multiplied the prices of stock: {stock.symbol} -> price multiplied by ({number_product})',
                send_type=NotificationSendType.SYSTEM.value,
                recipient=request.user)
        return Response(
            {
                "__notification": {
                    stock.symbol: "successful modify stock",
                    'updated': True,
                    "number_product": number_product
                }
            },
            status=status.HTTP_200_OK)

    queryset = Stock.objects.all()
    serializer_class = StockModelSerializer

    filter_backends = [
        filters.OrderingFilter, filters.SearchFilter, DjangoFilterBackend
    ]
    ordering_fields = ['symbol']
    ordering = ['symbol']
    search_fields = ("symbol", )
    filterset_fields = {"symbol": ["exact", "icontains"]}

    def get_aggregates(self, queryset, **kwargs):
        return {
            "symbol": {
                "#": format_number(queryset.count())
            },
        }
示例#5
0
def test_adding_instance_buttons_ep(sender, many, *args, **kwargs):
    return bt.HyperlinkButton(icon="wb-icon-trash",
                              label="Far away button (EP)",
                              endpoint="https://www.google.com",
                              weight=1)
示例#6
0
def test_adding_instance_buttons_key(sender, many, *args, **kwargs):
    return bt.HyperlinkButton(icon="wb-icon-trash",
                              label="Far away button (KEY)",
                              key="some-key",
                              weight=100000)