Subversion Repositories SmartDukaan

Rev

Rev 1743 | Rev 1859 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1743 Rev 1845
Line 4... Line 4...
4
@author: ashish
4
@author: ashish
5
'''
5
'''
6
from shop2020.model.v1.user.impl import Dataservice
6
from shop2020.model.v1.user.impl import Dataservice
7
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
7
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
8
from shop2020.model.v1.user.impl.Dataservice import User, UserCommunication, IPMap,\
8
from shop2020.model.v1.user.impl.Dataservice import User, UserCommunication, IPMap,\
9
    Address, SocialHandle, UserState, InternalInfo, SocialService
9
    Address, SocialHandle, UserState, InternalInfo, SocialService, Affiliate, Tracker, TrackLog,\
-
 
10
    MasterAffiliate
10
from shop2020.thriftpy.model.v1.user.ttypes import UserContextException,\
11
from shop2020.thriftpy.model.v1.user.ttypes import UserContextException,\
11
    AuthenticationException, AccountStatus, Sex
12
    AuthenticationException, AccountStatus, Sex
12
from shop2020.clients.HelperClient import HelperClient
13
from shop2020.clients.HelperClient import HelperClient
13
from elixir import session
14
from elixir import session
14
import datetime, random, string
15
import datetime, random, string
Line 269... Line 270...
269
    return UserCommunication.query.filter_by(user_id = user_communication_user_id).order_by(-UserCommunication.id).all()
270
    return UserCommunication.query.filter_by(user_id = user_communication_user_id).order_by(-UserCommunication.id).all()
270
 
271
 
271
def get_all_user_communications():
272
def get_all_user_communications():
272
    return UserCommunication.query.order_by(UserCommunication.user_id, -UserCommunication.id).all()
273
    return UserCommunication.query.order_by(UserCommunication.user_id, -UserCommunication.id).all()
273
 
274
 
-
 
275
def create_master_affiliate(name):
-
 
276
    master_affiliate = MasterAffiliate()
-
 
277
    master_affiliate.name = name
-
 
278
    session.commit()
-
 
279
    return master_affiliate
-
 
280
 
-
 
281
def get_master_affiliate_by_id(id):
-
 
282
    return MasterAffiliate.get_by(id = id)
-
 
283
 
-
 
284
def get_master_affiliate_by_name(name):
-
 
285
    return MasterAffiliate.get_by(name = name)
-
 
286
 
-
 
287
def create_affiliate(name, url, master_affiliate_id):
-
 
288
    affiliate = Affiliate()
-
 
289
    affiliate.name = name
-
 
290
    if url is not None:
-
 
291
        affiliate.url = url
-
 
292
    affiliate.master_affiliate_id = master_affiliate_id
-
 
293
    session.commit()
-
 
294
    return affiliate
-
 
295
 
-
 
296
def get_affiliate_by_id(id):
-
 
297
    return Affiliate.get_by(id = id)
-
 
298
 
-
 
299
def get_affiliate_by_name(name):
-
 
300
    return Affiliate.get_by(name = name)
-
 
301
 
-
 
302
def get_affiliates_by_master_affiliate(master_affiliate_id):
-
 
303
    return MasterAffiliate.get_by(id =  master_affiliate_id).affiliates
-
 
304
 
-
 
305
def create_tracker(affiliate_id):
-
 
306
    tracker = Tracker()
-
 
307
    tracker.affiliate_id = affiliate_id
-
 
308
    session.commit()
-
 
309
    return tracker
-
 
310
 
-
 
311
def get_tracker_by_id(id):
-
 
312
    return Tracker.get_by(id = id)
-
 
313
 
-
 
314
def get_trackers_by_affiliate(affiliate_id):
-
 
315
    return Affiliate.get_by(id = affiliate_id).trackers
-
 
316
 
-
 
317
def add_track_log(tracker_id, user_id, event, url, data):
-
 
318
    track_log = TrackLog()
-
 
319
    track_log.tracker_id = tracker_id
-
 
320
    if user_id:
-
 
321
        track_log.user_id = user_id
-
 
322
    track_log.event = event
-
 
323
    if url:
-
 
324
        track_log.url = url
-
 
325
    if data:
-
 
326
        track_log.date = data
-
 
327
    session.commit()
-
 
328
    return track_log.id
-
 
329
 
-
 
330
def get_track_log_by_id(id):
-
 
331
    return TrackLog.get_by(id = id)
-
 
332
 
-
 
333
def get_track_logs_by_tracker(tracker_id):
-
 
334
    return Tracker.get_by(id = tracker_id).tracklogs
-
 
335
 
-
 
336
def get_track_logs_by_user(user_id):
-
 
337
    return TrackLog.query.filter(TrackLog.user_id == user_id).all()
-
 
338
 
-
 
339
def get_track_logs(trackerId, userId, event, url):
-
 
340
    query = TrackLog.query
-
 
341
    
-
 
342
    if trackerId:
-
 
343
        query = query.filter(TrackLog.tracker_id == trackerId)
-
 
344
    if userId:
-
 
345
        query = query.filter(TrackLog.user_id == userId)
-
 
346
    if event:
-
 
347
        query = query.filter(TrackLog.event == event)
-
 
348
    if url:
-
 
349
        query = query.filter(TrackLog.url == url)
-
 
350
    return query.all()
-
 
351
 
-
 
352
 
274
def get_address(address_id):
353
def get_address(address_id):
275
    address = Address.get_by(id=address_id)
354
    address = Address.get_by(id=address_id)
276
    return address
355
    return address
277
 
356
 
278
def get_social_service(service_id):
357
def get_social_service(service_id):