Exemple #1
0
def get_common_data_for_feedback(request):
    result_data = {}
    if not request:
        return {'common_data' : result_data}

    company = None
    authorized = not request.user.is_anonymous() and hasattr(request, "company") and request.company is not None

    own = False
    if authorized:
        own = True
        company = request.company
        result_data.update({'verified' : CompanyAccountStatus.is_active_account(company.account_status)})

    result_data.update({
        'own_company' : own,
        'authorized' : authorized
    })

    if authorized:
        result_data.update({'companyRekId' : company.rek_id,
                            'company_logo_url' : company.get_logo_url(),
                            'brandName' : company.brand_name,
                            'ownBrandName' : request.company.brand_name,
                            'ownCompanyRekId' : request.company.rek_id})

        if result_data['verified']:
            result_data.update({'notifications' :
                                        {'unread_dialogs' : get_unread_dialog_count(request.employee._id)}
            })

    return {'common_data' : result_data}
    def wrapper(request, *args, **kw):
        company = request.company
        if not company:
            return HttpResponseRedirect(redirect_url)

        if CompanyAccountStatus.is_active_account(company.account_status):
            if not company.is_required_data_filled():
                return HttpResponseRedirect('/fill_required/')
            return function(request, *args, **kw)

        return HttpResponseRedirect(redirect_url)
    def can_view_address(self, company):
        #noinspection PyUnusedLocal
        unused = company

        if not self.user.is_authenticated():
            return False

        user_company = get_user_company(self.user)
        own = user_company == company
        if not own and (not user_company or not CompanyAccountStatus.is_active_account(user_company.account_status)):
            return False

        return True
    def can_view(self, employee):
        if not self.user.is_authenticated():
            return False

        user_company = get_user_company(self.user)
        if not user_company or not CompanyAccountStatus.is_active_account(user_company.account_status):
            return False

        if not employee.visible_in_profile:
            return (employee.company == user_company and self.user.groups.filter(name="companyadmin").count() > 0) or \
                    employee == self.user.get_profile()

        return True
    def can_view(self, employee):
        if not self.user.is_authenticated():
            return False

        user_company = get_user_company(self.user)
        if not user_company or not CompanyAccountStatus.is_active_account(
                user_company.account_status):
            return False

        if not employee.visible_in_profile:
            return (employee.company == user_company and self.user.groups.filter(name="companyadmin").count() > 0) or \
                    employee == self.user.get_profile()

        return True
    def can_view_address(self, company):
        #noinspection PyUnusedLocal
        unused = company

        if not self.user.is_authenticated():
            return False

        user_company = get_user_company(self.user)
        own = user_company == company
        if not own and (not user_company
                        or not CompanyAccountStatus.is_active_account(
                            user_company.account_status)):
            return False

        return True
    def get_view_accounts_criteria(self, company):
        #noinspection PyUnusedLocal
        unused = company

        pcm = 0

        if not self.user.is_authenticated():
            pcm |= PermissionCriteriaMask.REGISTERED
        else:
            user_company = get_user_company(self.user)
            own = user_company == company
            if not own and (not user_company or not CompanyAccountStatus.is_active_account(user_company.account_status)):
                pcm |= PermissionCriteriaMask.COMPANY_VERIFIED

        return pcm
    def get_view_accounts_criteria(self, company):
        #noinspection PyUnusedLocal
        unused = company

        pcm = 0

        if not self.user.is_authenticated():
            pcm |= PermissionCriteriaMask.REGISTERED
        else:
            user_company = get_user_company(self.user)
            own = user_company == company
            if not own and (not user_company
                            or not CompanyAccountStatus.is_active_account(
                                user_company.account_status)):
                pcm |= PermissionCriteriaMask.COMPANY_VERIFIED

        return pcm
