Beispiel #1
0
def add_source(request):
    init_db()
    nw = NewsWorker()
    if request.POST['txtSourceTitle'] != "" and request.POST['txtSourceUrl'] != "" :
        nw.add_source(request.POST['txtSourceTitle'],request.POST['txtSourceUrl'],request.POST['txtSourceIcon'])
    return source_manager(request)
    pass
Beispiel #2
0
def reset_password(request):
    try:
        success = False
        if request.POST.has_key('resetKey'):
            reset_key = request.POST['resetKey']
            
            Setting.log.info("Reset password attemp for key:"+reset_key)
            uw = UserWorker()
            init_db()
            username = uw.find_username_by_reset_password_key(reset_key)
            email =  uw.get_user_email(username)
            if email != "":
                Setting.log.info("Reset password attemp for user:"******"user password changed to "+new_password)

                (title, text, html) = get_reset_password_template()

                text = text.format(new_password)
                html = html.format(new_password)
                
                Setting.log.info("got template - title is "+title)
                sendmail(email, title, text, html)
                Setting.log.info("mail sent to "+email)
                success = True
                
    except Exception as ex:
        Setting.log.log_exception(ex)

    return { 'success': success}
Beispiel #3
0
def sign_up(request):
    try:
        success = False
        fail_type = ''
        
        if request.POST.has_key('username') and request.POST.has_key('password') :
            Setting.log.info("signup attemp for  username:"******"signup done for email:  username:"+request.POST['username'])
                else:
                    fail_type = 'data'
                
                    
        return {'success':success, 'fail_type': fail_type}
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')
Beispiel #4
0
def home_page(header,request):   
        #raise()
        Setting.log.log_request(request)
        try:
                forgot_key = None
                #LogOut(header,request)
                init_db()
                user_name = ""
                authenticated = False
                session = request.session
                if 'authenticated' in session and session['authenticated']:
                        authenticated = True
                        uw = UserWorker()                       
                        user_name = uw.get_user_full_name(session['username'])
                if 'forgotPasswordKey' in request.params.keys():
                        forgot_key = request.params.getone('forgotPasswordKey')

                nw = NewsWorker()
                news = nw.get_news()             
                return {'news':news,'authenticated':authenticated,'user_name':user_name,'forgot_key':forgot_key}
        except Exception as ex:
                Setting.log.log_exception(ex)
                if Setting.debuging:
                        return Response(ex.__str__())
                else:
                        return Response('sorry,problem')
Beispiel #5
0
def home_page(header, request):
    #raise()
    Setting.log.log_request(request)
    try:
        forgot_key = None
        #LogOut(header,request)
        init_db()
        user_name = ""
        authenticated = False
        session = request.session
        if 'authenticated' in session and session['authenticated']:
            authenticated = True
            uw = UserWorker()
            user_name = uw.get_user_full_name(session['username'])
        if 'forgotPasswordKey' in request.params.keys():
            forgot_key = request.params.getone('forgotPasswordKey')

        nw = NewsWorker()
        news = nw.get_news()
        return {
            'news': news,
            'authenticated': authenticated,
            'user_name': user_name,
            'forgot_key': forgot_key
        }
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')
Beispiel #6
0
def add_feed(request):
    init_db()
    nw = NewsWorker()
    if request.POST['txtFeedTitle'] != "" and request.POST['txtFeedUrl'] != "" :
        nw.add_feed(request.POST['cbFeedSource'],request.POST['txtFeedTitle'],request.POST['txtFeedUrl'],)
    return source_manager(request)
    pass
