Exemplo n.º 1
0
    def random(cls, limit=4, project_group=None):
        """추천알고리즘없이 임의로 프로젝트 골라오기.

        PROJECT:
        이 함수들은 성능이 좋지 않아서 PRODUCTION에서는 사용할 수 없습니다.
        batch로 project list를 준비하던가 해야겠음

        """
        if project_group is None:
            project_group = ProjectGroup.default()

        # picked priority
        selected = cls._random(limit=limit,
                               picked=True,
                               project_group=project_group)

        if len(selected) < limit:
            # 만약 limit만큼 채워지지 않았으면 조금 더 얻어오기
            chunks = cls._random(limit=limit - len(selected),
                                 project_group=project_group)
            selected.extend(chunks)

        # shuffle!
        # random.shuffle(selected)
        return selected
Exemplo n.º 2
0
 def base4erc_html(self):
     if current_user.is_authenticated:
         if self.project_group:
             return self.project_group.base4erc_html
         else:
             return "base4erc.html"
     else:
         return ProjectGroup.default().base4erc_html
Exemplo n.º 3
0
def validate_pg_slug():

    pg_slug = request.args.get('slug')
    if pg_slug and len(pg_slug.strip()):
        pg = ProjectGroup.objects(slug=pg_slug).first()
        if pg:
            return str(pg.id)  # just 200 response.

    abort(404)
Exemplo n.º 4
0
 def my_visit_log(cls, limit=4, skip=0, project_group=None):
     """방문한 프로젝트 목록"""
     from erks.models import ProjectUser
     if project_group is None:
         project_group = ProjectGroup.default()
     user = current_user._get_current_object()
     project_group_user = ProjectGroupUser.objects(
         project_group=project_group, user=user).first()
     return (entry.project for entry in ProjectUser.objects(
         project_group_user=project_group_user, user=user).only('project').
             order_by('-last_visited_at').skip(skip).limit(limit))
Exemplo n.º 5
0
 def my_belonged(cls, project_group=None):
     """current_user의 소속된 프로젝트 목록. 소유를 포함한다."""
     from erks.models import ProjectUser
     if project_group is None:
         project_group = ProjectGroup.default()
     user = current_user._get_current_object()
     project_group_user = ProjectGroupUser.objects(
         project_group=project_group, user=user).first()
     return ProjectUser.objects(project_group_user=project_group_user,
                                user=user).exclude('user',
                                                   'project_group_user')
Exemplo n.º 6
0
    def my(cls, project_group=None):
        """current_user의 소유 프로젝트 목록."""
        from erks.models import ProjectUser
        if project_group is None:
            project_group = ProjectGroup.default()
        user = current_user._get_current_object()

        pgu = ProjectGroupUser.objects(project_group=project_group,
                                       user=user).first()
        return (entry.project for entry in ProjectUser.objects(
            project_group_user=pgu, user=user, is_owner=True).only(
                'project').all())
Exemplo n.º 7
0
    def clean(self):

        # free-project-cannot-be-private
        # self.id가 없을때 product를 참고하면 오류발
        if current_app.config['BILLING']:
            if self.id and \
               (self.product is None or not self.product.support_private):
                self.private = False
                self.visible = True

        # project-group-check
        if self.project_group is None:
            self.project_group = ProjectGroup.default()
Exemplo n.º 8
0
def _user_password_reset(project_group_user_id):
    pgu = ProjectGroupUser.objects.get_or_404(id=project_group_user_id)
    if pgu.project_group == ProjectGroup.default():
        from uuid import uuid4
        from erks.utils import password_hash

        temporary_passwd = str(uuid4())[:8]
        pgu.user.password = password_hash(temporary_passwd)
        pgu.user.save()
        flash_error(gettext('임시비밀번호가 설정되었습니다. 암호는 %(temporary_passwd)s입니다.', temporary_passwd=temporary_passwd))
        return redirect(url_for(
            'project_group._user_role_changer',
            project_group_user_id=project_group_user_id))
    else:
        abort(404)
