Beispiel #1
0
    def seed_static_data(self):
        self.event1 = self.add_event(key='event1')
        self.event2 = self.add_event(key='event2')
        self.user1 = self.add_user('*****@*****.**')
        self.user2 = self.add_user('*****@*****.**')
        self.user3 = self.add_user('*****@*****.**')

        self.event1.add_event_role('admin', self.user1.id)
        self.event2.add_event_role('admin', self.user2.id)

        db.session.commit()

        self.tags = [
            Tag(self.event1.id),
            Tag(self.event1.id),
            Tag(self.event2.id)
        ]

        db.session.add_all(self.tags)
        db.session.commit()

        tag_translations = [
            TagTranslation(self.tags[0].id, 'en', 'English Tag 1 Event 1'),
            TagTranslation(self.tags[0].id, 'fr', 'French Tag 1 Event 1'),
            TagTranslation(self.tags[1].id, 'en', 'English Tag 2 Event 1'),
            TagTranslation(self.tags[1].id, 'fr', 'French Tag 2 Event 1'),
            TagTranslation(self.tags[2].id, 'en', 'English Tag 1 Event 2')
        ]

        db.session.add_all(tag_translations)
        db.session.commit()

        self.user1_headers = self.get_auth_header_for('*****@*****.**')
        self.user2_headers = self.get_auth_header_for('*****@*****.**')
        self.user3_headers = self.get_auth_header_for('*****@*****.**')
Beispiel #2
0
def index():
    return render_template('database/index.html',
                           title="Database",
                           users=User.all(User()),
                           pages=Page.get_all_pages(Page()),
                           comments=Comment.get_all_comments(Comment()),
                           tags=Tag.get_all_tags(Tag()))
Beispiel #3
0
def edit(tag_id):
    tag = Tag.get_tag(Tag(), tag_id)
    form = EditForm(secret_key=app.config['SECRET_KEY'], obj=tag)
    if form.validate_on_submit():
        form.populate_obj(tag)
        tag.save_tag(tag)
        flash('Tag edited successfully.', 'success')
        return redirect('/tags')
    elif form.is_submitted():
        flash('Can\'t submit empty tag!', 'warning')
    return render_template('tags/edit.html',
                           title="Edit Tag",
                           form=form)
Beispiel #4
0
def new():
    tag = Tag(('', ''))
    form = NewForm(secret_key=app.config['SECRET_KEY'], obj=tag)
    if form.validate_on_submit():
        form.populate_obj(tag)
        Tag.new_tag(tag, tag)
        flash('New tag created successfully!', 'success')
        return redirect('/tags')
    elif form.is_submitted():
        flash('The new tag can\'t be empty!', 'warning')
    return render_template('tags/new.html',
                           title="New Tag",
                           form=form)
Beispiel #5
0
 def run(self, count):
     int_count = count if type(count) == int else int(count)
     for _ in range(int_count):
         tag = Tag(fake.sentence())
         db.session.add(tag)
         db.session.commit()
     print('done')
Beispiel #6
0
 def add_tag(self, event_id=1, names={'en': 'Tag 1 en', 'fr': 'Tag 1 fr'}):
     tag = Tag(event_id)
     db.session.add(tag)
     db.session.commit()
     translations = [
         TagTranslation(tag.id, k, name) for k, name in names.items()
     ]
     db.session.add_all(translations)
     db.session.commit()
     return tag
Beispiel #7
0
    def post(self, event_id):
        req_parser = reqparse.RequestParser()
        req_parser.add_argument('name', type=dict, required=True)
        args = req_parser.parse_args()
        name_translations = args['name']

        tag = Tag(event_id)
        for language, name in name_translations.iteritems():
            tag.translations.append(TagTranslation(tag.id, language, name))
        tag_repository.add_tag(tag)

        return _serialize_tag_detail(tag), 201
Beispiel #8
0
    def post(self, id):
        args = parser.parse_args()
        web_component = WebComponent.query.filter_by(id=id).first_or_404()

        # Get or create
        name = args['name']
        tag = Tag.query.filter_by(name=name).first()
        if not tag:
            tag = Tag(name=name)

        web_component.tags.append(tag)
        db.session.commit()

        return dict(web_component)
Beispiel #9
0
                                    password='******',
                                    gender=gender,
                                    age=seed_data.random_int(min=18, max=40),
                                    preference=preference,
                                    position=position,
                                    lat=lat,
                                    lng=lng,
                                    biography=seed_data.text(max_nb_chars=200),
                                    login_time=login_time)

            Picture.add_pic(uid=user.id, url=url, profile_picture=True)

            random_int = seed_data.random_int(min=0, max=(len(tag_data) - 1))
            tag = tag_data[random_int]

            Tag.add_tag(tag_uid=user.id, tag=tag)

        # add admin account
        User.create_user(first="admin",
                         last="admin",
                         email="*****@*****.**",
                         activation=None,
                         username="******",
                         password="******",
                         gender="male",
                         age=21,
                         preference="both",
                         position="Pluto",
                         lat=0,
                         lng=0,
                         biography="I love you so Matcha :)",
Beispiel #10
0
def index():
    return render_template('dashboard/index.html',
                           title="Dashboard",
                           pages=Page.get_recent(Page(), 5),
                           comments=Comment.recent_comments(Comment(), 5),
                           tags=Tag.popular_tags(Tag(), 5))
Beispiel #11
0
def delete(tag_id):
    print(tag_id)
    Tag.delete_tag(Tag(), Tag((tag_id, '')))
    flash('Tag deleted successfully!', 'success')
    return redirect('/tags')
Beispiel #12
0
def index():
    return render_template('tags/index.html',
                           title="Tags",
                           tags=Tag.get_all_tags(Tag()),
                           form=Form(secret_key=app.config['SECRET_KEY']))
Beispiel #13
0
 def get_tags(self):
     return Tag.get_by_page_id(Tag(), self.page_id)