Beispiel #7
0
def home_page(header,request):
        #raise()
        Setting.log.log_request(request)
        try:               
                query = ""
                days = None
                source=None
                starred = None
                alert_message = ""
                if 'q' in request.params:
                    query = request.params.getone('q')
                
                if 'date' in request.params:
                    days = request.params.getone('date')
                
                if 'source' in request.params:
                    source = request.params.getone('source')
                if 'starred' in request.params:
                    tmp = request.params.getone('starred')
                    if tmp == 'true':
                        starred = True
                    else:
                        starred = False
                forgot_key = None
                #LogOut(header,request)
                init_db()
                user_name = ""
                
                authenticated = False
                session = request.session
                if 'authenticated' in session and session['authenticated']:
                        authenticated = True
                        uw = UserWorker()                       
                        user_name = uw.get_user_full_name(session['username'])
                else:
                        if len(query) > 0 or days != None or source != None:
                            query = ""
                            days = None
                            source = None
                            alert_message = u'تنها کاربران عضو قادر به جستجو می باشند';
                if 'forgotPasswordKey' in request.params.keys():
                        forgot_key = request.params.getone('forgotPasswordKey')

                nw = NewsWorker()
                news = nw.get_news(query,source,days,starred,session['user_id'] if 'user_id' in session else None)    
                sources = nw.get_all_sources()         
                return  {'news':news,'authenticated':authenticated,'user_name':user_name,'forgot_key':forgot_key,
                         'search_text':query,'search_source':source,'search_date':days,'alert_message':alert_message,
                         'sources':sources,'starred':'true' if starred== True else 'false'}
        except Exception as ex:
                Setting.log.log_exception(ex)
                if Setting.debuging:
                        return Response(ex.__str__())
                else:
                        return Response('sorry,problem')
Beispiel #8
0
def toggle_star(request):
    try:
        init_db()
        news_id = request.POST['news_id']
        user_id = request.session['user_id']
        nw = NewsWorker()
        res = nw.add_user_news(user_id,news_id)
        
        return {'success':True, 'result':res}
    except Exception as ex:
        return Response(ex.__str__())            
Beispiel #9
0
def get_all_sources(request):
    try:
        init_db()
        n = NewsWorker()
        res = n.get_all_sources()
        return {'rows':res}    
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')   
Beispiel #10
0
def set_user_profile(request):
    try:
        init_db()
        u = UserWorker()
        res = u.set_user_profile(request.session['user_id'],request.POST['name'],request.POST['familly'],
                                 request.POST['mobile_number'],request.POST['password'])        
        return {'success':res}    
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')   
Beispiel #11
0
def get_user_profile(request):
    try:
        init_db()
        u = UserWorker()
        info = u.get_user_profile(request.session['user_id'])
        return {'success':True , 'profile': {'name':info.name, 'familly':info.familly,
                                             'mobile_number':info.mobile_number,'username':info.username}}
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')    
Beispiel #12
0
def home_page(header, request):
    #raise()
    Setting.log.log_request(request)
    try:

        query = ""
        alert_message = ""
        if 'q' in request.params:
            query = request.params.getone('q')
        forgot_key = None
        #LogOut(header,request)
        init_db()
        user_name = ""

        authenticated = False
        session = request.session
        if 'authenticated' in session and session['authenticated']:
            authenticated = True
            uw = UserWorker()
            user_name = uw.get_user_full_name(session['username'])
        else:
            if len(query) > 0:
                query = ""
                alert_message = 'تنها کاربران عضو قادر به جستجو می باشند'
        if 'forgotPasswordKey' in request.params.keys():
            forgot_key = request.params.getone('forgotPasswordKey')

        nw = NewsWorker()
        news = nw.get_news(
            query, session['user_id'] if 'user_id' in session else None)
        return {
            'news': news,
            'authenticated': authenticated,
            'user_name': user_name,
            'forgot_key': forgot_key,
            'search_text': query,
            'alert_message': alert_message
        }
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')
Beispiel #13
0
def source_manager(request):
    init_db()
    nw = NewsWorker()
    feeds = []
    sources = nw.get_all_sources()
    current_source=-1
    if 'cbFeedSource' in request.POST:
        current_source = request.POST['cbFeedSource']
    else:
        current_source = sources[0]['id']    
    feeds = nw.get_source_feed(current_source)
       
    
    
    for s in sources: 
        s['selected'] = 'selected' if s['id']==int(current_source) else None
        print(s['id'])
        
    return render_to_response('../frontend/templates/source_manager.pt',{'sources':sources,'feeds':feeds,'current_source':current_source},request=request)
