Ejemplo n.º 1
0
class CreateStoreTransactionLogMixin(object):
    DEFAULTS = {
        'item': StoreItem.all().values()[0].storeitem_id,
        'value': -1 * StoreItem.all().values()[0].cost,
        'purchased_at': datetime.datetime.now(),
        'context_type': 'unit',
        'context_id': 1,
    }

    @classmethod
    def create_store_transaction_log(cls, **kwargs):
        fields = CreateStoreTransactionLogMixin.DEFAULTS.copy()
        fields['user'] = kwargs.get("user")
        return StoreTransactionLog.objects.create(**fields)
Ejemplo n.º 2
0
    def alter_list_data_to_serialize(self, request, to_be_serialized):
        """Add username, user ID, facility name, and facility ID to responses"""
        store_items = StoreItem.all()
        for bundle in to_be_serialized["objects"]:
            user_id = bundle.data["user"].data["id"]
            user = self._facility_users.get(user_id)
            bundle.data["user_id"] = user_id
            bundle.data["person_name"] = user.get_name()
            bundle.data["username"] = user.username
            bundle.data["facility_name"] = user.facility.name
            bundle.data["facility_id"] = user.facility.id
            bundle.data["is_teacher"] = user.is_teacher
            item_id = bundle.data["item"].strip("/").split("/")[-1]
            bundle.data["item"] = item_id
            item = store_items.get(item_id)
            bundle.data["item_name"] = item.title if item else None
            bundle.data.pop("user")

        return to_be_serialized
Ejemplo n.º 3
0
    def alter_list_data_to_serialize(self, request, to_be_serialized):
        """Add username, user ID, facility name, and facility ID to responses"""
        store_items = StoreItem.all()
        for bundle in to_be_serialized["objects"]:
            user_id = bundle.data["user"].data["id"]
            user = self._facility_users.get(user_id)
            bundle.data["user_id"] = user_id
            bundle.data["person_name"] = user.get_name()
            bundle.data["username"] = user.username
            bundle.data["facility_name"] = user.facility.name
            bundle.data["facility_id"] = user.facility.id
            bundle.data["is_teacher"] = user.is_teacher
            item_id = bundle.data["item"].strip("/").split("/")[-1]
            bundle.data["item"] = item_id
            item = store_items.get(item_id)
            bundle.data["item_name"] = item.title if item else None
            bundle.data.pop("user")

        return to_be_serialized
Ejemplo n.º 4
0
def spending_report_detail_view(request, user_id):
    """View transaction logs for student"""
    student = get_object_or_404(FacilityUser, id=user_id)
    transactions = StoreTransactionLog.objects.filter(user=student, context_type='unit').order_by('purchased_at') # TODO(dylanjbarth): filter out gift cards?
    context = plotting_metadata_context(request)
    store_items = StoreItem.all()
    humanized_transactions = []
    for t in transactions:
        # Hydrate the store item object
        item_key = t.item.strip("/").split("/")[-1]
        humanized_transactions.append({
            "purchased_at": t.purchased_at,
            "item": store_items.get(item_key, ""),
            "value": abs(t.value),
            "context_id": t.context_id,
        })
    context.update({
        "student": student,
        "transactions": humanized_transactions,
    })
    return context
Ejemplo n.º 5
0
def spending_report_detail_view(request, user_id):
    """View transaction logs for student"""
    student = get_object_or_404(FacilityUser, id=user_id)
    transactions = StoreTransactionLog.objects.filter(user=student, context_type='unit').order_by('purchased_at') # TODO(dylanjbarth): filter out gift cards?
    context = plotting_metadata_context(request)
    store_items = StoreItem.all()
    humanized_transactions = []
    for t in transactions:
        # Hydrate the store item object
        item_key = t.item.strip("/").split("/")[-1]
        humanized_transactions.append({
            "purchased_at": t.purchased_at,
            "item": store_items.get(item_key, ""),
            "value": abs(t.value),
            "context_id": t.context_id,
        })
    context.update({
        "student": student,
        "transactions": humanized_transactions,
    })
    return context