Esempio n. 1
0
 def get_create_activity_list(self, info):
     '''
     我创建的活动列表
     第一步: 验证用户身份
     第二步: 判断活动是否存在,是否已经加入,是否已经满员
     第三步: 自动分配活动位置, 创建参加记录
     :param info: {'token_id': '', 'user_id': '', 'activity_id': ''}
     :return: {'data': '', 'status': 'SUCCESS'}
     '''
     start_index = info['start_index']
     page_count = info['page_count']
     user_id = info['user_id']
     query = db.session.query(Activity).filter(Activity.user_id == user_id)
     all_result = query.order_by(desc(Activity.createtime)).offset(start_index).limit(page_count).all()
     callback_data = []
     img_request = {}
     img_request['directory'] = 'activity'
     imagemanager = ImageManager()
     for result in all_result:
         (status, activity_info) = Activity.generate(result=result)
         img_request['foreign_id'] = result.activity_id
         (status, image_info) = imagemanager.get_image(info=img_request)
         activity_info.update(image_info)
         callback_data.append(activity_info)
     return (True, callback_data)
Esempio n. 2
0
 def get_create_activity_list(self, info):
     '''
     我创建的活动列表
     第一步: 验证用户身份
     第二步: 判断活动是否存在,是否已经加入,是否已经满员
     第三步: 自动分配活动位置, 创建参加记录
     :param info: {'token_id': '', 'user_id': '', 'activity_id': ''}
     :return: {'data': '', 'status': 'SUCCESS'}
     '''
     start_index = info['start_index']
     page_count = info['page_count']
     user_id = info['user_id']
     query = db.session.query(Activity).filter(Activity.user_id == user_id)
     all_result = query.order_by(desc(
         Activity.createtime)).offset(start_index).limit(page_count).all()
     callback_data = []
     img_request = {}
     img_request['directory'] = 'activity'
     imagemanager = ImageManager()
     for result in all_result:
         (status, activity_info) = Activity.generate(result=result)
         img_request['foreign_id'] = result.activity_id
         (status, image_info) = imagemanager.get_image(info=img_request)
         activity_info.update(image_info)
         callback_data.append(activity_info)
     return (True, callback_data)
Esempio n. 3
0
    def get(self):
        # result = memcache.get("index")
        result = False
        if not result:
            logging.info("cache not hit(index)")
            user = users.get_current_user()
            if user:
                greeting = ("%s : <a href=\"%s\">logout</a>" %
                            (user.nickname(), users.create_logout_url("/")))
            else:
                greeting = ("<a href=\"%s\">login</a>" %
                            users.create_login_url("/"))


            template_values = {
                'greeting': greeting,
                'user': user,
                'activities': Activity.all().order('-created_at').fetch(5),
                'books': Book.all().order('-created_at').fetch(1000),
                }
            path = os.path.join(os.path.dirname(__file__), '..', 'view', 'index.html')
            result = template.render(path, template_values)
            # memcache.set("index", result, 600)

        self.response.out.write(result)
Esempio n. 4
0
 def create_activity(self, info):
     '''
     创建活动
     第一步: 验证用户身份
     第二步: 创建Imgpath, Activity信息
     :param info: {'token_id': '', 'user_name': '', 'imgpath': '', 'user_id': '', 'open_id': ''}
     :return: {'data': '', 'status': 'SUCCESS'}
     '''
     print(info)
     info['activity_id'] = self.generate_id(info['activity_name'])
     info['imgpath_id'] = self.generate_id(info['imgpath'])
     info['foreign_id'] = info['activity_id']
     ImgPath.create(info=info)
     info['createtime'] = datetime.now()
     Activity.create(info=info)
     db.session.commit()
     return (True, info['activity_id'])
Esempio n. 5
0
 def create_activity(self, info):
     '''
     创建活动
     第一步: 验证用户身份
     第二步: 创建Imgpath, Activity信息
     :param info: {'token_id': '', 'user_name': '', 'imgpath': '', 'user_id': '', 'open_id': ''}
     :return: {'data': '', 'status': 'SUCCESS'}
     '''
     print(info)
     info['activity_id'] = self.generate_id(info['activity_name'])
     info['imgpath_id'] = self.generate_id(info['imgpath'])
     info['foreign_id'] = info['activity_id']
     ImgPath.create(info=info)
     info['createtime'] = datetime.now()
     Activity.create(info=info)
     db.session.commit()
     return (True, info['activity_id'])
