Example #1
0
def sub_category(request, category_id, subcategory_id):
    main_category = SportNewsMainCategory.objects.filter(id=category_id)
    sub_category = SportNewsCategory.objects.filter(
        mainCategory=main_category).filter(id=subcategory_id)
    sub_category_name = ''
    if sub_category:
        sub_category_name = sub_category[0].name
    sub_category_news = SportNews.objects.filter(
        category=sub_category).order_by('-created_at')
    news_to_show = []
    for news in sub_category_news:
        newsItem = []
        newsItem.append(news.id)
        newsItem.append(news.photo)
        newsItem.append(news.title)
        news_to_show.append(newsItem)
    return render(request,
                  'main/subCategory.html', {
                      'user_info': getUseInfo(request),
                      'navigationBar': getNavigationBar(),
                      'side_bar': getSideBar(int(category_id)),
                      'sub_category_name': sub_category_name,
                      'news_to_show': news_to_show,
                  },
                  context_instance=RequestContext(request))
Example #2
0
def info(request):
    return render(request,
                  'main/info.html', {
                      'user_info': getUseInfo(request),
                      'navigationBar': getNavigationBar(),
                      'side_bar': getSideBar(),
                  },
                  context_instance=RequestContext(request))
Example #3
0
def forgot_password(request):
    signUpErrors = {}
    if request.method == 'POST':
        if 'username' in request.POST and 'email' in request.POST:
            userQuery = User.objects.filter(username=request.POST['username'])
            if userQuery:
                user = userQuery[0]
                if user.email == request.POST['email']:
                    email_subject = 'Forgotten password for spirtal.py'
                    email_message = 'You requested from us to send you your password. Password:'******'*****@*****.**'
                    mail_to = []
                    mail_to.append(user.email)
                    send_mail(email_subject, email_message, email_from,
                              mail_to)
                    return HttpResponseRedirect('/accounts/login/')
                else:
                    signUpErrors['email'] = 'Email missmatched'
                    return render(
                        request, 'main/forgotten_pass.html', {
                            'signUpErrors': signUpErrors,
                            'user_info': getUseInfo(request),
                            'navigationBar': getNavigationBar(),
                            'side_bar': getSideBar(),
                        })
            else:
                signUpErrors['username'] = '******'
                return render(
                    request, 'main/forgotten_pass.html', {
                        'signUpErrors': signUpErrors,
                        'user_info': getUseInfo(request),
                        'navigationBar': getNavigationBar(),
                        'side_bar': getSideBar(),
                    })
    else:
        return render(request,
                      'main/forgotten_pass.html', {
                          'signUpErrors': signUpErrors,
                          'user_info': getUseInfo(request),
                          'navigationBar': getNavigationBar(),
                          'side_bar': getSideBar(),
                      },
                      context_instance=RequestContext(request))
Example #4
0
def login_view(request):
    signUpErrors = {}
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        fromPath = request.POST['fromPath']
        fromPath = fromPath[:-1]
        if user is not None:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(fromPath)
            else:
                signUpErrors['username'] = '******'
                return render(
                    request, 'main/login.html', {
                        'signUpErrors': signUpErrors,
                        'user_info': getUseInfo(request),
                        'navigationBar': getNavigationBar(),
                        'side_bar': getSideBar(),
                    })
        else:
            signUpErrors[
                'username'] = '******'
            return render(
                request, 'main/login.html', {
                    'signUpErrors': signUpErrors,
                    'user_info': getUseInfo(request),
                    'navigationBar': getNavigationBar(),
                    'side_bar': getSideBar(),
                })
    else:
        return render(
            request, 'main/login.html', {
                'signUpErrors': signUpErrors,
                'user_info': getUseInfo(request),
                'navigationBar': getNavigationBar(),
                'side_bar': getSideBar(),
            })
Example #5
0
def index(request):
    first_news = []
    first_news_list = SportNews.objects.filter(
        priority='NEWS_MAIN').order_by('-created_at')
    if len(first_news_list) > 0:
        news_info = {}
        news_info['title'] = first_news_list[0].title
        news_info['img'] = '/media/' + str(first_news_list[0].photo)
        first_news.append(first_news_list[0].id)
        first_news.append(news_info)
    main_news = []
    for news_prio in NEWS_PRIO:
        if news_prio[0] != 'NEWS_NORMAL' and news_prio[0] != 'NEWS_MAIN':
            main_news_list = SportNews.objects.filter(
                priority=news_prio[0]).order_by('-created_at')
            if len(main_news_list) > 0:
                news_info = {}
                news_info['title'] = main_news_list[0].title
                news_info['img'] = '/media/' + str(main_news_list[0].photo)
                news = []
                news.append(main_news_list[0].id)
                news.append(news_info)
                main_news.append(news)

    other_news_list = SportNews.objects.all().order_by('-created_at')[:20]
    other_news = []
    for other in other_news_list:
        news = []
        news.append(other.id)
        news.append(other.photo)
        news.append(other.title)
        isItemInMainNews = False
        for mainNewsItem in main_news:
            if mainNewsItem[0] == news[0]:
                isItemInMainNews = True
        if not isItemInMainNews and first_news and other.id != first_news[0]:
            other_news.append(news)

    return render(request,
                  'main/index.html', {
                      'user_info': getUseInfo(request),
                      'navigationBar': getNavigationBar(),
                      'side_bar': getSideBar(),
                      'first_news': first_news,
                      'main_news': main_news,
                      'other_news': other_news,
                  },
                  context_instance=RequestContext(request))