Beispiel #14
0
def home_page(header, request):
    # raise()
    Setting.log.log_request(request)
    try:

        query = ""
        alert_message = ""
        if "q" in request.params:
            query = request.params.getone("q")
        forgot_key = None
        # LogOut(header,request)
        init_db()
        user_name = ""
        authenticated = False
        session = request.session
        if "authenticated" in session and session["authenticated"]:
            authenticated = True
            uw = UserWorker()
            user_name = uw.get_user_full_name(session["username"])
        else:
            if len(query) > 0:
                query = ""
                alert_message = "تنها کاربران عضو قادر به جستجو می باشند"
        if "forgotPasswordKey" in request.params.keys():
            forgot_key = request.params.getone("forgotPasswordKey")

        nw = NewsWorker()
        news = nw.get_news(query)
        return {
            "news": news,
            "authenticated": authenticated,
            "user_name": user_name,
            "forgot_key": forgot_key,
            "search_text": query,
            "alert_message": alert_message,
        }
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response("sorry,problem")
Beispiel #15
0
def feedback(request):   
    try:
        init_db()
        content = request.POST['txtFeedback']
        Setting.log.info('inserting feedback '+content)
        fk_user = None
        
        if ('user_id' in request.session and  request.session['user_id'] != None ):
            fk_user = request.session['user_id']
            Setting.log.info('feedback is from signed in user with id='+str(fk_user))
                    
        feedback_record = Feedback(contents = content, fk_user = fk_user, submit_date = datetime.now());                
        feedback_record.save()
        Setting.log.info('insert feedback done')
        return {}
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')
Beispiel #16
0
def sign_in(request):
    try:
        success = False
        if request.POST.has_key('username') and request.POST.has_key('password') :
            Setting.log.info("login attemp for user:"+request.POST['username'])
            uw = UserWorker()
            init_db()
            res = uw.sign_in(request.POST['username'], request.POST['password'])
            if res[0] :
                request.session['authenticated'] =  True 
                request.session['username'] = request.POST['username']
                request.session['user_id' ] = res[2]
                Setting.log.info('sign in done for '+res[1]+' and user id is '+str(res[2]))
                return {'success':True,'name':res[1]}   
                
        return {'success':success}
    except Exception as ex:
        Setting.log.log_exception(ex)
        if Setting.debuging:
            return Response(ex.__str__())
        else:
            return Response('sorry,problem')
