Пример #1
0
def save_draft_and_redirect():
    print('In Method: save_draft_and_redirect()')

    title: str = request.form.get('title')
    content: str = request.form.get('content')
    timestamp: datetime = datetime.now()
    user_id: str = session['user_id']
    reading_time: int = ceil(len(content) / 1500)

    test_dict = {
        'title': title,
        'content': content,
        'timestamp': timestamp,
        'user_id': user_id,
        'reading_time': reading_time,
        'public': True,
        'public_with_link': True
    }

    handler = DbHandler()
    db = 'test'  # change for production
    collection = "stories"
    result_of_db_operation = handler.write_to_database(
        db_name=db, collection_name=collection, json_to_write=test_dict)

    if result_of_db_operation['success'] is True:
        return redirect(
            url_for('user_bps.view_draft',
                    story_id=result_of_db_operation['doc_id']))
    else:
        return redirect(
            url_for(
                'user_bps.display_editor',
                notification='Etwas ist schief gelaufen. Bitte versuche es '
                'später noch ein Mal.'))
Пример #2
0
def async_get_story_previews():
    print('In Method: async_get_story_previews()')

    index = request.args.get('index')

    selected_categories = []
    selected_lengths = []

    try:
        categories_in_url = request.args.get('categories')
        selected_categories = categories_in_url.split(',')
    except Exception as e:
        print("No categories in Url specified.")

    try:
        lengths_in_url = request.args.get('lengths')
        selected_lengths = lengths_in_url.split(',')
    except Exception as e:
        print("No lengths in Url specified.")

    handler = DbHandler()
    db = 'test'  # change for production
    collection = 'previews'
    result_of_db_operation = handler.read_document_previews(
        db_name=db,
        collection_name=collection,
        starting_id=int(index),
        amount_of_documents=8,
        categories=selected_categories,
        lengths=selected_lengths)

    if result_of_db_operation['success'] is True:
        return result_of_db_operation
    else:
        return 'False'
Пример #3
0
    def check_if_user_is_registered(self):
        print("In Method: check_if_user_is_registered()")

        handler = DbHandler()
        db = 'twitter_mmo'  # change for production
        collection = 'users'

        result_of_db_operation = handler.read_one_doc_by_param_from_database(
            db_name=db,
            collection_name=collection,
            doc_value=self.user_name,
            doc_param='user_id')

        if result_of_db_operation['success'] is True:
            self.level = result_of_db_operation['result']['level']
            self.character_class = result_of_db_operation['result'][
                'character_class']
            self.xp = result_of_db_operation['result']['xp']
            self.money = result_of_db_operation['result']['money']
            self.status = result_of_db_operation['result']['status']
            self.status_id = result_of_db_operation['result']['status_id']
            self.stats = result_of_db_operation['result']['stats']
            self.items_equipped = result_of_db_operation['result'][
                'items_equipped']
            self.items_inventory = result_of_db_operation['result'][
                'items_inventory']

            return True
        else:
            return False
Пример #4
0
    def register_user(self):
        print("In Method: register_user()")

        handler = DbHandler()
        db = 'twitter_mmo'  # change for production
        collection = 'users'

        user_dict = {
            'user_id': self.user_name,
            'level': self.level,
            'character_class': self.character_class,
            'xp': self.xp,
            'money': self.money,
            'status': self.status,
            'status_id': self.status_id,
            'stats': self.stats,
            'items_equipped': self.items_equipped,
            'items_inventory': self.items_inventory,
            'registration_time': datetime.today()
        }

        result_of_db_operation = handler.write_to_database(
            db_name=db, collection_name=collection, json_to_write=user_dict)

        if result_of_db_operation['success'] is True:
            return True
        else:
            return False
Пример #5
0
def get_all_users_in_db():
    print('In Method: get_all_users_in_db()')

    handler = DbHandler()
    db = 'twitter_mmo'
    collection = 'user'

    result_of_db_operation = handler.read_all_docs_in_collection(
        db_name=db, collection_name=collection)

    items = []

    for user in result_of_db_operation['result']:
        new_user = User(name=user['user_id'],
                        level=user['level'],
                        character_class=user['character_class'],
                        xp=user['xp'],
                        money=user['money'],
                        status=user['status'],
                        status_id=user['status_id'],
                        stats=user['stats'],
                        items_equipped=user['items_equipped'],
                        items_inventory=user['items_inventory'])
        items.append(new_user)

    return items