Esempio n. 6
0
    def readActivity(self):
        """
		Read one activity and insert it in the database
		"""
        data = json.load(self.path)

        for row in data["data"]:
            self.result.append(
                Activity(row["EquipementId"], row["ActLib"],
                         row["EquipementId"]))
Esempio n. 7
0
 def _get_activity_detail(self, info):
     activity_id = info['activity_id']
     query = db.session.query(Activity).filter(Activity.activity_id == activity_id)
     result = query.first()
     img_request = {}
     img_request['directory'] = 'activity'
     img_request['foreign_id'] = activity_id
     imagemanager = ImageManager()
     (status, activity_info) = Activity.generate(result=result)
     (status, image_info) = imagemanager.get_image(info=img_request)
     activity_info.update(image_info)
     return (True, activity_info)
    def read_Activities(self):
        """
		Reading of the entire installation table
		"""
        c = self.conn.cursor()
        c.execute('SELECT * FROM activite')
        result = c.fetchall()
        activites = []

        for a in result:
            activites.append(Activity(a[0], a[1], 0))

        return activites
Esempio n. 9
0
 def _get_activity_detail(self, info):
     activity_id = info['activity_id']
     query = db.session.query(Activity).filter(
         Activity.activity_id == activity_id)
     result = query.first()
     img_request = {}
     img_request['directory'] = 'activity'
     img_request['foreign_id'] = activity_id
     imagemanager = ImageManager()
     (status, activity_info) = Activity.generate(result=result)
     (status, image_info) = imagemanager.get_image(info=img_request)
     activity_info.update(image_info)
     return (True, activity_info)
Esempio n. 10
0
    def read_activities(self):
        """
        Reads all the activities from the 'activites' table
        """
        c = self.conn.cursor()
        c.execute('SELECT * FROM activites')
        rows = c.fetchall()
        activities = []

        for row in rows:
            activities.append(Activity(row[0], row[1], 0))

        return activities
    def read_One_Activity(self, number):
        """
		Read the entry of the given number
		"""
        c = self.conn.cursor()
        c.execute('SELECT * FROM activite WHERE number = :givenNumber',
                  {'givenNumber': number})
        result = c.fetchone()

        try:
            activity = Activity(result[0], result[1], 0)
        except:
            return "Il n'y a pas d'activité qui possède ce numéro"
        return activity
Esempio n. 12
0
 def create_activity_background(self, info):
     '''
     后台,创建活动
     第一步: 验证管理员身份
     第二步: 创建Imgpath, Activity信息
     :param info: {'token_id': '', 'user_name': '', 'imgpath': '', 'user_id': '', 'open_id': ''}
     :return: {'data': '', 'status': 'SUCCESS'}
     '''
     print(info)
     info['activity_id'] = self.generate_id(info['activity_name'])
     info['imgpath_id'] = self.generate_id(info['imgpath'])
     info['foreign_id'] = info['activity_id']
     ImgPath.create(info=info)
     info['createtime'] = datetime.now()
     if 'club_id' in info:
         info['type_id'] = ACTIVITY_CLUB
         info['area'] = None
     else:
         info['club_id'] = None
         info['type_id'] = ACTIVITY_USER
     Activity.create(info=info)
     db.session.commit()
     return (True, info['activity_id'])
Esempio n. 13
0
 def create_activity_background(self, info):
     '''
     后台,创建活动
     第一步: 验证管理员身份
     第二步: 创建Imgpath, Activity信息
     :param info: {'token_id': '', 'user_name': '', 'imgpath': '', 'user_id': '', 'open_id': ''}
     :return: {'data': '', 'status': 'SUCCESS'}
     '''
     print(info)
     info['activity_id'] = self.generate_id(info['activity_name'])
     info['imgpath_id'] = self.generate_id(info['imgpath'])
     info['foreign_id'] = info['activity_id']
     ImgPath.create(info=info)
     info['createtime'] = datetime.now()
     if 'club_id' in info:
         info['type_id'] = ACTIVITY_CLUB
         info['area'] = None
     else:
         info['club_id'] = None
         info['type_id'] = ACTIVITY_USER
     Activity.create(info=info)
     db.session.commit()
     return (True, info['activity_id'])