Exemplo n.º 9
0
def default_project_group_index():
    # import pdb; pdb.set_trace()
    """login여부에 따라 적절한 index로 이동."""
    slug = current_app.config['DEFAULT_PROJECT_GROUP_SLUG']
    if current_user.is_authenticated:
        return redirect(url_for('project_group.list_projects', slug=slug))
    else:
        projects = Project.random(limit=8)
        project_group = ProjectGroup.default()
        if project_group and project_group.has_theme():
            form = LoginForm(request.form)
            theme_key = project_group.theme_key
            return render_template(
                f'theme/{theme_key}/login/login_{theme_key}.html', form=form)
        else:
            return render_template('index.html', projects=projects)
Exemplo n.º 10
0
def login():
    next_url = get_redirect_target()
    form = LoginForm(request.form)
    if request.method == 'POST':
        # import pdb; pdb.set_trace()
        if form.validate():
            try:
                email_or_userid = form.email.data
                password = form.password.data
                password = password_hash(password)
                if '@' in email_or_userid:
                    user = User.objects.get(email=email_or_userid,
                                            password=password)
                else:
                    user = User.objects.get(user_id=email_or_userid,
                                            password=password)
                if user.verified:
                    login_user(user, remember=form.remember_me.data)
                    session['lang_code'] = user.locale
                    return redirect(url_for('portal.index'))
                    # return redirect_back('portal.index')
                else:
                    message = Markup(
                        lazy_gettext(
                            u'이메일 인증이 완료되지 않은 사용자입니다.<br/><a href=\'#\' style=\"color: blue;\">인증 요청</a>'
                        ))
                    flash(message)
                    # flash(lazy_gettext(u'이메일 인증이 완료되지 않은 사용자입니다.'))
            except User.DoesNotExist:
                flash(lazy_gettext(u'죄송합니다. 사용자가 존재하지 않거나 비밀번호가 일치하지 않습니다.'))
        else:
            flash(lazy_gettext(u'form검증이 실패했습니다.'))
            current_app.logger.debug(form.errors)

    project_group = ProjectGroup.default()
    if project_group and project_group.has_theme():
        return render_template(
            'theme/{theme_key}/login/login_{theme_key}.html'.format(
                theme_key=project_group.theme_key),
            form=form)
    else:
        return render_template('login/login.htm.j2', form=form, next=next_url)
Exemplo n.º 11
0
def _profile_edit():
    from erks.erks_bps.project.models import ProjectGroup
    user = current_user._get_current_object()
    form = ProfileEditForm(request.form, obj=user)

    # choices = [('', 'default'), ]
    # choices.extend([(str(g.id), g.title) for g in ProjectGroup.my()])
    choices = [(str(g.id), g.title) for g in ProjectGroup.my()]
    form.default_project_group_id.choices = choices

    if request.method == 'POST':
        if form.validate():
            form.populate_obj(user)
            user.save()
            flash_success(lazy_gettext(u'사용자 정보가 변경되었습니다.'))
            return redirect(url_for('login._profile'))
        else:
            current_app.logger.warning(form.errors)

    return render_template('login/_profile_edit.htm.j2', form=form)
Exemplo n.º 12
0
    def save(self):

        project_group = ProjectGroup()
        self.populate_obj(project_group)

        try:
            project_group.save()
        except mongoengine.errors.NotUniqueError:
            # slug  중복시 slug 명칭을 임의로 변경
            project_group.save_as_random_slug()
            flash_warning(
                lazy_gettext(u'프로젝트 ID가 중복되어 %(slug)s로 변경 되었습니다.',
                             slug=project_group.slug))

        self.write_project_order(project_group, self.erks_transaction.data)

        return project_group
Exemplo n.º 13
0
 def my_free_project(cls):
     return [
         project for project in cls.my(project_group=ProjectGroup.default())
         if project.is_free
     ]