示例#1
0
def index():
    """ The Dashboard """
    return render_template(
        "basic/main.html",
        number_of_courses=PageDetails().number_of_courses(),
        top_courses=PageDetails().top_3_expensive_courses(),
        quotes=PageDetails().random_quotes(),
        random_blog_post=PageDetails().get_random_blog_post(),
        survey=PageDetails().get_survey_json_data())
示例#2
0
def remove_full_day_admin():
    """ The Remove Full Day Page as an admin. """
    if request.method == "POST":

        def form_handler(request):

            if request.form.get("slug") == "":
                return {
                    "Result": False,
                    "Message": "نام انگلیسی دوره را وارد کنید."
                }
            if request.form.get("day") == "":
                return {"Result": False, "Message": "روز دوره را وارد کنید."}

            try:
                int(request.form.get("day"))
            except ValueError:
                return {"Result": False, "Message": "روز دوره باید عدد باشد."}

            if Database().get_courses_data_from_db(
                    request.form.get("slug")) is False:
                return {
                    "Result": False,
                    "Message": "همچین دوره ای وجود ندارد."
                }

            message = Database().delete_day_of_course_data_to_db(
                slug=request.form.get("slug"),
                day=request.form.get("day"),
            )
            return message

        message = form_handler(request)
        if message is True:
            message = {"Color": "green", "Result": "با موفقیت حذف شد."}
        else:
            if message["Result"] is False:
                message["Color"] = "red"
            else:
                message["Color"] = "green"
            message["Result"] = message["Message"]

        flash(message)
        return redirect(url_for("admin_remove.remove_full_day_admin"))

    Parts = PageDetails().all_day_parts_to_remove_in_admin_page()

    return render_template(
        "admin/admin_remove_day.html",
        Parts=Parts,
        Courses=PageDetails(session).all_courses_page_info_html(),
    )
示例#3
0
def sub_course(slug, day):
    """ The one sub Course page. """
    # Day is a number or not
    try:
        day = int(day)
    except ValueError:
        abort(404)
    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    try:
        identity = session["Data"]["Email"]
    except KeyError:
        identity = ""

    # Get needed Data
    course_data = Database().get_courses_data_from_db(slug=slug)
    day_data = Database().get_one_day_data_of_courses_data_from_db(slug, day)

    # Check Length Day
    if int(day) > int(course_data["Length"]):
        return redirect("/Course/{}".format(slug))

    # Check if data is FALSE or not
    if course_data is False or day_data is False:
        abort(404)

    # Some days and courses in database might not have "Free" key, so we add them.
    if "Free" not in day_data:
        day_data["Free"] = False
    if "Free" not in course_data:
        course_data["Free"] = False

    # Check if day or course is not free and if we do not have access
    user_accesses = Database().get_users_access_data_from_db(identity)
    if (course_data["Free"] is not True and slug not in user_accesses
            and day_data["Free"] is False):
        return redirect("/Course/{}/info".format(slug))

    if slug in user_accesses and (user_accesses[slug] - 1 + day -
                                  General().days_passed_till_now()) > 0:
        return redirect("/Course/{}".format(slug))

    return render_template(
        "courses_and_days/day.html",
        course=PageDetails(session).course_page_info(slug)[0],
        day=PageDetails(session).sub_course_page_info_html(slug, day),
    )
示例#4
0
def start_free_course(slug):
    """ The free Course start page. """
    data = PageDetails().course_page_info(slug)
    if data is False:
        abort(404)
    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    try:
        identity = session["Data"]["Email"]
    except KeyError:
        identity = ""
    if slug in Database().get_users_access_data_from_db(identity):
        return redirect("/Course/{slug}".format(slug=slug))
    if not (slug in Database().get_users_access_data_from_db(identity)
            or data[0]["Free"] is True or data[0]["Now_Price"] == 0):
        return redirect("/Course/{slug}/buy".format(slug=slug))

    return render_template(
        "courses_and_days/start_course_card.html",
        course=data[0],
        days=data[1],
        intro=data[2],
    )
