Exemplo n.º 1
0
def add_data():
    '''Lägger till data från databas och returnerar till ursprungssidan annars welcome_user'''
    popper_name = request.cookies.get('popper_name')

    if logged_in_status() == True and validate_login(popper_name) == True:
        try:
            task_title = request.form['new_task_header']
            task_content = request.form['task_content'].replace("\r\n", "\\n")
            task_prio = request.form['task_prio']
            task_enddate = request.form['new_task_enddate']
            user = request.cookies.get('user_id')

            origin_path = request.referrer.split("/")[3]
            task.add_task(task_title, task_content, task_prio, task_enddate,
                          user)
            if origin_path == 'timeline' or origin_path == 'tidslinje':
                return redirect(url_for('tidslinje'))
            elif origin_path == 'calendar' or origin_path == 'kalender':
                return redirect(url_for('kalender'))
            elif origin_path == 'settings':
                popper = request.cookies.get('popper_name')
                return redirect(url_for('settings', pagename=popper))
            else:
                popper = request.cookies.get('popper_name')
                return redirect(url_for('welcome_user', pagename=popper))
        except:
            popper = request.cookies.get('popper_name')
            return redirect(url_for('welcome_user', pagename=popper))
    else:
        return render_template('error.html', error="Logga in först")
Exemplo n.º 2
0
def rank(update, context):
    try:
        r = connector.get_connection()
        chat_type = update.effective_chat.type
        user_id = update.effective_user.id
        chat_id = update.effective_message.chat_id
        try:
            username = update.effective_user.username
        except Exception as e:
            username = update.effective_user.id
        # 限制为群组
        if chat_type != "supergroup":
            update.message.reply_text("此命令只有在群组中有效")
            return
        if RANK_COMMAND_MODE == 1:
            try:
                chat_member = bot.get_chat_member(chat_id, user_id)
                status = chat_member["status"]
                print("此用户在群组中身份为: {}".format(status))
                if status == "creator" or status == "administrator":
                    print("用户权限正确")
                else:
                    update.message.reply_text("此命令仅对管理员开放")
                    return
            except Exception as e:
                print(e)
                print("获取用户身份失败")
        if r.exists("{}_frequency_limit".format(chat_id)):
            r.setrange("{}_frequency_limit".format(chat_id), 0,
                       int(r.get("{}_frequency_limit".format(chat_id))) + 1)
        else:
            struct_time = time.localtime(time.time())
            # 数据过期时间为当前小时的 59 分
            ex_time = datetime.datetime(struct_time.tm_year,
                                        struct_time.tm_mon,
                                        struct_time.tm_mday,
                                        struct_time.tm_hour, 59)
            r.set("{}_frequency_limit".format(chat_id), 1)
            r.expireat("{}_frequency_limit".format(chat_id), ex_time)
        count = int(r.get("{}_frequency_limit".format(chat_id)))
        if count > LIMIT_COUNT:
            update.message.reply_text("该群组在这个小时内的生成配额已经用完,请稍后再试~")
            return
        add_task(chat_id)
        print("群组: {},用户: {}|{} 发起了主动触发请求".format(
            chat_id,
            username,
            user_id,
        ))
        update.message.reply_text("统计数据将在分析完毕后发送到当前群组,请稍等~")
    except Exception as e:
        print("主动触发任务失败,请检查")
        print(e)
Exemplo n.º 3
0
def add_task():
    data = request.json
    # userId = data.get(TASKOWNERID)
    try:
        if Task.add_task(data):
            return Respond.return_success_with_data(data)
    except:
        return Respond.return_failed()
Exemplo n.º 4
0
 def setUp(self):
     self.test_tdate = "1000-10-10"
     self.test_ename = "test_name"
     self.test_tname = "test_task"
     self.test_ttime = "50"
     self.test_tnotes = "test_notes"
     self.test_task = task.add_task(self.test_tdate, self.test_ename,
                                    self.test_tname, self.test_ttime,
                                    self.test_tnotes)
Exemplo n.º 5
0
 def setUp(self):
     self.test_tdate = "2006-10-10"
     self.test_ename = "somebody"
     self.test_tname = "test task"
     self.test_ttime = "10"
     self.test_tnotes = "test notes"
     self.test_task = task.add_task(self.test_tdate, self.test_ename,
                                    self.test_tname, self.test_ttime,
                                    self.test_tnotes)
Exemplo n.º 6
0
def add_task(data, username=''):
    serializer = TaskSerializer(data=data)

    if not serializer.is_valid():
        raise IgniteException(serializer.errors)

    task_obj = task.add_task(serializer.data, username)
    serializer = TaskBriefSerializer(task_obj)
    return serializer.data
Exemplo n.º 7
0
def app_menu():
    """Application menu"""
    init_task_db()
    while True:
        clear_screen()
        prompt_res = input(MAIN_MENU).upper()
        clear_screen()
        if prompt_res == 'A':
            add_task(get_user_date(),
                     get_emp_name().strip(),
                     input(TASK_NAME).strip(), task_minutes(),
                     input(NOTES).strip())
        elif prompt_res == 'B':
            tasks_search()
        elif prompt_res == 'C':
            db.close()
            return None
        else:
            print("Error: Please provide a valid input: a,b or c\n\n")
            time.sleep(4)
Exemplo n.º 8
0
 def test_add_task(self):
     task_name = "TESTING TASK"
     priority = 9
     self.assertNotIn(task_name, self.task_dictionary)
     task.add_task(task_name, priority, self.task_dictionary)
     self.assertIn(task_name, self.task_dictionary["Active"])