Beispiel #17
0
def forgot_password(request):
    try:
        success = False
        if request.POST.has_key('username'):
            username = request.POST['username']
            
            Setting.log.info("Forgot password attemp for user:"******"":
                Setting.log.info("Forgot password attemp for user:"******"Forgot password attemp for user:"******"receiving email template")
                (title, text, html) = get_forgot_password_template()

                site_prefix = "www"
                if ( Setting.mode == "beta" ):
                    site_prefix="beta"
                    
                text = text.format("http://"+site_prefix+".yeksatr.com/?forgotPasswordKey="+reset_password_key)
                html = html.format("http://"+site_prefix+".yeksatr.com/?forgotPasswordKey="+reset_password_key)
                
                Setting.log.info("got template - title is "+title)
                sendmail(email, title, text, html)
                Setting.log.info("mail sent to "+email)
                
    except Exception as ex:
        Setting.log.log_exception(ex)

    return Response('')
Beispiel #18
0
def home_page(header,request):   
        #raise()
        Setting.log.log_request(request)
        try:
               
                query = ""
                alert_message = ""
                if 'q' in request.params:
                    query = request.params.getone('q')
                forgot_key = None
                #LogOut(header,request)
                init_db()
                user_name = ""
                
                authenticated = False
                session = request.session
                if 'authenticated' in session and session['authenticated']:
                        authenticated = True
                        uw = UserWorker()                       
                        user_name = uw.get_user_full_name(session['username'])
                else:
                        if len(query) > 0 :
                            query = ""
                            alert_message = u'تنها کاربران عضو قادر به جستجو می باشند';
                if 'forgotPasswordKey' in request.params.keys():
                        forgot_key = request.params.getone('forgotPasswordKey')

                nw = NewsWorker()
                news = nw.get_news(query,session['user_id'] if 'user_id' in session else None)             
                return  {'news':news,'authenticated':authenticated,'user_name':user_name,'forgot_key':forgot_key,'search_text':query,'alert_message':alert_message}
        except Exception as ex:
                Setting.log.log_exception(ex)
                if Setting.debuging:
                        return Response(ex.__str__())
                else:
                        return Response('sorry,problem')
Beispiel #19
0
def InitSetting(path):    
    config = configparser.ConfigParser()
    config.read(path)
    init_setting(config)
    init_db()
Beispiel #20
0
def get_bulletin_filter_dialog(request):
    init_db()
    nw = NewsWorker()    
    sources = nw.get_all_sources()   
    return render_to_response('../frontend/templates/index.bulletin.filter.pt',
                              {'bulletin_id':request.POST['bulletin_id'],'sources':sources},request=request)
Beispiel #21
0
# -*- coding: utf8 -*-
# encoding=utf8  
import configparser,sys

from yeksatr.backend.helpers.setting import init_setting, init_db
from yeksatr.backend.helpers.setting import Setting

from feed.rssreader import RssReader
from feed.newsagent import NewsAgent

if __name__ == '__main__':
    path = "../development.ini";
    config = configparser.ConfigParser()
    config.read(path)
    init_setting(config)
    init_db()
 
    for i in range(len(sys.argv)):
        param = sys.argv[i]
        if param == '-update' :
            rr = RssReader()
            rr.read()
            pass
        elif param == '-extract':
            na = NewsAgent()    
            na.extract_news(30)
            pass
    

    print ("jobs done")
    pass
Beispiel #22
0
def InitSetting(path):
    config = configparser.ConfigParser()
    config.read(path)
    init_setting(config)
    init_db()
Beispiel #23
0
def add_bulletin(request):
    init_db()
    nw = NewsWorker()
    nw.add_bulletin(request.session['user_id'], request.POST['query_text'], int(request.POST['scan_period']), int(request.POST['source']),
                     request.POST['starred'], int(request.POST['bulletin_id']))
    return {'success':True}
Beispiel #24
0
def get_user_bulletin(request):
    init_db()    
    nw = NewsWorker()    
    return {'success':True,'data':nw.get_user_bulletin(request.session['user_id'])}
Beispiel #25
0
# -*- coding: utf8 -*-
# encoding=utf8
import configparser, sys

from yeksatr.backend.helpers.setting import init_setting, init_db
from yeksatr.backend.helpers.setting import Setting

from feed.rssreader import RssReader
from feed.newsagent import NewsAgent

if __name__ == '__main__':
    path = "../development.ini"
    config = configparser.ConfigParser()
    config.read(path)
    init_setting(config)
    init_db()

    for i in range(len(sys.argv)):
        param = sys.argv[i]
        if param == '-update':
            rr = RssReader()
            rr.read()
            pass
        elif param == '-extract':
            na = NewsAgent()
            na.extract_news(30)
            pass

    print("jobs done")
    pass
Beispiel #26
0
def add_bulletin_filter(request):
    init_db()
    nw = NewsWorker()
    nw.add_bulletin_filter(request.POST['bulletin_id'],int(request.POST['source_id']) if int(request.POST['source_id'])>=0 else None ,
                           request.POST['query_text'])
    return {'success':True}
Beispiel #27
0
def get_bulletin_filter(request):
    init_db()    
    nw = NewsWorker()    
    return {'success':True,'data':nw.get_bulletin_filter(request.POST['bulletin_id'],request.session['user_id'])}
Beispiel #28
0
def remove_bulletin(request):
    init_db()
    nw = NewsWorker()
    res = nw.remove_bulletin(request.POST['bulletin_id'],request.session['user_id'])
    return {'success':res}