示例#5
0
def buy_course_redirect(slug):
    """ The Course redirect to zarinpall page. """
    data = PageDetails().course_page_info(slug)
    if data is False:
        abort(404)
    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    try:
        identity = session["Data"]["Email"]
    except KeyError:
        return redirect("/LogIn")

    if slug in Database().get_users_access_data_from_db(identity):
        return redirect("/Course/{slug}".format(slug=slug))

    client = Client(ZARINPAL_WEBSERVICE)
    result = client.service.PaymentRequest(
        MMERCHANT_ID, int(str(data[0]["Now_Price"]).replace(",", "")),
        description, 'email', "mobile",
        str(url_for('courses_and_days.buy_callback', _external=True)))

    if result.Status == 100:
        Database().add_payment_record_to_db(slug, data[0]["Now_Price"],
                                            identity, str(result.Authority))
        return redirect('https://www.zarinpal.com/pg/StartPay/' +
                        result.Authority)
    else:
        return 'Error'
示例#6
0
def add_course_info_admin():
    """ The Add Course information Page as an admin. """

    if request.method == "POST":
        message = Database().add_course_info_to_db(
            slug=request.form.get("slug"),
            introduction=request.form.get("intro"),
            speciality=request.form.get("speciality"),
            importance=request.form.get("importance"),
            why=request.form.get("why"),
            length=request.form.get("length"),
            price=request.form.get("price"),
            last_words=request.form.get("last_word"),
        )
        if message is True:
            message = {"Color": "green", "Result": "با موفقیت اضافه شد."}
        else:
            message["Result"] = message["Message"]
            message["Color"] = "red"
        flash(message)
        return redirect(url_for("admin_add.add_course_info_admin"))

    return render_template(
        "admin/admin_add_course_info.html",
        Courses=PageDetails().
        get_all_courses_info_categorized_by_info_existence(),
    )
示例#7
0
def fail_page_course(slug):
    """ The Course Buy report fail page. """
    data = PageDetails().course_page_info(slug)
    if data is False:
        abort(404)
    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    try:
        identity = session["Data"]["Email"]
    except KeyError:
        identity = ""

    if slug not in Database().get_users_access_data_from_db(identity):
        return redirect("/Course/{slug}".format(slug=slug))
    try:
        code = (request.args['auth_code'])
    except KeyError:
        return redirect("/Course/{slug}".format(slug=slug))
    return render_template("courses_and_days/fail_payment.html",
                           course=data[0],
                           days=data[1],
                           intro=data[2],
                           code=code)
示例#8
0
def all_courses():
    """ The Courses page. """
    courses_per_page = 10
    courses = PageDetails(session).all_courses_list_sorted_by_date()
    courses.reverse()
    page = request.args.get("page")
    last_page = len(courses) // courses_per_page
    if len(courses) - last_page * courses_per_page > 0:
        last_page += 1
    if page is None:
        page = 1
    else:
        try:
            page = int(page)
        except ValueError:
            page = 1
    if page < 1:
        return redirect("?page=1")
    limited_courses = (courses[(page - 1) * courses_per_page:page *
                               courses_per_page])
    if limited_courses == [] and page != 1:
        return redirect("?page={}".format(last_page))

    try:
        identity = session["Data"]["Email"]
    except KeyError:
        identity = ""

    return render_template(
        "courses_and_days/courses.html",
        courses=limited_courses,
        accesses=Database().get_users_access_data_from_db(identity),
        days_till_now=General().days_passed_till_now(),
        now_page=page,
        last_page=last_page,
        pagination=General().pagination_designer(page, last_page))
示例#9
0
def info_course(slug):
    """ The one Course info page. """

    data = PageDetails().info_intro_course_page(slug)
    if data is False or "Intro" not in data:
        return redirect(url_for("courses_and_days.one_course", slug=slug))
    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    return render_template(
        "courses_and_days/course_info.html",
        course=data,
    )
示例#10
0
def survey_topics():
    if session.get("logged_in"):
        identity = session["Data"]["Email"]
    else:
        identity = "unknown"
    user_ip_address = request.remote_addr
    request_args = request.get_json()
    topics = PageDetails().get_survey_json_data()["questions"]
    user_survey_answer = {}
    for topic in topics:
        user_survey_answer[topic] = request_args[topic]
    user_survey_answer["secound_questions"] = request_args["secound_questions"]
    Database().add_user_survey_answer_to_db(user_ip_address, identity,
                                            dumps(user_survey_answer))
    Authentication(session).user_answered_survey()
    return redirect("/")
示例#11
0
        def form_handler(request):

            remove_ones = []
            course_names = []
            for course in PageDetails().all_courses_page_info_html():
                course_names.append(course["Slug"])
            for part in course_names:
                if (part) == request.form.get(part):
                    remove_ones.append(part)

            for course in remove_ones:
                Database().delete_courses_data_from_db(course)
                General().remove_file_to_trash(
                    "static/assets/images/blog/{slug}/".format(slug=course))

            return True
