Exemplo n.º 1
0
def invite_admin():
    form = InviteForm()

    if request.method == 'GET':
        return render_template('account/admin.html', user=[], form=form)

    if request.method == 'POST' and form.validate_on_submit():
        existing_user = User.get(email=form.email.data)
        if existing_user is None:
            try:
                realtor = User.get(accounts_realtor=current_user.get_account())
                send_invitation(form.email.data,
                                realtor=realtor,
                                new_user=True)
                User.add(form.email.data, form.first_name.data, form.last_name.data, \
                    current_user.get_account(), 'admin', invited_by=current_user.get_id(), confirmed=False)
                flash("Invitation sent", category='success')
            except:
                flash("Error inviting team member", category='danger')
                return render_template('account/admin.html', form=form)

            return redirect(url_for('account.admins'))
        else:
            flash("User already exists", category='danger')
            return render_template('account/admin.html', user=[], form=form)
    else:
        flash_errors(form)
        return render_template('account/admin.html', user=[], form=form)
Exemplo n.º 2
0
def edit_viewer(id, viewer_id):
    form = InviteForm()
    user = User.get(id=viewer_id)
    user_role = user['role']

    if request.method == 'GET':
        form.first_name.data = user['first_name']
        form.last_name.data = user['last_name']
        form.email.data = user['email']
        form.cell.data = user['cell']
        form.partner_type.data = user['partner_type'] if 'partner_type' in user else None

        return render_template('project/viewer.html', id=id, user=user, user_role=user_role, form=form)

    if request.method == 'POST' and form.validate_on_submit():
        try:
            realtor = User.get(accounts_realtor=current_user.get_account())
            print(form.partner_type.data)
            User.update(viewer_id, form.email.data, form.first_name.data, form.last_name.data, form.cell.data, partner_type=form.partner_type.data)
            send_invitation(form.email.data, realtor=realtor, new_user=True)
            flash("Invitation resent", category='success')
        except:
            flash("Error inviting viewer", category='danger')
            return render_template('project/viewer.html', form=form, user=user, user_role=user_role)

        return redirect(url_for('project.project_steps', id=id))
    else:
        flash_errors(form)
        return render_template('project/viewer.html', id=id, user=[], user_role=user_role, form=form)
Exemplo n.º 3
0
def edit_admin(id):
    form = InviteForm()

    if request.method == 'GET':
        user = User.get(id)
        form.first_name.data = user['first_name']
        form.last_name.data = user['last_name']
        form.email.data = user['email']

        return render_template('account/admin.html',
                               id=id,
                               user=user,
                               form=form)

    if request.method == 'POST' and form.validate_on_submit():
        try:
            realtor = User.get(accounts_realtor=current_user.get_account())
            User.update(id, form.email.data, form.first_name.data,
                        form.last_name.data)
            send_invitation(form.email.data, realtor=realtor, new_user=True)
            flash("Invitation resent", category='success')
        except:
            flash("Error inviting team member", category='danger')
            return render_template('account/admin.html', form=form)

        return redirect(url_for('account.admins'))
    else:
        flash_errors(form)
Exemplo n.º 4
0
def admins():
    users = User.all(account=current_user.get_account())
    count = users.count(True)
    return render_template('account/admins.html',
                           users=users,
                           count=count,
                           title="Welcome")
Exemplo n.º 5
0
def add_template():
    form = TemplateForm()
    if request.method == 'POST' and form.validate_on_submit():
        template = Template(form.name.data, current_user.get_account())
        id = template.add()
        return redirect(url_for('account.template_steps', id=id))
    else:
        flash_errors(form)
    return render_template('account/template.html', template=[], form=form)
Exemplo n.º 6
0
def add_project():
    form = ProjectForm()
    if request.method == 'GET':
        templates = Template.all(current_user.get_account())
        form.template.choices = [("111111111111111111111111", "Use a template...")] + [(template['_id'], template['name']) for template in templates]

    if request.method == 'POST' and form.validate_on_submit():
        if form.photo.data:
            s3_filepath = s3_upload(form.photo, 'photo')
        else:
            s3_filepath = None

        if form.close_date.data is None:
            date_time = ''
        elif form.close_time.data is None:
            date_time = datetime.datetime.combine(form.close_date.data, datetime.time.min)
        else:
            date_time = datetime.datetime.combine(form.close_date.data, form.close_time.data)

        project = Project(form.name.data, form.address1.data, \
        form.address2.data, form.city.data, form.state.data, form.zip.data, \
        date_time, photo=s3_filepath)
        project_id = project.add()

        # Add user's template steps to new project
        template_steps = list(TemplateStep.all(form.template.data))
        template_steps_count = template_steps.count(True)
        for template_step in template_steps:
            # takes the account steps and derives the new date based on the close date
            if 'days_before_close' in template_step['steps'] and form.close_date.data:
                days_before_close = template_step['steps']['days_before_close']

                if days_before_close:
                    due_date = form.close_date.data - datetime.timedelta(days=days_before_close)
                    due_date_time = datetime.datetime.combine(due_date, datetime.datetime.min.time())
                else:
                    due_date_time = None
            else:
                due_date_time = None

            name = template_step['steps']['name'] if 'name' in template_step['steps'] else None
            notes = template_step['steps']['notes'] if 'notes' in template_step['steps'] else None

            project_step = ProjectStep(project_id, name=name, notes=notes, due_date=due_date_time, status='red')
            project_step.add()
        flash("Successfully created %s with %s steps" % (form.name.data, template_steps_count), category='success')
        return redirect(url_for('project.project_steps', id=project_id))
    else:
        flash_errors(form)
    return render_template('project/project.html', id=[], form=form)
