Esempio n. 1
0
def edit_project(request, id):
    template_data = {
        'company_members':[UserController.GetUserByUserId(c) for c in request.company.members],
        'data_points':[DataPointController.LoadDataPoint(d).get_unconfigured_config() for d in request.company.data_points_available],
        'actions':[ActionController.LoadAction(a).get_unconfigured_config() for a in request.company.actions_available],
        'outputs':[OutputController.LoadOutput(o).get_unconfigured_config() for o in request.company.outputs_available],
        'visualizations':[VisualizationController.LoadVisualization(v).get_unconfigured_config() for v in request.company.visualizations_available],
    }
    project = ProjectsController.GetProjectById(request.company, request.user, id)
    if not project:
        messages.error(request, constants.TEMPLATE_STRINGS['view_project']['message_not_project_member'])
        return redirect('/%s/%s' % (settings.SITE_URLS['company_prefix'], request.company.id))

    if request.method == 'POST' and request.POST.get('delete'):
        ProjectsController.MarkProjectAsInactive(request.company, id)
        messages.info(request, constants.TEMPLATE_STRINGS['manage_project']['message_project_inactive'] % project.display_name)
        return redirect('/%s/%s' % (settings.SITE_URLS['company_prefix'], request.company.id))
    elif request.method == 'POST':
        passed, errors = ProjectsController.UpdateProjectFromFormValues(id, request.company, request.POST)
        if passed:
            ActivityRecordsController.RecordProjectSaved(request.user, request.company, project)
            messages.info(request, constants.TEMPLATE_STRINGS['manage_project']['message_project_saved'] % request.POST['display_name'])
            return redirect('/%s/%s' % (settings.SITE_URLS['company_prefix'], request.company.id))
        template_data['errors'] = errors
        template_data['project'] = request.POST
    else:
        template_data['project'] = project
    return render_to_device(
        request,
        template_data,
        '/themanager/project_edit.html'
    )
Esempio n. 2
0
def edit_user(request, id=None):
    template_data = {
        'is_edit':bool(id is not None)
    }
    if request.method == 'POST':
        if id:
            passed, errors = UserController.UpdateUserFromValues(id, request.POST, request.company)
        else:
            passed, errors = UserController.CreateNewUserFromValues(request.POST, request.company)
        if passed:
            user = UserController.GetUserByEmail(request.POST['email'])
            CompaniesController.AddUserToCompany(request.company, user)
            if id:
                message_key = 'message_user_saved'
                ActivityRecordsController.RecordUserSaved(request.user, request.company, secondary_user=user)
            else:
                message_key = 'message_user_created'
                ActivityRecordsController.RecordUserCreated(request.user, request.company, secondary_user=user)
            messages.info(request, constants.TEMPLATE_STRINGS['manage_user'][message_key] % request.POST['email'])
            if request.GET.get('next'):
                return redirect(request.GET['next'])
            return redirect('/%s/%s' % (settings.SITE_URLS['company_prefix'], request.company.id))
        template_data['errors'] = errors
        template_data['subject_user'] = request.POST
    else:
        template_data['subject_user'] = UserController.GetUserByUserId(id) if id else None
    return render_to_device(
        request,
        template_data,
        '/themanager/user_edit.html'
    )
Esempio n. 3
0
def company_root(request):
    template_data = {
        'projects':ProjectsController.GetCompanyProjectsForUser(request.company, request.user),
        'company_activity':ActivityRecordsController.GetAndFormatCompanyWideActivity(request.user, request.company),
        'members':CompaniesController.GetAllActiveCompanyMembers(request.company),
    }
    return render_to_device(
        request,
        template_data,
        '/themanager/company_home.html'
    )
Esempio n. 4
0
def landing_page(request):
    template_data = {}
    if request.method == 'POST':
        passed, errors = login_form_is_valid(request)
        if passed:
            passed, errors, _redirect = UserController.UserCanBeLoggedInAndRedirected(
                request,
                request.POST['username'],
                request.POST['password'],
            )
            if passed:
                user = UserController.GetUserByEmail(request.POST['username'])
                ActivityRecordsController.RecordLogin(user, CompaniesController.IdentifyCompanyForUser(user))
                return _redirect #redirect('/company/50fed64025f0fc4588a64c70/projects/IAuIbtFzmqdMfZT/dashboard')
        template_data['login_form'] = {
            'errors':errors,
            'username':request.POST.get('username')
        }
    return render_to_device(request, template_data, '/themanager/login.html')
Esempio n. 5
0
def change_password(request):
    errors = []
    if request.method == 'POST':
        current_password = request.POST.get('current_password')
        new_password_1 = request.POST.get('new_password_1')
        new_password_2 = request.POST.get('new_password_2')
        if not current_password or not new_password_1 or not new_password_2:
            errors.append(constants.TEMPLATE_STRINGS['change_password']['form_errors_incomplete'])
        if not errors and not request.user.check_password(current_password):
            errors.append(constants.TEMPLATE_STRINGS['change_password']['form_errors_current_password'])
        if not errors and not new_password_1 == new_password_2:
            errors.append(constants.TEMPLATE_STRINGS['change_password']['form_errors_new_password_match'])
        if not errors and not re.search(r'^\w+$', new_password_1) or len(new_password_1) < 6:
            errors.append(constants.TEMPLATE_STRINGS['change_password']['form_errors_new_password_strength'])
        if not errors:
            request.user.set_password(new_password_1)
            request.user.save()
            messages.info(request, constants.TEMPLATE_STRINGS['change_password']['messages_password_saved'])
            return redirect('/%s/%s' % (settings.SITE_URLS['company_prefix'], request.company.id))
    return render_to_device(
        request,
        {'errors':errors},
        '/themanager/change_password.html'
    )
Esempio n. 6
0
def view_project(request, project_id):
    if 'delete_insight' in request.GET:
        delete_insight = request.GET.get('delete_insight')
        insight = DashboardsController.GetDashboardById(delete_insight)
        if insight and (is_company_admin(request.user, request.company) or request.user.username == insight.username):
            DashboardsController.DeleteDashboardById(delete_insight)
            messages.info(request, constants.TEMPLATE_STRINGS['view_project']['message_insight_deleted'])

    template_data = {
        'project':ProjectsController.GetProjectById(request.company, request.user, project_id),
        'project_activity':ActivityRecordsController.GetAndFormatProjectWideActivity(request.user, request.company, project_id)
    }

    if not template_data['project']:
        raise Http404

    template_data['project_members'] = [UserController.GetUserByUserId(u) for u in request.company.administrators] + [UserController.GetUserByUserId(u) for u in template_data['project'].members]
    template_data['project_insights'] = sorted([i for i in [DashboardsController.GetDashboardById(d) for d in template_data['project'].insights] if i['active'] == True and i['deleted'] == False], key=lambda db: db.last_saved, reverse=True)

    return render_to_device(
        request,
        template_data,
        '/themanager/project_view.html'
    )