Esempio n. 1
0
def comment_add(req, blog_id):
    if not req.user.is_authenticated:
        return redirect(reverse_lazy("blog:index"))

    template = "comment_form.html"

    comment = Comment()
    comment.author = req.user
    comment.blog = Blog.objects.get(id=blog_id)

    if req.method == "POST":
        form = CommentForm(req.POST, instance=comment)

        if form.is_valid():
            form.save()
            return redirect(reverse_lazy("blog:view_blog", args=[blog_id]))

        else:
            res(form)

    context = {
        "page_title": "Add New Comment",
        "comment_form": CommentForm(instance=comment)
    }

    return render(req, template, context)
Esempio n. 2
0
def download_file(request, file_name):
    fl_path = 'file'
    filename = file_name + '.txt'
    fl = open(fl_path, 'r')
    mime_type, _ = mimetypes.guess_type(fl_path)
    response = res(fl, content_type=mime_type)
    response['Content-Disposition'] = "attachment; filename=%s" % filename
    return response
Esempio n. 3
0
def blog_delete(req, blog_id):
    if not req.user.is_authenticated:
        return redirect(reverse_lazy("blog:index"))

    blog = Blog.objects.get(id=blog_id)
    blog.delete()

    return redirect(reverse_lazy("blog:index"))

    return res("Delete blog")
Esempio n. 4
0
def register(request):
    if request.method == 'POST':
        form = FORMS.formRegister(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = User(name=data['name'],
                        phone=data['phone'],
                        email=data['email'])
            ##################3
            sizePublickey = len(PublicKey.objects.all()) + 1
            sizeUser = len(User.objects.all()) + 1
            n, e, d = generateKey()
            userid = generateId(sizeUser)

            idpublickey = generateId(sizePublickey)
            publicKey = PublicKey(idPublicKey=str(idpublickey),
                                  publicKeyE=str(e),
                                  publicKeyN=str(n))
            user = User(userId=str(userid),
                        name=data['name'],
                        phone=data['phone'],
                        email=data['email'])
            #Id + id khoa cong khai
            CI = str(encode(userid, n, d)) + '#' + str(idpublickey)
            C = int(str(CI).split('#')[0])
            P = decode(C, n, e)

            # return res(P == int.from_bytes(sha512(str(userid).encode()).digest(),byteorder='big'))
            try:
                u = User.objects.filter(email=user.email).get().email
                if (u == user.name):
                    return res(
                        "<script>alert('tai khoan da ton tai')</script>")
            except User.DoesNotExist:
                user.save()
                publicKey.save()
                return res(CI)

            return HttpResponseRedirect(reverse('app:index'))
        return
    form = FORMS.formRegister()
    return render(request, "app/register.html", {"form": form})
Esempio n. 5
0
def index(request):
    return res("Hello da den voi trang ban hang")
Esempio n. 6
0
def show(request, ID):
    return res(f"id cua ban la {ID}")
Esempio n. 7
0
def show(request):
    info = {'name': 'arpit', 'age': 30}
    return res(json.dumps(info))
Esempio n. 8
0
def del_todo(req, todo_id):
    obj = models.Todo.objects.using(todoDB).get(id=todo_id)
    obj.delete()
    return res('delete')
Esempio n. 9
0
def add_todo(req, name):
    obj = models.Todo(content=name)
    obj.save(using=todoDB)
    return res('save')
Esempio n. 10
0
def todo_list(req):
    flds = ['content']
    # obj = serialise(getTodoList(), flds)
    obj1 = simple_serialise(getTodoList(), flds)
    # listJson = {'data': obj}
    return res(obj1, content_type=jsonType)
Esempio n. 11
0
def hello(request):
    #最简单的定义url例子
    return res("hello world")
Esempio n. 12
0
def home(request, text, keyword):
    print(keyword)
    movie_user_likes = text
    tic = time.time()
    df = pd.read_csv("./dataset/movie_dataset.csv")

    def combine_features(row):
        return row['keywords'] + " " + row['genres']

    features = ['keywords', 'genres']
    for feature in features:
        df[feature] = df[feature].fillna(
            '')  # filling all NaNs with blank string

    df['combined_features'] = df.apply(combine_features, axis=1)

    if len(df[df['id'] == text]) > 0:
        print("success")

        cv = CountVectorizer()
        count_matrix = cv.fit_transform(df['combined_features'])
        cosine_sim = cosine_similarity(count_matrix)

        def get_id_from_index(index):
            return df[df.index == index]['id'].values[0]

        def get_index_from_id(id):
            return df[df.id == id]['index'].values[0]

        movie_index = get_index_from_id(movie_user_likes)
        print(movie_index)
        similar_movies = list(enumerate(cosine_sim[movie_index]))
        # accessing the row corresponding to given movie to find all the similarity scores for that movie and then enumerating over it
        similar_sorted = sorted(similar_movies,
                                key=lambda x: x[1],
                                reverse=True)[1:]
        similar_movies = similar_sorted[0:10]
        tac = time.time()
        print("read time" + str(((tac - tic) * 1000)) + "ms")
        list_names = []
        for names in similar_movies:
            # list_names.append(df[df.id==get_id_from_index(names[0])]['title'].values[0])
            temp = {
                'id':
                str(get_id_from_index(names[0])),
                'movie':
                df[df.id == get_id_from_index(names[0])]['title'].values[0]
            }
            list_names.append(temp)

        result = {'result': list_names}
        # list.append(text)
        # print(list)
        return res(result)

    else:
        print("failed")
        df2 = pd.DataFrame({
            "index": [len(df['index'])],
            "id": [text],
            "combined_features": [keyword]
        })
        df = df.append(df2, ignore_index=True)
        cv = CountVectorizer()
        count_matrix = cv.fit_transform(df['combined_features'])
        cosine_sim = cosine_similarity(count_matrix)

        def get_id_from_index(index):
            return df[df.index == index]['id'].values[0]

        def get_index_from_id(id):
            return df[df.id == id]['index'].values[0]

        movie_index = get_index_from_id(movie_user_likes)
        print(movie_index)
        similar_movies = list(enumerate(cosine_sim[movie_index]))
        # accessing the row corresponding to given movie to find all the similarity scores for that movie and then enumerating over it
        similar_sorted = sorted(similar_movies,
                                key=lambda x: x[1],
                                reverse=True)[1:]
        similar_movies = similar_sorted[0:10]
        tac = time.time()
        print("read time" + str(((tac - tic) * 1000)) + "ms")
        list_names = []
        for names in similar_movies:
            # list_names.append(df[df.id==get_id_from_index(names[0])]['title'].values[0])
            temp = {
                'id':
                str(get_id_from_index(names[0])),
                'movie':
                df[df.id == get_id_from_index(names[0])]['title'].values[0]
            }
            list_names.append(temp)

        result = {'result': list_names}
        # list.append(text)
        # print(list)
        return res(result)
Esempio n. 13
0
def about(request):

    return res("<h2>About</h2")
Esempio n. 14
0
def hello(request):
    #最简单的定义url例子
    return res("hello world")
Esempio n. 15
0
def success(request):
    return res("dang ky ok ")
Esempio n. 16
0
def home(request):
    return res("dang nhap thanh cong")