Exemple #9
0
def get_common_data_for_search(request, show_options):
    result_data = {}
    if not request:
        return {'common_data': result_data}

    company = None
    authorized = not request.user.is_anonymous() and hasattr(
        request, "company") and request.company is not None
    own = False
    if authorized:
        own = True
        company = request.company
        result_data.update({
            'show_mode':
            show_options.get('show_mode', 'companies'),
            'verified':
            CompanyAccountStatus.is_active_account(company.account_status),
            'companyRekId':
            company.rek_id,
            'brandName':
            company.brand_name
        })

    result_data.update({'own_company': own, 'authorized': authorized})

    if authorized:
        result_data.update({
            'companyRekId': company.rek_id,
            'company_logo_url': company.get_logo_url(),
            'brandName': company.brand_name,
            'ownBrandName': company.brand_name,
            'ownCompanyRekId': company.rek_id
        })

        if result_data['verified']:
            result_data.update({
                'notifications': {
                    'unread_dialogs':
                    get_unread_dialog_count(request.employee._id)
                }
            })

    return {'common_data': result_data}
        def require_auth(handler, kwargs):
            request = handler.request
            session_id = request.cookies['sessionid'].value
            csrf_key = request.cookies['csrftoken'].value
            # todo: asyncmongo!
            user, company, employee = get_authorized_parameters(csrf_key, session_id, request)

            if not user or not employee or not company:
                handler._transforms = []
                handler.redirect('/')
                return False

            if not CompanyAccountStatus.is_active_account(company.account_status):
                handler._transforms = []
                handler.redirect('/verification/')
                return False

            setattr(request, 'user', user)
            setattr(request, 'company', company)
            setattr(request, 'employee', employee)
            return True
Exemple #11
0
        def require_auth(handler, kwargs):
            request = handler.request
            session_id = request.cookies['sessionid'].value
            csrf_key = request.cookies['csrftoken'].value
            # todo: asyncmongo!
            user, company, employee = get_authorized_parameters(
                csrf_key, session_id, request)

            if not user or not employee or not company:
                handler._transforms = []
                handler.redirect('/')
                return False

            if not CompanyAccountStatus.is_active_account(
                    company.account_status):
                handler._transforms = []
                handler.redirect('/verification/')
                return False

            setattr(request, 'user', user)
            setattr(request, 'company', company)
            setattr(request, 'employee', employee)
            return True