Example #6
0
def news(request, news_id):
    comment_to_answer_id = '-1'
    if request.method == 'POST' and 'comment_to_answer_id' in request.POST:
        comment_to_answer_id = request.POST['comment_to_answer_id']
        comment_to_answer_id = comment_to_answer_id[:-1]
    try:
        news = SportNews.objects.get(pk=news_id)
    except SportNews.DoesNotExist:
        raise Http404
    photoUrl = '/media/' + str(news.photo)
    category_id = news.category.mainCategory.id
    comments = SportNewsComment.objects.filter(
        news=news).order_by('-created_at')
    comments_to_show = []
    for comment in comments:
        comment_to_show = {}
        comment_to_show['id'] = comment.id
        comment_to_show['created_at'] = comment.created_at
        comment_to_show['comment_number'] = comment.comment_number
        comment_to_show['user_username'] = comment.user.username
        comment_to_show['user_first_name'] = comment.user.first_name
        comment_to_show['user_last_name'] = comment.user.last_name
        comment_to_show['title'] = comment.title
        comment_to_show['text'] = comment.text
        comment_to_show['root_comment'] = comment.root_comment
        comments_to_show.append(comment_to_show)
    return render(request,
                  'main/news.html', {
                      'user_info': getUseInfo(request),
                      'navigationBar': getNavigationBar(),
                      'side_bar': getSideBar(category_id),
                      'news_id': news_id,
                      'news_title': news.title,
                      'news_text': news.text,
                      'photo': photoUrl,
                      'comments_to_show': comments_to_show,
                      'comment_to_answer_id': int(comment_to_answer_id)
                  },
                  context_instance=RequestContext(request))
Example #7
0
def search_news(request):
    search_word = ''
    if request.method == 'GET':
        search_word = request.GET['search_text']
    elif request.method == 'POST':
        search_word = request.POST['search_text']
    searched_news = SportNews.objects.filter(
        Q(title__icontains=search_word) | Q(text__icontains=search_word)
        | Q(category__name__icontains=search_word))
    news_to_show = []
    for news in searched_news:
        newsItem = []
        newsItem.append(news.id)
        newsItem.append(news.photo)
        newsItem.append(news.title)
        news_to_show.append(newsItem)
    return render(
        request, 'main/search_news.html', {
            'search_word': search_word,
            'user_info': getUseInfo(request),
            'navigationBar': getNavigationBar(),
            'side_bar': getSideBar(int()),
            'news_to_show': news_to_show,
        })