示例#12
0
def start_course_redirect(slug):
    """ The Course redirect to start the free course page. """
    data = PageDetails().course_page_info(slug)
    if data is False:
        abort(404)
    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    try:
        identity = session["Data"]["Email"]
    except KeyError:
        return redirect("/LogIn")

    if slug in Database().get_users_access_data_from_db(identity):
        return redirect("/Course/{slug}".format(slug=slug))

    Database().add_users_access_data_to_db(identity, slug)
    return redirect("/Course/{slug}/start/success".format(slug=slug))
示例#13
0
def remove_course_admin():
    """ The Remove day options Page as an admin. """

    if request.method == "POST":

        def form_handler(request):

            remove_ones = []
            course_names = []
            for course in PageDetails().all_courses_page_info_html():
                course_names.append(course["Slug"])
            for part in course_names:
                if (part) == request.form.get(part):
                    remove_ones.append(part)

            for course in remove_ones:
                Database().delete_courses_data_from_db(course)
                General().remove_file_to_trash(
                    "static/assets/images/blog/{slug}/".format(slug=course))

            return True

        message = form_handler(request)
        if message is True:
            message = {"Color": "green", "Result": "با موفقیت حذف شد."}
        else:
            if message["Result"] is False:
                message["Color"] = "red"
            else:
                message["Color"] = "green"
            message["Result"] = message["Message"]

        flash(message)
        return redirect(url_for("admin_remove.remove_course_admin"))

    Parts = PageDetails().all_course_data_slug_name_to_remove_in_admin_page()

    return render_template(
        "admin/admin_remove_courses.html",
        Parts=Parts,
    )
示例#14
0
def remove_tool_admin():
    """ The Remove tool as an admin. """

    if request.method == "POST":

        def form_handler(request):
            name = request.form.get("tool_name")

            remove_ones = []
            tool_names = []
            for tool_name in Database().get_all_tools_data_db():
                tool_names.append(tool_name["Slug"])
            for part in tool_names:
                if part == request.form.get(part):
                    remove_ones.append(part)

            for tool_slug in remove_ones:
                Database().delete_tool_data_from_db(tool_slug)

            message = True
            return message

        message = form_handler(request)

        if message is True:
            message = {"Color": "green", "Result": "با موفقیت حذف شد."}
        else:
            if message["Result"] is False:
                message["Color"] = "red"
            else:
                message["Color"] = "green"
            message["Result"] = message["Message"]

        flash(message)
        return redirect(url_for("admin_remove.remove_tool_admin"))

    Parts = PageDetails().all_tools_data_name_slug_to_remove_in_admin_page()
    return render_template(
        "admin/admin_remove_tool.html",
        Parts=Parts,
    )
示例#15
0
def remove_music_admin():
    """ The Remove Music as an admin. """

    if request.method == "POST":

        def form_handler(request):
            name = request.form.get("music_name")

            remove_ones = []
            music_names = []
            for music_name in Database().get_all_musics_data_from_db():
                music_names.append(music_name["Music_Name"])
            for part in music_names:
                if (part) == request.form.get(part):
                    remove_ones.append(part)

            for music_name in remove_ones:
                Database().delete_music_data_from_db(music_name)

            message = True
            return message

        message = form_handler(request)

        if message is True:
            message = {"Color": "green", "Result": "با موفقیت حذف شد."}
        else:
            if message["Result"] is False:
                message["Color"] = "red"
            else:
                message["Color"] = "green"
            message["Result"] = message["Message"]

        flash(message)
        return redirect(url_for("admin_remove.remove_music_admin"))

    Parts = PageDetails().all_music_data_name_creator_to_remove_in_admin_page()
    return render_template(
        "admin/admin_remove_musics.html",
        Parts=Parts,
    )
示例#16
0
def one_course(slug):
    """ The one Course page. """
    try:
        identity = session["Data"]["Email"]
    except KeyError:
        identity = ""
    data = PageDetails().course_page_info(slug)
    if data is False:
        abort(404)

    course = Database().get_courses_data_from_db(slug)
    published_date = General().convert_timestamp_to_days(
        course["First_Created_TimeStamp"]) + course["Days_Till_Open"]
    if published_date > General().days_passed_till_now():
        abort(404)
    return render_template(
        "courses_and_days/course.html",
        course=data[0],
        days=data[1],
        intro=data[2],
        accesses=Database().get_users_access_data_from_db(identity),
        days_till_now=General().days_passed_till_now())