Exemple #12
0
    def post(self, request):
        signup_form = SignupForm()
        top_signin_form = SigninForm()
        subscribe_form = SubscribeForm()
        login_error = False
        login_disabled = False
        email_error = False
        user = request.user
        page_status = "registered"
        brand_name = ""
        brand_name_error = False
        password_error = False
        promo_code_part1 = ""
        promo_code_part2 = ""
        promo_code_error = False
        email_error_str = ""
        password_error_str = ""
        brandname_error_str = ""
        promo_code_error_str = ""

        if 'login' in request.POST:
            top_signin_form = SigninForm(request.POST)
            if top_signin_form.is_valid():
                username = top_signin_form.cleaned_data['username'].lower()
                password = top_signin_form.cleaned_data['password']
                end_session_on_browser_close = top_signin_form.cleaned_data[
                    'publicpc']
                auth_user = auth_authenticate(username=username,
                                              password=password)

                if auth_user:
                    if not auth_user.activated:
                        page_status = "user_not_activated"
                    elif auth_user.is_active:
                        try:
                            return self.login_user(
                                request, auth_user,
                                end_session_on_browser_close)
                        except Exception:
                            pass
                    else:
                        page_status = "user_blocked"

                    login_disabled = True
                else:
                    page_status = "wrong_password"
                    login_error = True
            else:
                page_status = "wrong_email"
                login_error = True
        elif 'join' in request.POST:
            if not user.is_anonymous():
                return HttpResponseRedirect(reverse('index_view'))

            signup_form = SignupForm(request.POST)

            if signup_form.is_valid():
                email = signup_form.cleaned_data['email'].lower()
                brand_name = signup_form.cleaned_data['brand_name']
                password = signup_form.cleaned_data['password']

                promo_code = signup_form.cleaned_data['promo_code']

                try:
                    #with transaction.commit_on_success(): # mustdo: return transaction!
                    invite_cookie = request.COOKIES.get('invite')
                    created_user, password, new_company, activation_link = create_new_account(
                        email, password, brand_name, promo_code, invite_cookie)
                    self.send_success_registration_email(
                        email, password, activation_link)
                    if not CompanyAccountStatus.is_active_account(
                            new_company.account_status):
                        self.generate_verification_letters(
                            email, new_company._id)

                    if promo_code:
                        self.send_reg_promo_email(email)
                    auth_authenticate(username=email, password=password)

                    return render_to_response(
                        'base.html', {
                            'email': email,
                            'page_status': page_status
                        },
                        context_instance=RequestContext(request))
                except Exception:
                    page_status = "unknown_error"

            elif 'email' in signup_form.errors:
                page_status = "user_creating_error"
                email_error_str = getattr(signup_form, 'email_error_str',
                                          signup_form._errors['email'][0])
                email_error = True
            elif 'password' in signup_form.errors:
                page_status = "user_creating_error"
                password_error_str = getattr(
                    signup_form, 'password_error_str',
                    signup_form._errors['password'][0])
                password_error = True
            elif 'brand_name' in signup_form.errors:
                page_status = "user_creating_error"
                brandname_error_str = getattr(
                    signup_form, 'brand_name_error_str',
                    signup_form._errors['brand_name'][0])
                brand_name_error = True
            elif 'promo_code' in signup_form.errors:
                page_status = "user_creating_error"
                promo_code_error_str = getattr(
                    signup_form, 'promo_code_error_str',
                    signup_form._errors['promo_code'][0])
                promo_code_error = True
                promo_code_part1 = request.POST.get('promo_code_part1', '')
                promo_code_part2 = request.POST.get('promo_code_part2', '')
            elif '__all__' in signup_form.errors:
                page_status = "user_creating_error"
                promo_code_error_str = getattr(
                    signup_form, 'promo_code_error_str',
                    signup_form._errors['__all__'][0])
                promo_code_error = True
                promo_code_part1 = request.POST.get('promo_code_part1', '')
                promo_code_part2 = request.POST.get('promo_code_part2', '')
            else:
                page_status = "user_creating_error"

            if settings.PRODUCTION:
                valid_metas = {}
                for key in request.META:
                    val = request.META[key]
                    if isinstance(val, basestring) or isinstance(
                            val, dict) or isinstance(val, list) or isinstance(
                                val, tuple):
                        valid_metas[key] = val

                logger.warning(
                    u'Reg error: page_status=%(page_status)s\nGET: %(get)s\nPOST: %(post)s\nMETA: %(meta)s'
                    % {
                        'page_status': page_status or '',
                        'get': simplejson.dumps(request.GET),
                        'post': simplejson.dumps(request.POST),
                        'meta': simplejson.dumps(valid_metas)
                    })

        next = self.get_next(request, request.path)

        result_dict = {
            'page_status': page_status,
            'top_signin_form': top_signin_form,
            'signup_form': signup_form,
            'subscribe_form': subscribe_form,
            'next': next,
            'login_error': login_error,
            'login_disabled': login_disabled,
            'email_error': email_error,
            'user': user,
            'brand_name': brand_name,
            'brand_name_error': brand_name_error,
            'password_error': password_error,
            'email_error_str': email_error_str,
            'password_error_str': password_error_str,
            'brandname_error_str': brandname_error_str,
            'promo_code_error': promo_code_error,
            'promo_code_error_str': promo_code_error_str,
            'promo_code_part1': promo_code_part1,
            'promo_code_part2': promo_code_part2
        }

        if 'email' in request.POST:
            email = request.POST['email']
            result_dict['email'] = email.strip().lower()

        if 'username' in request.POST:
            username = request.POST['username']
            result_dict['username'] = username.strip()

        if 'brand_name' in request.POST:
            brand_name = request.POST['brand_name']
            result_dict['brand_name'] = brand_name.strip()

        return render_to_response('base.html',
                                  result_dict,
                                  context_instance=RequestContext(request))
Exemple #13
0
 def can_be_modified(self):
     return CompanyAccountStatus.is_active_account(self.account_status)
Exemple #14
0
 def is_active(self):
     return self.is_account_activated and \
            CompanyAccountStatus.is_active_account(self.account_status) and \
            self.is_required_data_filled()
