Пример #1
0
def star_backend(language='en'):
    if session['username']:
        username = session['username']
        project_name = request.args.get('project', '')
        starred_project = StarredProjects.objects(username=username, project_name=project_name).count()
        if starred_project > 0:
            starred_project = StarredProjects.objects.get(username=username, project_name=project_name)
            starred_project.delete()
            return 'Star'
        else:
            starred_project = StarredProjects(username=username, project_name=project_name)
            starred_project.save()
            return 'Unstar'
    else:
        return 'Fail'
Пример #2
0
def profile_backend(language='en'):

    if session['username']:
        username = session['username']
        user = User.objects.get(username=username)
        starred_projects = StarredProjects.objects(username=username)
        created_projects = CreatedProjects.objects(username=username)
        if not user['admin']:
            alert_message = request.args.get('alert_message', '')
            alert_type = request.args.get('alert_type', '')
            if alert_type:
                return render_template('user.html', user=user, disp_user=user,
                                       starred_projects=starred_projects,
                                       created_projects=created_projects,
                               language=language, alert_message=alert_message,
                               alert_type=alert_type)
            else:
                return render_template('user.html', user=user, disp_user=user,
                                       starred_projects=starred_projects,
                                       created_projects=created_projects,
                                       language=language)
        else:
            admin = user
            username = request.args.get('username', '')
            if username:
                user = User.objects.get(username=username)
            return render_template('user.html', user=admin, disp_user=user,
                                   starred_projects=starred_projects,
                                   created_projects=created_projects,
                                   language=language)

    else:
        return redirect(url_for('index.index_backend'))
Пример #3
0
def delete_project_backend(language='en'):

    if 'username' in session:
        username = session['username']
        user = User.objects.get(username=username)
        project_name = request.args.get('projectname', '')
        count = CreatedProjects.objects(username=username, project_name=project_name).count()
        if count <= 0 and not user['admin']:
            return redirect(url_for('index.index_backend', language=language))
        else:
            CreatedProjects.objects(project_name=project_name).delete()
            StarredProjects.objects(project_name=project_name).delete()
            mongo.db.projects.remove({'name': project_name})
            mongo.db.samples.remove({'project_name': project_name})
            mongo.db.fields.remove({'project_name': project_name})
            mongo.db.mapping.remove({'project_name': project_name})
            return redirect(url_for('.projects_backend', language=language))
    else:
        return redirect(url_for('index.index_backend', language=language))
Пример #4
0
def projects_backend(language='en'):
    """
    Returns the projects page.
    :param language: Defines the language ('en' or 'cn') used for the template.
    :return: The rendered project.html template which contains all the projects for now.
                /projects
    """
    project_list = list(mongo.db.projects.find())

    alertinfo = ''
    if 'insert_error' in session and session['insert_error'] != '':
        succeed = 'False'
        alertinfo = session['insert_error']
        session['insert_error'] = ''
    else:
        succeed = 'True'
        session['insert_error'] = ''

    print succeed
    print session['insert_error']
    if 'username' in session:
        user = User.objects.get(username=session['username'])
        for project in project_list:
            project_name = project['name']
            starred_project = StarredProjects.objects(username=user['username'], project_name=project_name).count()
            created_project = CreatedProjects.objects(username=user['username'], project_name=project_name).count()
            if starred_project > 0:
                project['star'] = True
            else:
                project['star'] = False
            if created_project > 0:
                project['delete'] = True
            else:
                project['delete'] = False
        return render_template('projects.html',language=language, project_list=project_list, user=user, succeed=succeed,
                               alertinfo=alertinfo)
    return render_template('projects.html', language=language, project_list=project_list, succeed=succeed,
                           alertinfo=alertinfo)