def edit_location(request): company, partner, _ = prm_worthy(request) contact = get_object_or_none(Contact, id=request.REQUEST.get("id")) location = get_object_or_none(Location, id=request.REQUEST.get("location")) if request.method == "POST": if location: form = LocationForm(request.POST, instance=location) else: form = LocationForm(request.POST) if form.is_valid(): location = form.save(request) if location not in contact.locations.all(): contact.locations.add(location) contact.save() return HttpResponseRedirect(reverse("edit_contact") + "?partner=%s&id=%s" % (partner.id, contact.id)) else: form = LocationForm(instance=location) ctx = {"form": form, "company": company, "partner": str(partner.id)} if contact: ctx["contact"] = str(contact.id) if location: ctx["location"] = str(location.id) return render_to_response("mypartners/edit_location.html", ctx, RequestContext(request))
def __init__(self, filepath, js_field=None, crawl_field=None, node_tag=None, datetime_pattern=None, jsid=None, schema=None, markdown=True, company=None): if None in (js_field, crawl_field, datetime_pattern): raise AttributeError("You must specify valid values for js_field, " "datetime_pattern and crawl_field.") self.filepath = filepath self.bu_mapped_mocs = None self.parser = etree.XMLParser(recover=False, schema=schema) self.doc = etree.parse(self.filepath, self.parser) self.datetime_pattern = datetime_pattern self.jsid = jsid self.node_tag = node_tag self.job_source_name = self.unescape(self.parse_doc(js_field)) self.crawled_date = get_strptime(self.parse_doc(crawl_field), self.datetime_pattern) self.markdown = markdown self.company = company if jsid is None: jsid = self.parse_doc('job_source_id') if jsid: self.jsid = int(jsid) else: self.jsid = jsid self.bu = (get_object_or_none(BusinessUnit, pk=self.jsid) if self.jsid is not None else None)
def product_listing(request): site = settings.SITE company = site.canonical_company # Get all site packages and products for a site. site_packages = site.sitepackage_set.all() products = Product.objects.filter(package__sitepackage__in=site_packages) # Group products by the site package they belong to. groupings = set() for product in products: profile = get_object_or_none(CompanyProfile, company=product.owner) if product.cost < 0.01 or (profile and profile.authorize_net_login and profile.authorize_net_transaction_key): groupings = groupings.union( set( product.productgrouping_set.filter( is_displayed=True, products__isnull=False))) # Sort the grouped packages by the specified display order. groupings = sorted(groupings, key=lambda grouping: grouping.display_order) return render_to_response('postajob/package_list.html', { 'product_groupings': groupings, 'company': company }, RequestContext(request))
def product_listing(request): site = settings.SITE company = site.canonical_company # Get all site packages and products for a site. site_packages = site.sitepackage_set.all() products = Product.objects.filter(package__sitepackage__in=site_packages) # Group products by the site package they belong to. groupings = set() for product in products: profile = get_object_or_none(CompanyProfile, company=product.owner) if product.cost < 0.01 or (profile and profile.authorize_net_login and profile.authorize_net_transaction_key): groupings = groupings.union( set(product.productgrouping_set.filter(is_displayed=True, products__isnull=False))) # Sort the grouped packages by the specified display order. groupings = sorted(groupings, key=lambda grouping: grouping.display_order) return render_to_response('postajob/package_list.html', {'product_groupings': groupings, 'company': company}, RequestContext(request))
def clean_redemption_id(self): redemption_id = self.cleaned_data.get("redemption_id") offline_purchase = get_object_or_none( OfflinePurchase, redemption_uid=redemption_id, redeemed_by=None, redeemed_on=None ) if not offline_purchase: raise ValidationError("The redemption id you entered is invalid.") return offline_purchase
def request_object(self): """ Gets the object referred to by the request. Because this is not a true ForeignKey, this object may not exist. """ from universal.helpers import get_object_or_none return get_object_or_none(self.content_type.model_class(), pk=self.object_id)
def clean_redemption_id(self): redemption_id = self.cleaned_data.get('redemption_id') offline_purchase = get_object_or_none(OfflinePurchase, redemption_uid=redemption_id, redeemed_by=None, redeemed_on=None) if not offline_purchase: raise ValidationError('The redemption id you entered is invalid.') return offline_purchase
def clean_cost(self): cost = self.cleaned_data.get("cost") profile = get_object_or_none(CompanyProfile, company=self.cleaned_data.get("owner")) # cost comes through as a Decimal, which has a handy is_zero method; # cost is required, so we don't have to worry about None if not cost.is_zero() and ( not profile or not (profile.authorize_net_login and profile.authorize_net_transaction_key) ): raise ValidationError( "This company does not have Authorize.net " "credentials defined - product must be free" ) return cost
def email_domain_choices(self,): from postajob.models import CompanyProfile profile = get_object_or_none(CompanyProfile, company=self.canonical_company) email_domain_field = SeoSite._meta.get_field('email_domain') choices = [ (email_domain_field.get_default(), email_domain_field.get_default()), (self.domain, self.domain), ] if profile and profile.outgoing_email_domain: choices.append((profile.outgoing_email_domain, profile.outgoing_email_domain)) return choices
def clean_cost(self): cost = self.cleaned_data.get('cost') profile = get_object_or_none(CompanyProfile, company=self.cleaned_data.get('owner')) # cost comes through as a Decimal, which has a handy is_zero method; # cost is required, so we don't have to worry about None if not cost.is_zero() and ( not profile or not (profile.authorize_net_login and profile.authorize_net_transaction_key)): raise ValidationError('This company does not have Authorize.net ' 'credentials defined - product must be free') return cost
def edit_location(request): company, partner, _ = prm_worthy(request) contact = get_object_or_none(Contact, id=request.REQUEST.get('id')) location = get_object_or_none( Location, id=request.REQUEST.get('location')) if request.method == 'POST': if location: form = LocationForm(request.POST, instance=location) else: form = LocationForm(request.POST) if form.is_valid(): location = form.save(request) if location not in contact.locations.all(): contact.locations.add(location) contact.update_last_action_time() content_id = ContentType.objects.get_for_model(contact.__class__).pk return HttpResponseRedirect( reverse('edit_contact') + "?partner=%s&id=%s&ct=%s" % ( partner.id, contact.id, content_id)) else: form = LocationForm(instance=location) ctx = { 'form': form, 'company': company, 'partner': str(partner.id), } if contact: ctx['contact'] = str(contact.id) if location: ctx['location'] = str(location.id) return render_to_response( 'mypartners/edit_location.html', ctx, RequestContext(request))
def dispatch(self, *args, **kwargs): """ Determine and set which product is attempting to be purchased. """ # The add url also has the pk for the product they're attempting # to purchase. self.product = get_object_or_404(self.purchase_model, pk=kwargs.get('product')) # Set the display name based on the model self.display_name = self.display_name.format(product=self.product) # If the product is free but the current user has no companies or an # un-filled-out profile, use the product form that only gets company # information. if self.product.cost < 0.01: company = get_company(self.request) profile = get_object_or_none(CompanyProfile, company=company) if company and profile and profile.address_line_one: invoice = Invoice.objects.create( transaction_type=Invoice.FREE, first_name=self.request.user.first_name, last_name=self.request.user.last_name, address_line_one=profile.address_line_one, address_line_two=profile.address_line_two, city=profile.city, state=profile.state, country=profile.country, zipcode=profile.zipcode, owner=self.product.owner, ) purchase_kwargs = { 'product': self.product, 'invoice': invoice, 'owner': company, 'paid': True, } PurchasedProduct.objects.create(**purchase_kwargs) return redirect(self.success_url) else: self.display_name = self.product self.form_class = PurchasedProductNoPurchaseForm return super(PurchasedProductFormView, self).dispatch(*args, **kwargs)
def __init__(self, *args, **kwargs): super(ProductForm, self).__init__(*args, **kwargs) if not is_superuser_in_admin(self.request): # Update querysets based on what the user should have # access to. self.fields["owner"].widget = HiddenInput() self.initial["owner"] = self.company packages = Package.objects.user_available() packages = packages.filter_company([self.company]) self.fields["package"].queryset = packages # remove "------" option from select box self.fields["package"].empty_label = None if self.instance.pk and self.instance.num_jobs_allowed != 0: self.initial["job_limit"] = "specific" profile = get_object_or_none(CompanyProfile, company=self.company) if not profile or not (profile.authorize_net_login and profile.authorize_net_transaction_key): if is_superuser_in_admin(self.request): # Superusers should know better than to break things self.fields["cost"].help_text = ( "This member needs to " "have added Authorize.net " "account information " "before we can safely " "charge for posting. If " "that hasn't been added, " "bad things may happen." ) else: self.fields["cost"].help_text = ( "You cannot charge for " "jobs until you " "<a href=%s>add your " "Authorize.net account " "information</a>." % reverse_lazy("companyprofile_add") ) self.initial["cost"] = 0 self.fields["cost"].widget.attrs["readonly"] = True setattr(self, "no_payment_info", True) autofocus_input(self)
def save(self, commit=True): self.instance.owner = self.company self.instance.created_by = self.request.user instance = super(OfflinePurchaseForm, self).save(commit) for product in self.products: product_quantity = self.cleaned_data.get(str(product.pk)) if product_quantity: OfflineProduct.objects.create( product=product, offline_purchase=instance, product_quantity=product_quantity ) instance.save() company = get_object_or_none(Company, pk=self.cleaned_data.get("purchasing_company")) if company: instance.redeemed_on = date.today() instance.create_purchased_products(company) instance.save() return instance
def __init__(self, *args, **kwargs): super(ProductForm, self).__init__(*args, **kwargs) if not is_superuser_in_admin(self.request): # Update querysets based on what the user should have # access to. self.fields['owner'].widget = HiddenInput() self.initial['owner'] = self.company packages = Package.objects.user_available() packages = packages.filter_company([self.company]) self.fields['package'].queryset = packages # remove "------" option from select box self.fields['package'].empty_label = None if self.instance.pk and self.instance.num_jobs_allowed != 0: self.initial['job_limit'] = 'specific' profile = get_object_or_none(CompanyProfile, company=self.company) if (not profile or not (profile.authorize_net_login and profile.authorize_net_transaction_key)): if is_superuser_in_admin(self.request): # Superusers should know better than to break things self.fields["cost"].help_text = ("This member needs to " "have added Authorize.net " "account information " "before we can safely " "charge for posting. If " "that hasn't been added, " "bad things may happen.") else: self.fields['cost'].help_text = ( 'You cannot charge for ' 'jobs until you ' '<a href=%s>add your ' 'Authorize.net account ' 'information</a>.' % reverse_lazy('companyprofile_add')) self.initial['cost'] = 0 self.fields['cost'].widget.attrs['readonly'] = True setattr(self, 'no_payment_info', True) autofocus_input(self)
def save(self, commit=True): self.instance.owner = self.company self.instance.created_by = self.request.user instance = super(OfflinePurchaseForm, self).save(commit) for product in self.products: product_quantity = self.cleaned_data.get(str(product.pk)) if product_quantity: OfflineProduct.objects.create( product=product, offline_purchase=instance, product_quantity=product_quantity) instance.save() company = get_object_or_none( Company, pk=self.cleaned_data.get('purchasing_company')) if company: instance.redeemed_on = date.today() instance.create_purchased_products(company) instance.save() return instance
def get_custom_page(flatpage): return get_object_or_none(CustomPage, pk=flatpage.pk)