def get(self, *args, **kwargs): company = get_company_or_404(self.request) if not can_modify(self.request.user, company, kwargs, "update product", "create product"): return MissingActivity() return super(ProductFormView, self).get(*args, **kwargs)
def post(self, *args, **kwargs): company = get_company_or_404(self.request) if not can_modify(self.request.user, company, kwargs, "update job", "create job"): return MissingActivity() return super(JobFormView, self).post(*args, **kwargs)
def view_request(request, pk, model=None): template = 'postajob/request/{model}.html' company = get_company(request) model = model or Request request_kwargs = {'pk': pk, 'owner': company} request_made = get_object_or_404(model, **request_kwargs) if model == Request: activity = "read request" request_object = request_made.request_object() else: activity = "read offline purchase" request_object = request_made content_type = ContentType.objects.get_for_model(type(request_object)) data = { 'company': company, 'content_type': content_type, 'object': request_object, 'request_obj': request_made, } if not request.user.can(company, activity): return MissingActivity() return render_to_response(template.format(model=content_type.model), data, RequestContext(request))
def purchasedmicrosite_admin_overview(request): company = settings.SITE.canonical_company has_access = request.user.can(company, 'read product', 'read request', 'read offline purchase', 'read purchased product', 'read grouping', compare=at_least_one) if not has_access: return MissingActivity() sites = settings.SITE.postajob_site_list() products = Product.objects.filter_by_sites(sites) purchased = PurchasedProduct.objects.filter_by_sites(sites) groupings = ProductGrouping.objects.filter_by_sites(sites) offline_purchases = OfflinePurchase.objects.filter_by_sites(sites) requests = Request.objects.filter_by_sites(sites) data = { 'products': products.filter(owner=company)[:3], 'product_groupings': groupings.filter(owner=company)[:3], 'purchased_products': purchased.filter(product__owner=company)[:3], 'offline_purchases': offline_purchases.filter(owner=company)[:3], 'requests': requests.filter(owner=company)[:3], 'company': company } return render_to_response('postajob/admin_overview.html', data, RequestContext(request))
def purchasedjobs_overview(request, purchased_product, admin): """ Normally we would need to filter by settings.SITE for objects in postajob but this is already done from a previous view. """ product = PurchasedProduct.objects.prefetch_related( 'purchasedjob_set').get(pk=purchased_product) if admin: company = product.product.owner else: company = product.owner if not request.user.can(company, 'read purchased job'): return MissingActivity() jobs = product.purchasedjob_set.all() data = { 'company': company, 'purchased_product': product, 'active_jobs': jobs.filter(is_expired=False), 'expired_jobs': jobs.filter(is_expired=True) } if admin: return render_to_response('postajob/purchasedjobs_admin_overview.html', data, RequestContext(request)) else: return render_to_response('postajob/purchasedjobs_overview.html', data, RequestContext(request))
def post(self, *args, **kwargs): company = get_company_or_404(self.request) if not can_modify(self.request.user, company, kwargs, "update offline purchase", "create offline purchase"): return MissingActivity() return super(OfflinePurchaseFormView, self).post(*args, **kwargs)
def delete(self, request): company = get_company_or_404(self.request) if self.request.user.can(company, 'delete grouping'): return super(ProductGroupingFormView, self).delete(request) return MissingActivity()