Exemple #15
0
def get_common_data_for_company(request, target_company):
    common_data = {}
    if not target_company:
        return {'common_data' : common_data}

    company = None
    authorized = not request.user.is_anonymous() and hasattr(request, "company") and request.company is not None

    # <temporary> // until employees are implemented
    employee_id = ''
    # </temporary>

    own = False
    if authorized:
        company = target_company
        own = request.company._id == target_company._id
        # <temporary> // until employees are implemented
        employee = CompanyEmployee.objects.get_one({'company_id' : company._id})
        employee_id = unicode(employee._id) if employee else ''
        # </temporary>
        common_data.update({'verified' : CompanyAccountStatus.is_active_account(request.company.account_status)})
        common_data.update({'they_verified' : CompanyAccountStatus.is_active_account(target_company.account_status)})

    common_data.update({'contractors' : [],
                        'companyRekId' : target_company.rek_id,
                        'company_logo_url' : target_company.get_logo_url(),
                        'brandName' : target_company.brand_name,
                        # <temporary> // until employees are implemented
                        'employee_id' : employee_id
                        # </temporary>
    })

    common_data.update({
        'own_company' : own,
        'authorized' : authorized
    })

    if authorized:
        common_data.update({'companyRekId' : company.rek_id,
                            'company_logo_url' : company.get_logo_url(),
                            'brandName' : company.brand_name,
                            'ownBrandName' : request.company.brand_name,
                            'ownCompanyRekId' : request.company.rek_id})
        if own:
            common_data['unviewed_contractors'] = get_unviewed_contractors_count(request.company)
        else:
            my_rec_request_status = -1
            their_rec_request_status = -1
            recs = RecommendationRequest.objects.get({'$or' : [{'requester' : company._id,
                                                                'recipient' : request.company._id},
                                                               {'recipient' : company._id,
                                                                'requester' : request.company._id}]})
            for rec in recs:
                if rec.recipient == request.company._id:
                    their_rec_request_status = rec.status
                else:
                    my_rec_request_status = rec.status
                if my_rec_request_status != -1 and their_rec_request_status != -1:
                    break
            if my_rec_request_status != -1:
                common_data['my_rec_request_status'] = my_rec_request_status
            if their_rec_request_status != -1:
                common_data['their_rec_request_status'] = their_rec_request_status

            we_are_contractors = ""
            contractor = Contractor.objects.get_one({'$or' : [{'company_1' : target_company._id,
                                                               'company_2' : request.company._id},
                                                              {'company_2' : target_company._id,
                                                               'company_1' : request.company._id}]})
            if contractor:
                if contractor.status == ContractorStatusEnum.ACCEPTED:
                    we_are_contractors = 'yes'
                elif contractor.status == ContractorStatusEnum.RECEIVED:
                    if contractor.company_1 == request.company._id:
                        we_are_contractors = 'we_asked'
                    else:
                        we_are_contractors = 'they_asked'
                elif contractor.status == ContractorStatusEnum.DECLINED:
                    if contractor.company_1 == request.company._id:
                        we_are_contractors = 'they_declined'
                    else:
                        we_are_contractors = 'we_declined'
            else:
                we_are_contractors = 'no'

            common_data['we_are_contractors'] = we_are_contractors

        if common_data['verified']:
            common_data.update({'notifications' : {'unread_dialogs' : get_unread_dialog_count(request.employee._id)}})

    return {'common_data' : common_data}
Exemple #16
0
 def is_active(self):
     return self.is_account_activated and \
            CompanyAccountStatus.is_active_account(self.account_status) and \
            self.is_required_data_filled()
Exemple #17
0
def get_common_data_for_company(request, target_company):
    common_data = {}
    if not target_company:
        return {'common_data': common_data}

    company = None
    authorized = not request.user.is_anonymous() and hasattr(
        request, "company") and request.company is not None

    # <temporary> // until employees are implemented
    employee_id = ''
    # </temporary>

    own = False
    if authorized:
        company = target_company
        own = request.company._id == target_company._id
        # <temporary> // until employees are implemented
        employee = CompanyEmployee.objects.get_one({'company_id': company._id})
        employee_id = unicode(employee._id) if employee else ''
        # </temporary>
        common_data.update({
            'verified':
            CompanyAccountStatus.is_active_account(
                request.company.account_status)
        })
        common_data.update({
            'they_verified':
            CompanyAccountStatus.is_active_account(
                target_company.account_status)
        })

    common_data.update({
        'contractors': [],
        'companyRekId': target_company.rek_id,
        'company_logo_url': target_company.get_logo_url(),
        'brandName': target_company.brand_name,
        # <temporary> // until employees are implemented
        'employee_id': employee_id
        # </temporary>
    })

    common_data.update({'own_company': own, 'authorized': authorized})

    if authorized:
        common_data.update({
            'companyRekId': company.rek_id,
            'company_logo_url': company.get_logo_url(),
            'brandName': company.brand_name,
            'ownBrandName': request.company.brand_name,
            'ownCompanyRekId': request.company.rek_id
        })
        if own:
            common_data[
                'unviewed_contractors'] = get_unviewed_contractors_count(
                    request.company)
        else:
            my_rec_request_status = -1
            their_rec_request_status = -1
            recs = RecommendationRequest.objects.get({
                '$or': [{
                    'requester': company._id,
                    'recipient': request.company._id
                }, {
                    'recipient': company._id,
                    'requester': request.company._id
                }]
            })
            for rec in recs:
                if rec.recipient == request.company._id:
                    their_rec_request_status = rec.status
                else:
                    my_rec_request_status = rec.status
                if my_rec_request_status != -1 and their_rec_request_status != -1:
                    break
            if my_rec_request_status != -1:
                common_data['my_rec_request_status'] = my_rec_request_status
            if their_rec_request_status != -1:
                common_data[
                    'their_rec_request_status'] = their_rec_request_status

            we_are_contractors = ""
            contractor = Contractor.objects.get_one({
                '$or': [{
                    'company_1': target_company._id,
                    'company_2': request.company._id
                }, {
                    'company_2': target_company._id,
                    'company_1': request.company._id
                }]
            })
            if contractor:
                if contractor.status == ContractorStatusEnum.ACCEPTED:
                    we_are_contractors = 'yes'
                elif contractor.status == ContractorStatusEnum.RECEIVED:
                    if contractor.company_1 == request.company._id:
                        we_are_contractors = 'we_asked'
                    else:
                        we_are_contractors = 'they_asked'
                elif contractor.status == ContractorStatusEnum.DECLINED:
                    if contractor.company_1 == request.company._id:
                        we_are_contractors = 'they_declined'
                    else:
                        we_are_contractors = 'we_declined'
            else:
                we_are_contractors = 'no'

            common_data['we_are_contractors'] = we_are_contractors

        if common_data['verified']:
            common_data.update({
                'notifications': {
                    'unread_dialogs':
                    get_unread_dialog_count(request.employee._id)
                }
            })

    return {'common_data': common_data}