Example #8
0
def sub_category(request, category_id, subcategory_id):
    main_category = SportNewsMainCategory.objects.filter(id=category_id)
    sub_category = SportNewsCategory.objects.filter(mainCategory=main_category).filter(id=subcategory_id)
    sub_category_name = ''
    if sub_category:
        sub_category_name = sub_category[0].name
    sub_category_news = SportNews.objects.filter(category=sub_category).order_by('-created_at')
    news_to_show = []
    for news in sub_category_news:
        newsItem = []
        newsItem.append(news.id)
        newsItem.append(news.photo)
        newsItem.append(news.title)
        news_to_show.append(newsItem)
    return render(request,
                  'main/subCategory.html', {'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(int(category_id)), 'sub_category_name': sub_category_name, 'news_to_show': news_to_show,},
                  context_instance=RequestContext(request))
Example #9
0
def news(request, news_id):
    comment_to_answer_id = '-1'
    if request.method == 'POST' and 'comment_to_answer_id' in request.POST:
        comment_to_answer_id = request.POST['comment_to_answer_id']
        comment_to_answer_id = comment_to_answer_id[:-1]
    try:
        news = SportNews.objects.get(pk=news_id)
    except SportNews.DoesNotExist:
        raise Http404
    photoUrl = '/media/' + str(news.photo)
    category_id = news.category.mainCategory.id
    comments = SportNewsComment.objects.filter(news=news).order_by('-created_at')
    comments_to_show = []
    for comment in comments:
        comment_to_show = {}
        comment_to_show['id'] = comment.id
        comment_to_show['created_at'] = comment.created_at
        comment_to_show['comment_number'] = comment.comment_number
        comment_to_show['user_username'] = comment.user.username
        comment_to_show['user_first_name'] = comment.user.first_name
        comment_to_show['user_last_name'] = comment.user.last_name
        comment_to_show['title'] = comment.title
        comment_to_show['text'] = comment.text
        comment_to_show['root_comment'] = comment.root_comment
        comments_to_show.append(comment_to_show)
    return render(request,
                  'main/news.html', {'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(category_id), 'news_id': news_id, 'news_title': news.title, 'news_text': news.text, 'photo': photoUrl, 'comments_to_show': comments_to_show, 'comment_to_answer_id': int(comment_to_answer_id)},
                  context_instance=RequestContext(request))
Example #10
0
def forgot_password(request):
    signUpErrors = {}
    if request.method == 'POST':
        if 'username' in request.POST and 'email' in request.POST:
            userQuery = User.objects.filter(username=request.POST['username'])
            if userQuery:
                user = userQuery[0]
                if user.email == request.POST['email']:
                    email_subject = 'Forgotten password for spirtal.py'
                    email_message = 'You requested from us to send you your password. Password:'******'*****@*****.**'
                    mail_to = []
                    mail_to.append(user.email)
                    send_mail(email_subject, email_message, email_from, mail_to)
                    return HttpResponseRedirect('/accounts/login/')
                else:
                    signUpErrors['email'] = 'Email missmatched'
                    return render(request, 'main/forgotten_pass.html', {'signUpErrors': signUpErrors, 'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),})
            else:
                signUpErrors['username'] = '******'
                return render(request, 'main/forgotten_pass.html', {'signUpErrors': signUpErrors, 'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),})
    else:
        return render(request, 'main/forgotten_pass.html', {'signUpErrors': signUpErrors, 'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),},
                  context_instance=RequestContext(request))
Example #11
0
def info(request):
    return render(request, 'main/info.html', {'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),},
                  context_instance=RequestContext(request))
Example #12
0
def search_news(request):
    search_word = ''
    if request.method == 'GET':
        search_word = request.GET['search_text']
    elif request.method == 'POST':
        search_word = request.POST['search_text']
    searched_news = SportNews.objects.filter(Q(title__icontains=search_word) | Q(text__icontains=search_word) | Q(category__name__icontains=search_word))
    news_to_show = []
    for news in searched_news:
        newsItem = []
        newsItem.append(news.id)
        newsItem.append(news.photo)
        newsItem.append(news.title)
        news_to_show.append(newsItem)
    return render(request, 'main/search_news.html', {'search_word': search_word,'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(int()), 'news_to_show': news_to_show,})
Example #13
0
def index(request):
    first_news = []
    first_news_list = SportNews.objects.filter(priority='NEWS_MAIN').order_by('-created_at')
    if len(first_news_list) > 0:
        news_info = {}
        news_info['title'] = first_news_list[0].title
        news_info['img'] = '/media/' + str(first_news_list[0].photo)
        first_news.append(first_news_list[0].id)
        first_news.append(news_info)
    main_news = []
    for news_prio in NEWS_PRIO:
        if news_prio[0] != 'NEWS_NORMAL' and news_prio[0] != 'NEWS_MAIN':
            main_news_list = SportNews.objects.filter(priority=news_prio[0]).order_by('-created_at')
            if len(main_news_list) > 0:
                news_info = {}
                news_info['title'] = main_news_list[0].title
                news_info['img'] = '/media/' + str(main_news_list[0].photo)
                news = []
                news.append(main_news_list[0].id)
                news.append(news_info)
                main_news.append(news)
    
    other_news_list = SportNews.objects.all().order_by('-created_at')[:20]
    other_news = []
    for other in other_news_list:
        news = []
        news.append(other.id)
        news.append(other.photo)
        news.append(other.title)
        isItemInMainNews = False
        for mainNewsItem in main_news:
            if mainNewsItem[0] == news[0]:
                isItemInMainNews = True
        if not isItemInMainNews and first_news and other.id != first_news[0]:
            other_news.append(news)
            
    return render(request,
                  'main/index.html', {'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(), 'first_news': first_news, 'main_news': main_news, 'other_news': other_news,},
                  context_instance=RequestContext(request)
                  )
Example #14
0
def login_view(request):
    signUpErrors = {}
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        fromPath = request.POST['fromPath']
        fromPath = fromPath[:-1]
        if user is not None:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(fromPath)
            else:
                signUpErrors['username'] = '******'
                return render(request, 'main/login.html', {'signUpErrors': signUpErrors, 'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),})
        else:
            signUpErrors['username'] = '******'
            return render(request, 'main/login.html', {'signUpErrors': signUpErrors, 'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),})
    else:
        return render(request, 'main/login.html', {'signUpErrors': signUpErrors, 'user_info': getUseInfo(request), 'navigationBar': getNavigationBar(),'side_bar': getSideBar(),})