Esempio n. 14
0
    def read_activity(self, number):
        """
        Reads the activity which has the given number from the 'activites' table
        """
        c = self.conn.cursor()
        c.execute('SELECT * FROM activites WHERE ac.numero = :numero',
                  {'numero': number})
        row = c.fetchone()

        try:
            activity = Activity(row[0], row[1], 0)
        except TypeError:
            return '<h2>Aucune activité ne correspond à ce numéro</h2>'

        return activity
Esempio n. 15
0
    def create_random_activity(self, categories):

        randomized_categories = random.sample(set(categories),2)

        if 'museum' in randomized_categories:
            a = Activity(name='The famouse museum',category_ids=['museum'])

        elif 'food' in randomized_categories:
            a = Activity(name='The famous restaurnat',category_ids=['food','asianfood'])

        else:
            a = Activity(name='The famouse activity',category_ids=['laidback'])

        return a.to_dict()
    def read_Informations(self, activity, city):
        """      
		Read information about a sport in a city
		"""
        c = self.conn.cursor()
        #c.execute("""SELECT i.number, i.name, e.number, e.name, a.number, a.name FROM installation i JOIN equipement e ON i.number = e.installationNumber JOIN equipement_activite ea ON e.number = ea.number_equipment JOIN activite a ON ea.number_activity = a.number WHERE i.city = ' + city + '  AND a.name LIKE '% + activity + %'""")
        c.execute(
            "SELECT DISTINCT i.number, i.name, e.number, e.name, a.number, a.name FROM installation i, equipement e, equipement_activite ea, activite a WHERE i.number = e.installationNumber AND e.number = ea.number_equipment AND ea.number_activity = a.number AND i.city = ' + city + '  AND a.name LIKE '% + activity + %'"
            "")
        result = c.fetchall()
        query = []

        for r in result:
            query.append(Installation(r[0], r[1]), Equipment(r[0], r[1]),
                         Activity(r[0], r[1]))

        print(query)
        return query
Esempio n. 17
0
    def get_infos(self, activity_name, city):
        """
        Gives all the installations, equipments and activities which match the given activity and city
        """
        c = self.conn.cursor()
        c.execute("""SELECT i.numero, i.nom, e.numero, e.nom, a.numero, a.nom
        FROM installations i
        JOIN equipements e ON i.numero = e.numero_installation
        JOIN equipements_activites ea ON e.numero = ea.numero_equipement
        JOIN activites a ON ea.numero_activite = a.numero
        WHERE LOWER(i.ville) = LOWER('""" + city + """') AND a.nom LIKE '%""" +
                  activity_name + """%'""")
        rows = c.fetchall()
        results = []

        for row in rows:
            results.append(
                (Installation(row[0],
                              row[1]), Equipment(row[2], row[3], row[0]),
                 Activity(row[4], row[5], row[2])))

        return results
Esempio n. 18
0
    def read_activities(self, path):
        """
        Reads a JSON file which contains data for the activities

        >>> reader = ReadJSON()
        >>> activities = reader.read_activities("data/test_activite.json")
        >>> (activities[0].number, activities[0].name, activities[0].equipment_number)
        ('3501', 'Gymnastique volontaire', ' 213704')
        """
        file = open(path)
        data = json.load(file)
        result = []

        pbar = ProgressBar(
            widgets=['Reading activities JSON: ',
                     Percentage(), ' ',
                     ETA()])
        for line in pbar(data["data"]):
            result.append(
                Activity(line["ActCode"], line["ActLib"],
                         line["EquipementId"]))

        return result
Esempio n. 19
0
 def post(self):        
     activity = ActivityModel()        
     activity.name = self.request.get('name')
     activity.put()
     
     self.redirect('/admin/activity')
Esempio n. 20
0
def extract_test_data(testdata, excel_dict):
    for item in excel_dict:
        for key in item:
            if item[key] == "":
                item[key] = None
        testdata.append(Activity(**item))