Exemple #18
0
    def generate_data_obj(cls, company, my_company, employee = None):
        own = False
        if my_company and company.rek_id == my_company.rek_id:
            own = True

        if not own and not company.is_active():
            return {}

        data = {"categoryText" : company.category_text or "",
                "brandName" : company.brand_name,
                "rek_id" : company.rek_id,
                "own" : own,
                "verify_rec_number" : SettingsManager.get_property("rnes"),
                "company_logo" : company.get_logo_url(),
                "authorized" : my_company is not None,
                "verified" : CompanyAccountStatus.is_active_account(company.account_status),
                "employee_id" : unicode(employee) if employee else u""}

        company_id = company._id
        if own:
            invoice = Invoice.objects.get_one({'expire_date' : {'$gte' : timezone.now()},
                                               'payer' : my_company._id,
                                               'status' : InvoiceStatusEnum.CREATED})
            if invoice:
                employee_tz = utc
                issued = invoice.create_date.astimezone(employee_tz)
                data['bill'] = {'id' : unicode(invoice._id),
                                 'service_title' : invoice.position,
                                 'price' : invoice.price,
                                 'status' : invoice.status,
                                 'issued' : issued.strftime('%d.%m.%Y %H:%M'),
                                 'number' : invoice.number}

        corresponding_rec_reqs = RecommendationRequest.objects.get({'$or' : [{'requester' : company_id},
                                                                             {'recipient' : company_id}]})

        sent_not_accepted_list = []
        sent_accepted_list = []
        received_accepted = []
        received_not_accepted = []

        max_req_count = 0

        for rec in corresponding_rec_reqs:
            if rec.requester == company_id:
                acceptor = Company.objects.get_one({'_id' : rec.recipient})
                max_req_count += 1
                if acceptor:
                    if rec.status == RecommendationStatusEnum.RECEIVED:
                        sent_not_accepted_list.append({
                            'rek_id' : acceptor.rek_id,
                            'brand_name' : acceptor.brand_name
                        })
                    elif rec.status == RecommendationStatusEnum.ACCEPTED:
                        sent_accepted_list.append({
                            'rek_id' : acceptor.rek_id,
                            'brand_name' : acceptor.brand_name,
                            'logo' : acceptor.get_some_logo_url(kind='list_logo'),
                            'kind_of_activity' : acceptor.category_text
                        })
            elif rec.recipient == company_id:
                sender = Company.objects.get_one({'_id' : rec.requester})
                if sender:
                    if rec.status == RecommendationStatusEnum.ACCEPTED:
                        received_accepted.append({'rek_id' : sender.rek_id,
                                                  'brand_name' : sender.brand_name})
                    elif rec.status == RecommendationStatusEnum.RECEIVED:
                        received_not_accepted.append({
                            'rek_id' : sender.rek_id,
                            'brand_name' : sender.brand_name,
                            'logo' : sender.get_some_logo_url(kind='list_logo'),
                            'kind_of_activity' : sender.category_text,
                            'request_id' : unicode(rec._id),
                            'msg' : rec.message
                        })

        max_req_count_reached = max_req_count >= SettingsManager.get_property('rmax')

        data.update({'sent_accepted_list' : sent_accepted_list,
                     'received_accepted' : received_accepted})

        if own:
            data.update({'sent_not_accepted_list' : sent_not_accepted_list,
                         'received_not_accepted' : received_not_accepted,
                         'max_req_count_reached' : max_req_count_reached})

        if own:
            my_company_id = my_company._id
            sent_invites_obj_list = Invite.objects.get({'sender' : my_company_id})
            sent_invites_not_used = []
            sent_invites_used = []
            for invite_obj in sent_invites_obj_list:
                if invite_obj.rec_request:
                    invited_rec = RecommendationRequest.objects.get_one({'_id' : invite_obj.rec_request})
                    if not invited_rec:
                        continue
                    invited_company = Company.objects.get_one({'_id' : invited_rec.requester})
                    if not invited_company:
                        continue
                    sent_invites_used.append({
                        'brand_name' : invited_company.brand_name,
                        'rek_id' : invited_company.rek_id
                    })
                else:
                    sent_invites_not_used.append({
                        'email' : invite_obj.email,
                        'date' : invite_obj.created.strftime('%d.%m.%Y')
                    })

            data.update({'sent_invites' : sent_invites_not_used,
                         'sent_registered_invites' : sent_invites_used})
        return data