Exemplo n.º 7
0
def invite_viewer(id, role):
    form = InviteForm()

    if request.method == 'GET':
        return render_template('project/viewer.html', id=id, user=[], user_role=role, form=form)

    if request.method == 'POST' and form.validate_on_submit():
        existing_user = User.get(email=form.email.data)
        realtor = User.get(accounts_realtor=current_user.get_account())

        try:
            if existing_user is None:
                send_invitation(form.email.data, realtor=realtor, new_user=True)

                if role == 'partner': # it's a partner
                    text_alert = False
                    email_alert = False
                else: # it's a client
                    text_alert = False ## Update this line to True when we buy Twilio
                    email_alert = True

                User.add(form.email.data, form.first_name.data, form.last_name.data, \
                    current_user.get_account(), role, invited_by=current_user.get_id(), \
                    confirmed=False, project=[id], email_alert=email_alert, text_alert=text_alert, \
                    partner_type=form.partner_type.data)
            else:
                send_invitation(form.email.data, realtor=realtor, new_user=False)
                User.update(existing_user['_id'], form.email.data, project=id)

            flash("Invitation sent", category='success')
            return redirect(url_for('project.project_steps', id=id))
        except:
            flash("Error inviting viewer", category='danger')
            return render_template('project/viewer.html', id=id, form=form)
    else:
        flash_errors(form)
        return render_template('project/viewer.html', id=id, user=[], form=form)
Exemplo n.º 8
0
    def all(active=True, complete=False, sort='update_date', order=-1):
        get = {'active': active}

        if complete == False:  #this is the default and the projects results
            get['complete_date'] = {'$exists': complete}
        else:  #this limits to the last 30 days until we build paging
            thirty_days_before = datetime.datetime.today(
            ) - datetime.timedelta(days=30)
            get['complete_date'] = {'$gte': datetime.datetime(2018, 7, 5)}

        if current_user.get_project() == 'all':  # realtor/admin's projects
            get['account'] = current_user.get_account()
            return mongo.db.projects.find(get).sort(sort, order)

        else:  # it's a client/partner
            projects_to_retrieve = current_user.get_project()
            projects_to_retrieve = [ObjectId(s) for s in projects_to_retrieve]
            get['_id'] = {'$in': projects_to_retrieve}
            return mongo.db.projects.find(get).sort(sort, order)
Exemplo n.º 9
0
def project_steps(id):
    project_steps = list(ProjectStep.all(id, active=True, include_complete=True))
    if not project_steps:
        project_steps = []

    # have to convert to list so i can iterate over users and pass users to template
    users = list(User.all(project=id))
    clients_count = sum(1 for user in users if user['role']=='client')
    partners_count = sum(1 for user in users if user['role']=='partner')

    project = Project.get(id)
    realtor = User.get(accounts_realtor=current_user.get_account())

    if project['close_date']:
        days_left = (project['close_date'].date() - datetime.datetime.now().date()).days
        if days_left < 0:
            days_left = 0
    else:
        days_left = -1
    return render_template('project/projectsteps.html', id=id, project_steps=project_steps, users=users, project=project, realtor=realtor, days_left=days_left, partners_count=partners_count, clients_count=clients_count)
Exemplo n.º 10
0
    def add(self):
        ### Enables no closing date to be added when project is created ###
        if self.close_date is None:
            close_date = ''
        else:
            close_date = self.close_date

        return mongo.db.projects.insert({
            'name':
            self.name,
            'address1':
            self.address1,
            'address2':
            self.address2,
            'city':
            self.city,
            'state':
            self.state,
            'zip':
            self.zip,
            'close_date':
            close_date,
            'photo':
            self.photo,
            'user':
            current_user.get_id(),
            'account':
            current_user.get_account(),
            'active':
            True,
            'steps': [],
            'create_date':
            datetime.datetime.utcnow(),
            'update_date':
            datetime.datetime.utcnow()
        })
Exemplo n.º 11
0
def templates():
    templates = Template.all(current_user.get_account())
    count = templates.count(True)
    return render_template('account/templates.html',
                           templates=templates,
                           count=count)