예제 #1
0
def mer230_base_tags():
    tt_dict = [
        {'pos': 1, 'name': 'Ts_active',},
        {'pos': 2, 'name': 'Ts_reactive',},
        {'pos': 3, 'name': 'T1_active',},
        {'pos': 4, 'name': 'T1_reactive',},
        {'pos': 5, 'name': 'T2_active',},
        {'pos': 6, 'name': 'T2_reactive',},
        {'pos': 7, 'name': 'Ts_phaseA',},
        {'pos': 8, 'name': 'Ts_phaseB',},
        {'pos': 9, 'name': 'Ts_phaseC',},
        {'pos': 10, 'name': 'T1_phaseA',},
        {'pos': 11, 'name': 'T1_phaseB',},
        {'pos': 12, 'name': 'T1_phaseC',},
        {'pos': 13, 'name': 'T2_phaseA',},
        {'pos': 14, 'name': 'T2_phaseB',},
        {'pos': 15, 'name': 'T2_phaseC',},
        {'pos': 16, 'name': 'Ps/100',},
        {'pos': 17, 'name': 'Pa/100',},
        {'pos': 18, 'name': 'Pb/100',},
        {'pos': 19, 'name': 'Pc/100',},
        {'pos': 20, 'name': 'Ua/100',},
        {'pos': 21, 'name': 'Ub/100',},
        {'pos': 22, 'name': 'Uc/100',},
        {'pos': 23, 'name': 'Ia/1000',},
        {'pos': 24, 'name': 'Ib/1000',},
        {'pos': 25, 'name': 'Ic/1000',},
        {'pos': 26, 'name': 'Hz/100',},
    ]

    for t in tt_dict:
        t = Tag(name=t['name'],
                group_id=1)
        t.save()
예제 #2
0
    def test_should_create_one_tag_with_same_text(self):
        tag_name = "tag name"
        tag1 = Tag(text=tag_name)
        tag1.save()
        tags_with_name = Tag.query.filter_by(text=tag_name).all()
        self.assertEqual(len(tags_with_name), 1)

        tag2 = Tag.create_unique(tag_name)
        tags_with_name = Tag.query.filter_by(text=tag_name).all()
        self.assertEqual(len(tags_with_name), 1)
        self.assertEqual(tag2, tag1)
예제 #3
0
def get_tag(name, kind):
    try:
        tag = Tag.objects.get(name=name)
        return tag
    except ObjectDoesNotExist:
        kind_obj = None
        if kind != None:
            try:
                kind_obj = TagKind.objects.get(name=kind)
            except ObjectDoesNotExist:
                kind_obj = TagKind()
                kind_obj.name = kind
                kind_obj.description = "{kind_%s}" % kind
                kind_obj.icon = "{kind_icon_%s}" % kind
                kind_obj.save()

        tag = Tag()
        tag.name = name
        tag.kind = kind_obj
        tag.save()
        return tag
예제 #4
0
def tags():
    id = request.values.get('id', default=0, type=int)
    id_user = current_user.get_id()
    tag = session.query(Tag).filter(Tag.id == id
                                    and Tag.id_user == id_user).one_or_none()

    if not tag:
        tag = Tag()
    elif request.args.get('action', default='', type=str) == 'delete':
        session.delete(tag)
        session.commit()
        flash(f"Tag was deleted (id='{tag.id}', name='{tag.name}')")
        return redirect(url_for('tags'))

    form = TagForm(obj=tag)

    if form.validate_on_submit():
        tag.add_form_data(form)
        session.add(tag)
        session.commit()
        if id:
            flash(f"Tag was updated (id='{tag.id}', name='{tag.name}')")
        else:
            flash(f"Tag was created (id='{tag.id}', name='{tag.name}')")
        return redirect(url_for('tags'))

    to_form = {
        "title":
        "Tags",
        "id":
        id,
        "form":
        form,
        "tags":
        session.query(Tag).filter(Tag.id_user == id_user).order_by('id').all(),
    }
    return render_template("tags.html", **to_form)
예제 #5
0
def get_tag_items(request, tags):
    l = tags.split(",")
    ids = []
    for v in l:
        ids.append(int(v))
    ids = sorted(list(set(ids)))
    tags = Tag.objects.filter(id__in=ids)
    current_tags = tags
    
    # Construct current taglist string
    ids = []
    for tag in tags:
        ids.append(tag.id)
    tids = ",".join(map(str, ids))
    if len(tids)>0:
        tids = tids + ","

    # Get subtags
    subtags = Tag.subtags(tags)


    # Get items by subtags
    latest_item_list = Item.subitems(tags).order_by('-updated')
    size = len(latest_item_list)
    
    # Filter tag list
    tags = []
    for tag in subtags:
        if tag.count != size:
            tags.append(tag)
    subtags = tags
   
    # Build pagination
    page = request.GET.get('page')
    paginator = Paginator(latest_item_list, 10)
    try:
        items = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        items = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        items = paginator.page(paginator.num_pages)
    
    items = paginator_post_process(items)
    return render(request, 'tag_items.html', {'tags': subtags, 'tids': tids, 'items': items, 'current_tags': current_tags})
예제 #6
0
def upload():
    """
    Отвечает за вывод страницы загрузки и загрузку файлов
    :return: Страница загрузки
    """

    form = UploadVideoForm()

    if form.validate_on_submit():
        file = request.files['video']

        video = save_video(file, form.title.data)

        if not video:
            form.video.errors.append(
                ValidationError('Ошибка при загрузке видео'))
            return render_template('upload_video.html',
                                   form=form,
                                   user=cur_user(),
                                   formats=app.config['ALLOWED_EXTENSIONS'])

        data = JSONDecoder().decode(form.geotag_data.data)
        if data['needed']:
            for coords in data['coords']:
                geo_tag = Geotag(*coords)
                video.geotags.append(geo_tag)

        if form.tags.data:
            tags = form.tags.data.split(',')
            for tag_name in tags:
                video_tag = Tag.create_unique(text=tag_name)
                video.tags.append(video_tag)
        db.session.commit()
        return redirect(url_for("main"))

    if not form.geotag_data.data:
        form.geotag_data.data = dumps({'needed': False, 'coords': []})

    return render_template('upload_video.html',
                           form=form,
                           user=cur_user(),
                           formats=app.config['ALLOWED_EXTENSIONS'])
예제 #7
0
def get_tags(request):
    tags = Tag.with_counts()
    return render(request, 'tags.html', {'tags': tags})
예제 #8
0
 def setUp(self):
     BaseTestModelSuite.setUp(self)
     self.tag1 = Tag(text="hello")
     self.tag2 = Tag(text="world")
     self.video.tags.append(self.tag1)
     db.session.commit()