Exemple #19
0
    def generate_data_obj(cls, company, my_company):
        if not my_company:
            own = False
        else:
            own = company == my_company

        # <temporary> // until employees are implemented
        company_employee = CompanyEmployee.objects.get_one(
            {'company_id': company._id})
        employee_id = "" if not company_employee else unicode(
            company_employee._id)
        # </temporary>

        data = {
            'authorized':
            my_company is not None,
            'company_logo':
            company.get_logo_url(),
            'rek_id':
            company.rek_id,
            'own_company':
            own,
            'verified':
            CompanyAccountStatus.is_active_account(company.account_status),
            # <temporary> // until employees are implemented
            'employee_id':
            employee_id,
            # </temporary>,
            'profile': {
                'descr': company.description,
                'information': {
                    'brandName':
                    company.brand_name,
                    'shortName':
                    company.short_name,
                    'fullName':
                    company.full_name,
                    'inn':
                    company.inn,
                    'kpp':
                    company.kpp,
                    'categoryText':
                    company.category_text or u'',
                    'estYear':
                    company.date_established.year
                    if company.date_established else None,
                    'staffSize':
                    company.staff_size,
                    'genDir':
                    company.gen_director,
                    'genAcc':
                    company.chief_accountant,
                    'categories':
                    get_categories_list(company)
                },
            },
            'contacts': {
                'site': '',
                'phone': '',
                'email': ''
            },
            'staff_size_select':
            StaffSizeEnum.choices()
        }
        if company.bank_accounts and len(company.bank_accounts):
            account = company.bank_accounts[0]
            data['profile']['essential_elements'] = {
                'bank': account['bank'],
                'bank_address': account['bank_address'],
                'bik': account['bik'],
                'correspondent_account': account['correspondent_account'],
                'settlement_account': account['settlement_account'],
                'recipient': account['recipient']
            }
        else:
            data['profile']['essential_elements'] = {
                'bank': "",
                'bank_address': "",
                'bik': "",
                'correspondent_account': "",
                'settlement_account': "",
                'recipient': ""
            }

        if len(company.web_sites):
            data['contacts']['site'] = company.web_sites[0]

        if len(company.phones):
            data['contacts']['phone'] = company.phones[0]

        if len(company.emails):
            data['contacts']['email'] = company.emails[0]

        if len(company.offices):
            office_list = []
            data['contacts']['offices'] = office_list
            for office in company.offices:
                office_data = {
                    'city': office.city,
                    'information': office.information,
                    'imgID': office.get_map_img_id(),
                    'img_src': office.get_map_url(company.rek_id),
                    'img_width': office.get_map_dimensions()[0],
                    'img_height': office.get_map_dimensions()[1]
                }
                office_list.append(office_data)

        #        'company_logo' : company.get_logo_url(),    -> company_logo_url
        #        'rek_id' : company.rek_id,                  -> companyRekId

        return data
