コード例 #1
0
def loadTags():
    try:
        tags = [
            Tag(57, 0, "RT_RPM", "RT velocidade do motor RPM", "R", "G01"),
            Tag(55, 0, "Hookload", "Carga no gancho", "R", "G02"),
            Tag(55, 4, "STANDPIPE", "Riser pressure", "R", "G03"),
            Tag(55, 8, "LEFTCATHEADPRE", "Left cat head pressure", "R", "G03"),
            Tag(57, 4, "RTMotorCurrent", "RT corrente do motor A", "R", "G04")
        ]

        return tags
    except Exception as e:
        print e
        logging.error(str(e))
コード例 #2
0
ファイル: bootstrap.py プロジェクト: worldeditor11/maniwani
def setup_tags(json_settings):
    for tag_info in json_settings["tags"]:
        tag_name = tag_info["tag"]
        bg_style = tag_info["bgstyle"]
        text_style = tag_info["textstyle"]
        tag = Tag(name=tag_name, bg_style=bg_style, text_style=text_style)
        db.session.add(tag)
コード例 #3
0
 def post_impl(self):
     parser = reqparse.RequestParser()
     parser.add_argument("subject", type=str)
     parser.add_argument("body", type=str, required=True)
     parser.add_argument("board", type=int, required=True)
     parser.add_argument("tags", type=str)
     args = parser.parse_args()
     if "media" not in request.files or not request.files["media"].filename:
         raise SubmissionError("A file is required to post a thread!",
                               args["board"])
     tags = []
     if args["tags"]:
         tag_list = args["tags"].replace(" ", "").split(",")
         for tag_name in tag_list:
             tag = db.session.query(Tag).filter(
                 Tag.name == tag_name).one_or_none()
             if tag is None:
                 tag = Tag(name=tag_name)
                 db.session.add(tag)
             tags.append(tag)
     db.session.flush()
     thread = Thread(board=args["board"], views=0, tags=tags)
     # FIXME: use one transaction for all of this, the current state defeats
     # the purpose of having transactions in the first place
     db.session.add(thread)
     db.session.commit()
     NewPost().post(thread_id=thread.id)
     return thread
コード例 #4
0
def get_tags(args: dict) -> List[Tag]:
    "Returns a list of Tag objects from the given tag list."
    if not args["tags"]:
        return

    tags = list(map(lambda s: s.strip(), args["tags"].split(",")))
    ret = []

    # add all the tags that already exist in the database
    for row in db.session.query(Tag, Tag.name).filter(Tag.name.in_(tags)):
        tags.remove(row.name)
        ret.append(row.Tag)

    # create the remaining tabs and add them to the transaction
    # (the above loop removes all tags that already exist in the database
    # from the list, # therefore simply looping over the tags list should
    # suffice)
    for tag in tags:
        ret.append(Tag(name=tag))

    return ret
コード例 #5
0
import os


from customjsonencoder import CustomJSONEncoder
from model.Board import Board
from model.Slip import gen_slip
from model.Tag import Tag
import model.Media
import model.Poster
from shared import db

db.create_all()
# set up some boards
for board_name in ("anime", "tech", "meta", "politics", "gaming", "music"):
    board = Board(name=board_name)
    db.session.add(board)
# admin credentials generation
admin = gen_slip("admin", "admin")
admin.is_admin = True
db.session.add(admin)
# special tags
for tag_name, bg_style, text_style in (("general", "bg-secondary", "text-light"),):
    tag = Tag(name=tag_name, bg_style=bg_style, text_style=text_style)
    db.session.add(tag)
db.session.commit()
# write a secret so we can have session support
open("secret", "w").write(str(os.urandom(16)))
# create upload and thumbnail directory if necessary
if not os.path.exists("uploads/thumb"):
    os.makedirs("uploads/thumb")