Aller au contenu

Views

CanCreateMixin

Bases: View

Protect any child view that would create an object.

Raises:

Type Description
PermissionDenied

If the user has not the necessary permission to create the object of the view.

CanEditMixin

Bases: GenericContentPermissionMixinBuilder

Ensure the user has permission to edit this view's object.

Raises:

Type Description
PermissionDenied

if the user cannot edit this view's object.

CanEditPropMixin

Bases: GenericContentPermissionMixinBuilder

Ensure the user has owner permissions on the child view object.

In other word, you can make a view with this view as parent, and it will be retricted to the users that are in the object's owner_group or that pass the obj.can_be_viewed_by test.

Raises:

Type Description
PermissionDenied

If the user cannot see the object

CanViewMixin

Bases: GenericContentPermissionMixinBuilder

Ensure the user has permission to view this view's object.

Raises:

Type Description
PermissionDenied

if the user cannot edit this view's object.

ProductType

Bases: Model

A product type.

Useful only for categorizing.

is_owned_by(user)

Method to see if that object can be edited by the given user.

Source code in counter/models.py
def is_owned_by(self, user):
    """Method to see if that object can be edited by the given user."""
    if user.is_anonymous:
        return False
    if user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
        return True
    return False

CounterAdminTabsMixin

CounterTabsMixin

ShoppingList

Bases: Model

The ShoppingList class, used to make an history of the shopping lists.

ShoppingListItem

Bases: Model

An Item on a shopping list.

Stock

Bases: Model

The Stock class, this one is used to know how many products are left for a specific counter.

StockItem

Bases: Model

The StockItem class, element of the stock.

StockItemList

Bases: CounterAdminTabsMixin, CanCreateMixin, ListView

The stockitems list view for the counter owner.

StockListView

Bases: CounterAdminTabsMixin, CanViewMixin, ListView

A list view for the admins.

StockEditForm(*args, **kwargs)

Bases: ModelForm

A form to change stock's characteristics.

Source code in stock/views.py
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

StockEditView

Bases: CounterAdminTabsMixin, CanEditPropMixin, UpdateView

An edit view for the stock.

StockItemEditView

Bases: CounterAdminTabsMixin, CanEditPropMixin, UpdateView

An edit view for a stock item.

StockCreateView

Bases: CounterAdminTabsMixin, CanCreateMixin, CreateView

A create view for a new Stock.

StockItemCreateView

Bases: CounterAdminTabsMixin, CanCreateMixin, CreateView

A create view for a new StockItem.

StockShoppingListView

Bases: CounterAdminTabsMixin, CanViewMixin, ListView

A list view for the people to know the item to buy.

StockItemQuantityForm

Bases: BaseForm

StockItemQuantityBaseFormView

Bases: CounterAdminTabsMixin, CanEditMixin, DetailView, BaseFormView

docstring for StockItemOutList.

get(request, *args, **kwargs)

Simple get view.

Source code in stock/views.py
def get(self, request, *args, **kwargs):
    """Simple get view."""
    self.stock = Stock.objects.filter(id=self.kwargs["stock_id"]).first()
    return super().get(request, *args, **kwargs)

post(request, *args, **kwargs)

Handle the many possibilities of the post request.

Source code in stock/views.py
def post(self, request, *args, **kwargs):
    """Handle the many possibilities of the post request."""
    self.object = self.get_object()
    self.stock = Stock.objects.filter(id=self.kwargs["stock_id"]).first()
    return super().post(request, *args, **kwargs)

StockShoppingListItemListView

Bases: CounterAdminTabsMixin, CanViewMixin, ListView

docstring for StockShoppingListItemListView.

StockShoppingListDeleteView

Bases: CounterAdminTabsMixin, CanEditMixin, DeleteView

Delete a ShoppingList (for the resonsible account).

StockShopppingListSetDone

Bases: CanEditMixin, DetailView

Set a ShoppingList as done.

StockShopppingListSetTodo

Bases: CanEditMixin, DetailView

Set a ShoppingList as done.

StockUpdateAfterShopppingForm

Bases: BaseForm

StockUpdateAfterShopppingBaseFormView

Bases: CounterAdminTabsMixin, CanEditMixin, DetailView, BaseFormView

docstring for StockUpdateAfterShopppingBaseFormView.

post(request, *args, **kwargs)

Handle the many possibilities of the post request.

Source code in stock/views.py
def post(self, request, *args, **kwargs):
    """Handle the many possibilities of the post request."""
    self.object = self.get_object()
    self.shoppinglist = ShoppingList.objects.filter(
        id=self.kwargs["shoppinglist_id"]
    ).first()
    return super().post(request, *args, **kwargs)

form_valid(form)

We handle here the redirection.

Source code in stock/views.py
def form_valid(self, form):
    """We handle here the redirection."""
    return super().form_valid(form)

StockTakeItemsForm

Bases: BaseForm

docstring for StockTakeItemsFormView.

StockTakeItemsBaseFormView

Bases: CounterTabsMixin, CanEditMixin, DetailView, BaseFormView

docstring for StockTakeItemsBaseFormView.

post(request, *args, **kwargs)

Handle the many possibilities of the post request.

Source code in stock/views.py
def post(self, request, *args, **kwargs):
    """Handle the many possibilities of the post request."""
    self.object = self.get_object()
    self.stock = Stock.objects.filter(id=self.kwargs["stock_id"]).first()
    if self.stock.counter.type == "BAR" and not (
        "counter_token" in self.request.session.keys()
        and self.request.session["counter_token"] == self.stock.counter.token
    ):  # Also check the token to avoid the bar to be stolen
        return HttpResponseRedirect(
            reverse_lazy(
                "counter:details",
                args=self.args,
                kwargs={"counter_id": self.stock.counter.id},
            )
            + "?bad_location"
        )
    return super().post(request, *args, **kwargs)