Exemple #20
0
 def can_be_modified(self):
     return CompanyAccountStatus.is_active_account(self.account_status)
Exemple #21
0
    def post(self, request):
        signup_form = SignupForm()
        top_signin_form = SigninForm()
        subscribe_form = SubscribeForm()
        login_error = False
        login_disabled = False
        email_error = False
        user = request.user
        page_status = "registered"
        brand_name = ""
        brand_name_error = False
        password_error = False
        promo_code_part1 = ""
        promo_code_part2 = ""
        promo_code_error = False
        email_error_str = ""
        password_error_str = ""
        brandname_error_str = ""
        promo_code_error_str = ""

        if 'login' in request.POST:
            top_signin_form = SigninForm(request.POST)
            if top_signin_form.is_valid():
                username = top_signin_form.cleaned_data['username'].lower()
                password = top_signin_form.cleaned_data['password']
                end_session_on_browser_close = top_signin_form.cleaned_data['publicpc']
                auth_user = auth_authenticate(username=username, password=password)

                if auth_user:
                    if not auth_user.activated:
                        page_status = "user_not_activated"
                    elif auth_user.is_active:
                        try:
                            return self.login_user(request, auth_user, end_session_on_browser_close)
                        except Exception:
                            pass
                    else:
                        page_status = "user_blocked"

                    login_disabled = True
                else:
                    page_status = "wrong_password"
                    login_error = True
            else:
                page_status = "wrong_email"
                login_error = True
        elif 'join' in request.POST:
            if not user.is_anonymous():
                return HttpResponseRedirect(reverse('index_view'))

            signup_form = SignupForm(request.POST)

            if signup_form.is_valid():
                email = signup_form.cleaned_data['email'].lower()
                brand_name = signup_form.cleaned_data['brand_name']
                password = signup_form.cleaned_data['password']

                promo_code = signup_form.cleaned_data['promo_code']

                try:
                    #with transaction.commit_on_success(): # mustdo: return transaction!
                    invite_cookie = request.COOKIES.get('invite')
                    created_user, password, new_company, activation_link = create_new_account(email, password, brand_name, promo_code, invite_cookie)
                    self.send_success_registration_email(email, password, activation_link)
                    if not CompanyAccountStatus.is_active_account(new_company.account_status):
                        self.generate_verification_letters(email, new_company._id)

                    if promo_code:
                        self.send_reg_promo_email(email)
                    auth_authenticate(username=email, password=password)

                    return render_to_response('base.html',
                                              {'email': email,
                                               'page_status': page_status},
                                              context_instance=RequestContext(request))
                except Exception:
                    page_status = "unknown_error"

            elif 'email' in signup_form.errors:
                page_status = "user_creating_error"
                email_error_str = getattr(signup_form, 'email_error_str', signup_form._errors['email'][0])
                email_error = True
            elif 'password' in signup_form.errors:
                page_status = "user_creating_error"
                password_error_str = getattr(signup_form, 'password_error_str', signup_form._errors['password'][0])
                password_error = True
            elif 'brand_name' in signup_form.errors:
                page_status = "user_creating_error"
                brandname_error_str = getattr(signup_form, 'brand_name_error_str', signup_form._errors['brand_name'][0])
                brand_name_error = True
            elif 'promo_code' in signup_form.errors:
                page_status = "user_creating_error"
                promo_code_error_str = getattr(signup_form, 'promo_code_error_str', signup_form._errors['promo_code'][0])
                promo_code_error = True
                promo_code_part1 = request.POST.get('promo_code_part1', '')
                promo_code_part2 = request.POST.get('promo_code_part2', '')
            elif '__all__' in signup_form.errors:
                page_status = "user_creating_error"
                promo_code_error_str = getattr(signup_form, 'promo_code_error_str', signup_form._errors['__all__'][0])
                promo_code_error = True
                promo_code_part1 = request.POST.get('promo_code_part1', '')
                promo_code_part2 = request.POST.get('promo_code_part2', '')
            else:
                page_status = "user_creating_error"

            if settings.PRODUCTION:
                valid_metas = {}
                for key in request.META:
                    val = request.META[key]
                    if isinstance(val, basestring) or isinstance(val, dict) or isinstance(val, list) or isinstance(val, tuple):
                        valid_metas[key] = val

                logger.warning(u'Reg error: page_status=%(page_status)s\nGET: %(get)s\nPOST: %(post)s\nMETA: %(meta)s' % {
                    'page_status' : page_status or '',
                    'get' : simplejson.dumps(request.GET),
                    'post' : simplejson.dumps(request.POST),
                    'meta' : simplejson.dumps(valid_metas)
                })

        next = self.get_next(request, request.path)

        result_dict = {'page_status': page_status,
                       'top_signin_form' : top_signin_form,
                       'signup_form' : signup_form,
                       'subscribe_form' : subscribe_form,
                       'next' : next,
                       'login_error' : login_error,
                       'login_disabled' : login_disabled,
                       'email_error' : email_error,
                       'user' : user,
                       'brand_name' : brand_name,
                       'brand_name_error' : brand_name_error,
                       'password_error' : password_error,
                       'email_error_str' : email_error_str,
                       'password_error_str' : password_error_str,
                       'brandname_error_str' : brandname_error_str,
                       'promo_code_error' : promo_code_error,
                       'promo_code_error_str' : promo_code_error_str,
                       'promo_code_part1' : promo_code_part1,
                       'promo_code_part2' : promo_code_part2}

        if 'email' in request.POST:
            email = request.POST['email']
            result_dict['email'] = email.strip().lower()

        if 'username' in request.POST:
            username = request.POST['username']
            result_dict['username'] = username.strip()

        if 'brand_name' in request.POST:
            brand_name = request.POST['brand_name']
            result_dict['brand_name'] = brand_name.strip()

        return render_to_response('base.html', result_dict, context_instance=RequestContext(request))