Пример #6
0
def async_get_story_data(story_id):
    print('In Method: async_get_story_data()')

    handler = DbHandler()
    db = 'test'  # change for production
    collection = 'stories'
    result_of_db_operation_story = handler.read_one_doc_by_id_from_database(
        db_name=db, collection_name=collection, doc_id=story_id)

    collection = 'previews'
    param_name = 'story_id'
    result_of_db_operation_preview = handler.read_one_doc_by_param_from_database(
        db_name=db,
        collection_name=collection,
        doc_value=story_id,
        doc_param=param_name)

    if result_of_db_operation_story[
            'success'] is True & result_of_db_operation_preview[
                'success'] is True:

        result = result_of_db_operation_preview['result']
        result.update(result_of_db_operation_story['result'])

        return result
    else:
        return 'False'
Пример #7
0
def publish_story_and_redirect():
    print('In Method: publish_story_and_redirect()')

    story_id: str = request.form.get('story_id')
    title: str = request.form.get('title')
    user_id: str = request.form.get('user_id')
    reading_time: int = int(request.form.get('reading_time'))
    preview_text: str = request.form.get('preview_text')
    categories: str = request.form.getlist('selected_categories')
    timestamp: datetime = request.form.get('timestamp')
    length: str = 'veryshort'

    if reading_time >= 5:
        length = 'short'
        if reading_time > 15:
            length = 'medium'
            if reading_time > 45:
                length = 'long'

    test_dict = {
        'story_id': story_id,
        'title': title,
        'preview_text': preview_text,
        'timestamp': timestamp,
        'user_id': user_id,
        'story_id': story_id,
        'reading_time': reading_time,
        'categories': categories,
        'length': length,
        'classic': False
    }

    handler = DbHandler()
    db = 'test'  # change for production
    collection = "previews"
    result_of_db_operation = handler.write_to_database(
        db_name=db, collection_name=collection, json_to_write=test_dict)

    if result_of_db_operation['success'] is True:
        return redirect(
            url_for(
                'main_bps.display_story',
                story_id=story_id,
                notification=
                'Herzlichen Glückwunsch! Deine Story wurde soeben veröffentlicht.'
            ))
    else:
        return redirect(
            url_for(
                'user_bps.display_editor',
                notification='Etwas ist schief gelaufen. Bitte versuche es '
                'später noch ein Mal.'))
def delete_account():
    print('In Method: delete_account()')
    handler = DbHandler()
    db = 'test' # change for production
    result_of_db_operation = handler.delete_from_all_collections_by_user_id(db_name=db, user_id=session['user_id'])

    if result_of_db_operation['success'] is True:
        logout_user()
        return redirect(url_for('main_bps.display_main_index', notification='Schade, dass du uns verlassen hast. Es ist'
                                                                            'nie zu spät zurück zu kommen!'))
    else:
        return redirect(url_for('user_bps.display_settings', notification='Etwas ist schief gelaufen. Bitte versuche es'
                                                                          ' später noch ein Mal.'))
Пример #9
0
def async_get_story_data_without_preview(story_id):
    print('In Method: get_story_data_without_preview()')

    handler = DbHandler()
    db = 'test'  # change for production
    collection = 'stories'
    result_of_db_operation_story = handler.read_one_doc_by_id_from_database(
        db_name=db, collection_name=collection, doc_id=story_id)

    if result_of_db_operation_story['success'] is True:
        return result_of_db_operation_story
    else:
        return 'False'
Пример #10
0
    def check_if_user_exists(self):
        print("In Method: check_if_user_exists()")

        handler = DbHandler()
        db = 'test'  # change for production
        collection = 'users'
        result_of_db_operation = handler.read_one_doc_by_param_from_database(
            db_name=db,
            collection_name=collection,
            doc_value=self.id,
            doc_param='email')
        if result_of_db_operation['success'] is True:
            return result_of_db_operation
        else:
            return False
Пример #11
0
def queue_tweet(api: tweepy.API, user_name: str, text: str, reply_id: str):
    print('In Method: queue_tweet()')

    handler = DbHandler()
    db = 'twitter_mmo'  # change for production
    collection = 'tweet_queue'

    tweet_dict = {'text': "@" + user_name + " " + text, 'replay_id': reply_id}

    result_of_db_operation = handler.write_to_database(
        db_name=db, collection_name=collection, json_to_write=tweet_dict)

    if result_of_db_operation['success'] is True:
        return True
    else:
        return False