示例#17
0
def survey_data():
    if not request.full_path.startswith("/static"):

        if Authentication(session).has_user_answered_survey() is True:
            g.survey = False
        else:
            try:
                survey_data_session = session["survey"]
            except KeyError:
                survey_data_session = 0
                session["survey"] = survey_data_session
                g.survey = True
            if type(survey_data_session) == int:
                if survey_data_session % 6 == 0:
                    g.survey = True
                else:
                    g.survey = False
                session["survey"] += 1
            else:
                g.survey = True
                session["survey"] = 1

        g.survey_data = PageDetails().get_survey_json_data()
示例#18
0
def add_user_admin():
    """ The Add User Page as an admin. """

    message = False
    if request.method == "POST":
        accesses = []
        for course in Database().get_all_slug_and_names_of_courses_from_db():
            if (course["Slug"]) == request.form.get(course["Slug"]):
                accesses.append(course["Slug"])
        message = Database().add_users_data_to_db(
            email=request.form.get("email"),
            password=General().sha256_hash(request.form.get("password")),
            first_name=request.form.get("name"),
            last_name=request.form.get("last_name"),
            phone_number=request.form.get("phone_num"),
            about_me=request.form.get("about_me"),
            bio=request.form.get("bio"),
            website=request.form.get("web"),
            birth_day=request.form.get("day"),
            birth_month=request.form.get("month"),
            birth_year=request.form.get("year"),
            Accesses=accesses,
        )
        if message is True:
            message = {"Color": "green", "Result": "با موفقیت اضافه شد."}
        else:
            message["Result"] = message["Message"]
            message["Color"] = "red"

        flash(message)
        return redirect(url_for("admin_add.add_user_admin"))

    return render_template(
        "admin/admin_add_user.html",
        Accesses=PageDetails().all_accesses_admin_page(),
        message=message,
    )
示例#19
0
文件: errors.py 项目: urgemag/urge
def not_found(e):
    """ The 404 not found page. """
    return render_template("errors/error.html",
        details = PageDetails(session).index_data(),
        error_code = str(e.code)
    )
示例#20
0
def essential_user_details():
    if request.full_path.endswith(
            ".jpg?") or not request.full_path.startswith("/static"):
        g.details = PageDetails(session).index_data()
示例#21
0
def remove_day_options_admin():
    """ The Remove day options Page as an admin. """

    if request.method == "POST":

        def form_handler(request):

            if request.form.get("slug") == "":
                return {
                    "Result": False,
                    "Message": "نام انگلیسی دوره را وارد کنید."
                }
            if request.form.get("day") == "":
                return {"Result": False, "Message": "روز دوره را وارد کنید."}

            try:
                int(request.form.get("day"))
            except ValueError:
                return {"Result": False, "Message": "روز دوره باید عدد باشد."}

            if Database().get_courses_data_from_db(
                    request.form.get("slug")) is False:
                return {
                    "Result": False,
                    "Message": "همچین دوره ای وجود ندارد."
                }

            remove_ones = []
            day_parts = [
                "Name",
                "Cover",
                "Description",
                "Text",
                "To_Do",
                "Quotes",
                "Musics",
                "Musics_Description",
                "Ted_Video",
                "Ted_Video_Description",
                "Animation_Link",
                "Animation_Description",
                "Movie_Links",
                "Movie_Text",
                "Movie_Cover",
                "Podcast",
                "Podcast_Description",
            ]
            for part in day_parts:
                if (part) == request.form.get(part):
                    remove_ones.append(part)

            message = Database().delete_parts_of_day_of_course_data_in_db(
                slug=request.form.get("slug"),
                day_of_course=request.form.get("day"),
                remove_parts_names=remove_ones,
            )
            return message

        message = form_handler(request)
        if message is True:
            message = {"Color": "green", "Result": "با موفقیت حذف شد."}
        else:
            if message["Result"] is False:
                message["Color"] = "red"
            else:
                message["Color"] = "green"
            message["Result"] = message["Message"]

        flash(message)
        return redirect(url_for("admin_remove.remove_day_options_admin"))

    Parts = PageDetails().all_day_parts_to_remove_in_admin_page()

    return render_template(
        "admin/admin_remove_day_options.html",
        Parts=Parts,
        Courses=PageDetails(session).all_courses_page_info_html(),
    )