def create_account(request, email, package): dt = datetime.datetime.now() account, pfu = Account.create_account(dt, email) account.apply_package(package) # Demo index creation account.create_demo_index() if account.package.base_price == 0: account.status = Account.Statuses.operational mail.report_new_account(account) account.save() password = account.apikey.split('-', 1)[1] user = auth.authenticate(username=pfu.user.username, password=password) auth.login(request, user) send_mail( 'Welcome to IndexTank!', 'Thanks signing-up for IndexTank!\nYour password for logging in to your dashboard is %s' % (password), 'IndexTank <*****@*****.**>', [email], fail_silently=False) return account
def _get_started_step2(request, plan): message = None data = request.POST if request.method == 'POST' else None account = None package = Package.objects.get(code=plan) if request.user.is_authenticated(): sign_up_form = None account = request.user.get_profile().account account.apply_package(package) account.save() if package.base_price > 0: payment_form = forms.PaymentInformationForm(data=data) else: return _get_started_step3(request) else: sign_up_form = forms.SignUpForm(data=data) if package.base_price > 0: payment_form = forms.PaymentInformationForm(data=data) else: payment_form = None if data: sign_up_ok = sign_up_form is None or sign_up_form.is_valid() payment_ok = payment_form is None or payment_form.is_valid() if sign_up_ok and payment_ok: if sign_up_form is not None: form_data = sign_up_form.cleaned_data try: account = do_sign_up(request, form_data, package) sign_up_form = None except IntegrityError, e: message = 'Email already exists.' if message is None and payment_form is not None: form_data = payment_form.cleaned_data try: process_payment_information(account, form_data) account.status = Account.Statuses.operational account.save() mail.report_new_account(account) return _get_started_step3(request) except BillingException, e: message = e.msg if message is None: return _get_started_step3(request)
def create_account(request, email, package): dt = datetime.datetime.now() account, pfu = Account.create_account(dt, email) account.apply_package(package) # Demo index creation account.create_demo_index() if account.package.base_price == 0: account.status = Account.Statuses.operational mail.report_new_account(account) account.save() password=account.apikey.split('-', 1)[1] user = auth.authenticate(username=pfu.user.username, password=password) auth.login(request, user) send_mail('Welcome to IndexTank!', 'Thanks signing-up for IndexTank!\nYour password for logging in to your dashboard is %s' % (password), 'IndexTank <*****@*****.**>', [email], fail_silently=False) return account
def enter_payment_information(request): account = request.user.get_profile().account if request.method == 'GET': form = forms.PaymentInformationForm() else: form = forms.PaymentInformationForm(data=request.POST) if form.is_valid(): form_data = form.cleaned_data try: if account.package.base_price > 0: process_payment_information(account, form_data) account.status = Account.Statuses.operational mail.report_new_account(account) account.save() return HttpResponseRedirect(reverse('dashboard')) except BillingException, e: messages.error(request, e.msg)
def dashboard(request): # Possible statuses: # - No index # - Index but no docs # - Index with docs account_status = None if request.user.get_profile().change_password: messages.info(request, 'Your password was reset and you need to change it.') return HttpResponseRedirect(reverse('change_password')) account = request.user.get_profile().account #if not account.package: # return HttpResponseRedirect(reverse('select_package')) if not account.status == Account.Statuses.operational and not account.payment_informations.count( ): if account.package.base_price > 0: messages.info( request, 'Before accessing your dashboard you need to enter your payment information' ) return HttpResponseRedirect(reverse('enter_payment')) elif account.status == Account.Statuses.creating: account.status = Account.Statuses.operational mail.report_new_account(account) account.save() else: return HttpResponseRedirect(reverse('logout')) indexes = account.indexes.filter(deleted=False) has_indexes_left = (len(indexes) < account.package.max_indexes) totals = dict(size=0, docs=0, qpd=0) for index in indexes: totals['docs'] += index.current_docs_number totals['size'] += index.current_size totals['qpd'] += index.queries_per_day if len(indexes) == 0: account_status = 'NOINDEX' elif totals['docs'] == 0: account_status = 'INDEXNODOCS' else: account_status = 'INDEXWITHDOCS' percentages = {} def add_percentage(k, max, t, p): p[k] = 100.0 * t[k] / max KB = 1024 MB = KB * KB max_docs = account.package.index_max_size max_size = account.package.max_size_mb() max_qpd = account.package.searches_per_day add_percentage('docs', max_docs, totals, percentages) add_percentage('size', max_size, totals, percentages) add_percentage('qpd', max_qpd, totals, percentages) for index in indexes: insights = {} insights_update = {} #for i in index.insights.all(): # try: # insights[i.code] = json.loads(i.data) # insights_update[i.code] = i.last_update # except: # print 'Failed to load insight %s for %s' % (i.code, index.code) #index.insights_map = insights #index.insights_update = insights_update context = { 'account': account, 'indexes': indexes, 'has_indexes_left': has_indexes_left, 'account_status': account_status, 'totals': totals, 'percentages': percentages, 'navigation_pos': 'dashboard', } return render('dashboard.html', request, context_dict=context)
def dashboard(request): # Possible statuses: # - No index # - Index but no docs # - Index with docs account_status = None if request.user.get_profile().change_password: messages.info(request, 'Your password was reset and you need to change it.') return HttpResponseRedirect(reverse('change_password')) account = request.user.get_profile().account #if not account.package: # return HttpResponseRedirect(reverse('select_package')) if not account.status == Account.Statuses.operational and not account.payment_informations.count(): if account.package.base_price > 0: messages.info(request, 'Before accessing your dashboard you need to enter your payment information') return HttpResponseRedirect(reverse('enter_payment')) elif account.status == Account.Statuses.creating: account.status = Account.Statuses.operational mail.report_new_account(account) account.save() else: return HttpResponseRedirect(reverse('logout')) indexes = account.indexes.filter(deleted=False) has_indexes_left = (len(indexes) < account.package.max_indexes) totals = dict(size=0, docs=0, qpd=0) for index in indexes: totals['docs'] += index.current_docs_number totals['size'] += index.current_size totals['qpd'] += index.queries_per_day if len(indexes) == 0: account_status = 'NOINDEX' elif totals['docs'] == 0: account_status = 'INDEXNODOCS' else: account_status = 'INDEXWITHDOCS' percentages = {} def add_percentage(k, max, t, p): p[k] = 100.0 * t[k] / max KB = 1024 MB = KB * KB max_docs = account.package.index_max_size max_size = account.package.max_size_mb() max_qpd = account.package.searches_per_day add_percentage('docs', max_docs, totals, percentages) add_percentage('size', max_size, totals, percentages) add_percentage('qpd', max_qpd, totals, percentages) for index in indexes: insights = {} insights_update = {} #for i in index.insights.all(): # try: # insights[i.code] = json.loads(i.data) # insights_update[i.code] = i.last_update # except: # print 'Failed to load insight %s for %s' % (i.code, index.code) #index.insights_map = insights #index.insights_update = insights_update context = { 'account': account, 'indexes': indexes, 'has_indexes_left': has_indexes_left, 'account_status': account_status, 'totals': totals, 'percentages': percentages, 'navigation_pos': 'dashboard', } return render('dashboard.html', request, context_dict=context)