Пример #12
0
def async_get_comments(story_id):
    print('In Method: async_get_comments()')

    handler = DbHandler()
    db = 'test'  # change for production
    collection = 'comments'

    param_name = 'story_id'

    result_of_db_operation = handler.read_multiple_docs_by_param_from_database(
        db_name=db,
        collection_name=collection,
        doc_value=story_id,
        doc_param=param_name)

    if result_of_db_operation['success'] is True:
        return result_of_db_operation
    else:
        return 'False'
Пример #13
0
    def sign_up(self):
        print("In Method: sign_up()")

        user_dict = {
            'user_id': self.user_id,
            'email': self.id,
            'password': generate_password_hash(self.password),
            'mail_confirmed': False
        }

        handler = DbHandler()
        db = 'test'  # change for production
        collection = "users"
        result_of_db_operation = handler.write_to_database(
            db_name=db, collection_name=collection, json_to_write=user_dict)

        if result_of_db_operation['success'] is True:
            return True
        else:
            return False
Пример #14
0
def get_all_items_in_db():
    print('In Method: get_all_items_in_db()')

    handler = DbHandler()
    db = 'twitter_mmo'
    collection = 'items'

    result_of_db_operation = handler.read_all_docs_in_collection(
        db_name=db, collection_name=collection)

    items = []

    for item in result_of_db_operation['result']:
        new_item = Item(name=item['name'],
                        category=item['category'],
                        level=item['level'],
                        stats=item['stats'],
                        power=item['power'])
        items.append(new_item)

    return items
def confirm_mail():
    print("In Method: confirm_mail()")

    user_id = request.args.get('user_id')

    handler = DbHandler()
    db = 'test' # change for production
    collection = 'users'

    param_name_find = 'user_id'

    param_name_new = 'mail_confirmed'
    result_of_db_operation = handler.update_one_doc_by_param_from_database(db_name=db, collection_name=collection,
                                                                                 doc_value_find=user_id,
                                                                                 doc_param_find=param_name_find,
                                                                                 doc_value_new=True,
                                                                                 doc_param_new=param_name_new)

    if result_of_db_operation['success'] is True:
        return redirect(url_for('main_bps.display_main_index', notification='Dein Profil ist jetzt bestätigt.'))
    else:
        return redirect(url_for('main_bps.display_main_index', notification='Etwas ist schief gelaufen. Bitte versuche es '
                                                                        'später noch ein Mal.'))
Пример #16
0
    def set_character_class(self, chosen_class: str):
        self.character_class = chosen_class

        handler = DbHandler()
        db = 'twitter_mmo'  # change for production
        collection = 'users'

        param_to_get_doc = 'user_id'
        param_to_change = 'character_class'
        new_value = chosen_class

        result_of_db_operation = handler.update_one_doc_by_param_from_database(
            db_name=db,
            collection_name=collection,
            doc_param_find=param_to_get_doc,
            doc_value_find=self.user_name,
            doc_param_new=param_to_change,
            doc_value_new=new_value)

        if result_of_db_operation['success'] is True:
            return True
        else:
            return False
Пример #17
0
def publish_comment():
    print('In Method: publish_comment()')

    content: str = request.form.get('content')
    timestamp: datetime = datetime.now()
    user_id: str = session['user_id']
    story_id: str = request.form.get('story_id')

    test_dict = {
        'content': content,
        'timestamp': timestamp,
        'user_id': user_id,
        'story_id': story_id
    }

    handler = DbHandler()
    db = 'test'  # change for production
    collection = "comments"
    result_of_db_operation = handler.write_to_database(
        db_name=db, collection_name=collection, json_to_write=test_dict)

    if result_of_db_operation['success'] is True:
        return redirect(
            url_for('main_bps.display_story',
                    story_id=story_id,
                    notification='Dein Kommentar wurde '
                    'veröffentlicht. Danke dafür,'
                    ' dass du ein Teil dieser '
                    'Community bist!'))
    else:
        return redirect(
            url_for('main_bps.display_story',
                    story_id=story_id,
                    notification='Etwas ist schief gelaufen. '
                    'Bitte versuche es '
                    'später noch ein Mal.'))