Exemple #22
0
    def generate_data_obj(cls, company, my_company):
        if not my_company:
            own = False
        else:
            own = company == my_company

        # <temporary> // until employees are implemented
        company_employee = CompanyEmployee.objects.get_one({'company_id' : company._id})
        employee_id = "" if not company_employee else unicode(company_employee._id)
        # </temporary>

        data = {
            'authorized' : my_company is not None,
            'company_logo' : company.get_logo_url(),
            'rek_id' : company.rek_id,
            'own_company' : own,
            'verified' : CompanyAccountStatus.is_active_account(company.account_status),
            # <temporary> // until employees are implemented
            'employee_id' : employee_id,
            # </temporary>,
            'profile' : {
                'descr' : company.description,
                'information' : {
                    'brandName' : company.brand_name,
                    'shortName' : company.short_name,
                    'fullName' : company.full_name,
                    'inn' : company.inn,
                    'kpp' : company.kpp,
                    'categoryText' : company.category_text or u'',
                    'estYear' : company.date_established.year if company.date_established else None,
                    'staffSize' : company.staff_size,
                    'genDir' : company.gen_director,
                    'genAcc' : company.chief_accountant,
                    'categories' : get_categories_list(company)
                },
            },
            'contacts' : {
                'site' : '',
                'phone' : '',
                'email' : ''
            },
            'staff_size_select' : StaffSizeEnum.choices()
        }
        if company.bank_accounts and len(company.bank_accounts):
            account = company.bank_accounts[0]
            data['profile']['essential_elements'] = {
                'bank' : account['bank'],
                'bank_address' : account['bank_address'],
                'bik' : account['bik'],
                'correspondent_account' : account['correspondent_account'],
                'settlement_account' : account['settlement_account'],
                'recipient' : account['recipient']
            }
        else:
            data['profile']['essential_elements'] = {
                'bank' : "",
                'bank_address' : "",
                'bik' : "",
                'correspondent_account' : "",
                'settlement_account' : "",
                'recipient' : ""
            }

        if len(company.web_sites):
            data['contacts']['site'] = company.web_sites[0]

        if len(company.phones):
            data['contacts']['phone'] = company.phones[0]

        if len(company.emails):
            data['contacts']['email'] = company.emails[0]

        if len(company.offices):
            office_list = []
            data['contacts']['offices'] = office_list
            for office in company.offices:
                office_data = {'city' : office.city,
                               'information' : office.information,
                               'imgID' : office.get_map_img_id(),
                               'img_src' : office.get_map_url(company.rek_id),
                               'img_width' : office.get_map_dimensions()[0],
                               'img_height' : office.get_map_dimensions()[1]}
                office_list.append(office_data)

        #        'company_logo' : company.get_logo_url(),    -> company_logo_url
        #        'rek_id' : company.rek_id,                  -> companyRekId

        return data