예제 #1
0
    def validatePage(self):
        try:
            tags, questions = self.ui.questionWidget.dump()

            for tag in tags:  # [tag.name for tag in project.tags]
                if tag not in list(map(lambda tag: tag.name,
                                       self.project.tags)):
                    # import pdb; pdb.set_trace()
                    self.project.tags.append(model.Tag(tag, 0))

            # self.project.tags = tags
            self.project.questions = questions

            api.validate_project(self.project)

            # TODO: Do at least one of the following:

            # 1. Set the project total_questions_per_exam number before generating
            #    the master here (with a dialog or a modified ui)
            # 2. Get the total_questions_per_exam number out of the master and into
            #    gen.py as a parameter (just like test_count)

            # Uncomment when one of the above is done.

            # master_data = api.render_master(self.project, TEMPLATE_PATH)
            # api.save_master(master_data)

            return True
        except Exception as e:
            self.diag = QMessageBox(QMessageBox.Warning, "Warning", str(e))
            self.diag.show()

            return False
예제 #2
0
def add_tag(session, pkgname, tag, user):
    """ Add a provided tag to the specified package. """

    tag = tag.lower()

    package = model.Package.by_name(session, pkgname)
    try:
        tagobj = model.Tag.get(session, package.id, tag)
        tagobj.like += 1
        user.score += 1
    except NoResultFound:

        # If no such tag exists, create a new one.  But first..
        if blacklisted(tag):
            raise ValueError("'%s' is not allowed." % tag)

        tagobj = model.Tag(package_id=package.id, label=tag)
        session.add(tagobj)
        session.flush()
        user.score += 2
    voteobj = model.Vote(user_id=user.id, tag_id=tagobj.id, like=True)
    session.add(user)
    session.add(voteobj)
    session.flush()

    fedmsg.publish('tag.create',
                   msg=dict(
                       tag=tagobj,
                       vote=voteobj,
                       user=user,
                   ))

    return 'Tag "%s" added to the package "%s"' % (tag, pkgname)
예제 #3
0
def parse_tag(elem):
    t = model.Tag(elem.attrib["id"])
    t.approval = elem.attrib["approval"]
    if elem.attrib["spoiler"].lower() == "true":
        t.spoiler = True
    for e in elem:
        setattr(t, e.tag, e.text)
    return t
예제 #4
0
 def update_tags(self, tags):
     tags = set(tags)
     for tag in tags:
         t = model.Tag.gql('WHERE tag=:1', tag).get()
         if not t:
             tg = model.Tag(tag=tag, count=1)
             tg.put()
         else:
             t.count = t.count + 1
             t.put()
예제 #5
0
def create_post(
    blog_name: str, post_title: str, tags: List[str], uow: AbstractUnitOfWork
):

    with uow:
        blog = uow.repo.get(name=blog_name)
        if not blog:
            blog = model.Blog(blog_name)
            uow.repo.add(blog)
        # create a post
        post = model.Post(post_title)
        post.blog = blog

        # create tags
        tag_list = [model.Tag(t) for t in tags]

        post.tags.extend(tag_list)
예제 #6
0
    def post(self):
        param = parser.parse_args()
        token = request.headers['Authorization']
        login_token = model.LoginToken.query.filter_by(token=token).first()
        user = login_token.user
        if not user:
            return base_response(code=-1, msg="用户不存在")

        if not param.title:
            return base_response(code=-2)
            
        if not param.content:
            return base_response(code=-2)

        if not param.cate_id:
            return base_response(code=-2)
    
        blog = model.Blog(title=param.title, content=param.content, category_id=param.cate_id)
        blog.user = user

        all_tags = model.Tag.query.all()
        # 最终博客的tags
        tags = []
        
        if len(param.tag_names) != 0:
            # 循环参数的tag名
            for tag_name in param.tag_names:
                # 判断是否有该tag
            for index in all_tags:
                    if tag_name == all_tags[index].tag_name:
                        tags.append(all_tags[index])
                    else:
                        new_tag = model.Tag(tag_name=tag_name)
                        tags.append(new_tag)

            blog.tags = tags
            
        db.session.add(blog)
        db.session.commit()
        return base_response()
예제 #7
0
            try:
                ing = model.Ingredient.query.filter_by(name=ingredient).one()
            except NoResultFound as e:
                ing = model.Ingredient(name=ingredient)
                model.db.session.add(ing)
            r_ing = model.RecipeIngredient(ingredient=ing,
                                           amount=amount,
                                           instructions=instructions,
                                           recipe=r)
            model.db.session.add(r_ing)

        for t in r_obj['tags']:
            try:
                tag = model.Tag.query.filter_by(name=t).one()
            except NoResultFound as e:
                tag = model.Tag(name=t)
                model.db.session.add(tag)
            r.tags.append(tag)

model.db.session.commit()

# {
#     "category": "Appetizers & Sides",
#     "cook_time": "5 - 6 Minutes",
#     "directions": "Preheat the Oven to 375\u00b0. Layer the lavash with the pear slices, pieces of Brie, prosciutto and sugar, in that order. Bake for 5-6 minutes until the Lavash is golden brown and the sugar has caramelized. Top with Baby Arugula and serve.",
#     "ingredients": [
#         "TJ's Lavash Bread (Regular or Whole Wheat)",
#         "1 TJ's Pear, thinly sliced",
#         "8 ounces (or so) TJ's Brie, cubed or torn into small pieces",
#         "2-3 slices TJ's Prosciutto, sliced thin",
#         "2-3 tablespoon TJ's Organic Brown Sugar",