def addTask(request): name = request.GET['taskname'] desc = request.GET['taskdesc'] freq = request.GET['taskfreq'] task = Task(name=name, description=desc, weeklyfreq=int(freq)) task.save() return HttpResponse(status=200)
def mutate(self, info, **kwargs): taskId = kwargs.get('taskId') try: task = Task.objects.get(id=taskId) Task.delete(task) return DeleteTaskMutation(status=200, message='successful') except Exception as e: return DeleteTaskMutation(status=500, message='failed')
def task_list_jsn(request): if request.method == 'GET': tasks = Task.objects.all() tasks = [t.to_json() for t in tasks] return JsonResponse(tasks, safe=False) elif request.method == 'POST': data = json.loads(request.body) task= Task(title=data['title'], owner=request.user,created = datetime.datetime.now() ,due = datetime.datetime.now() + datetime.timedelta(days=1, hours=3), mark = False) task.save() return JsonResponse(task.to_json())
def addTask(request, list_id): if(request.POST.get('addTaskBtn')): owner = "ADM" if(request.POST.get('owner')): owner = "GST" mark = "False" if(request.POST.get('mark_checkbox')=="on"): mark="True" t = Task(list_name=Task_List.objects.get(pk=list_id), created_at=timezone.now(), due_on=request.POST.get('due_on_datetime-local'), owner=owner, mark=mark) t.save() return redirect('/todos/'+str(list_id)+"/")
def task_list(request): if request.method == 'GET': tasks = Task.objects.all() for task in tasks: task.to_json() return JsonResponse(Task.objects.first().to_json(), safe=False) elif request.method == 'POST': data = json.loads(request.body) tlist = Task(name=data['name'], created=data['created'], due_on=data['due_on'], owner=data['owner'], mark=data['mark']) tlist.save() return JsonResponse(tlist.to_json())
def start(self): # CREATE A TEAM MEMBER User.objects.create(username=f'demo-member-{self.user.team_id}', password=bcrypt.hashpw(b'securepassword', bcrypt.gensalt()), team_id=self.user.team_id) # CREATE TASKS with open('main/data/tutorial_tasks.json', 'r') as read_file: tutorial_tasks = json.load(read_file) # Subtasks cannot be created before the tasks are created, so two # iterations are needed. Otherwise, it would mean too many DB calls. tasks = [Task(title=task['title'], description=task['description'], order=i, column=self.column, user=self.user) for i, task in enumerate(tutorial_tasks)] Task.objects.bulk_create(tasks) subtasks = [Subtask(title=title, task=tasks[ti], order=si) for ti, task in enumerate(tutorial_tasks) for si, title in enumerate(task['subtasks'])] Subtask.objects.bulk_create(subtasks)
def task_add(request, task_id): """タスクの追加""" # print(task_id) task = Task() tasks = Task.objects if request.method == "POST": form = TaskForm(request.POST, instance=task) if form.is_valid(): if tasks.filter(id=task_id).exists(): messages.info(request, '1件のタスクを編集しました。') tasks.filter(id=task_id).delete() else: messages.info(request, '1件のタスクを追加しました。') task = form.save(commit=False) task.id = task_id task.save() form = TaskForm() return redirect('main:index')
def create(self, validated_data): task = Task(**validated_data) task.owner = User.objects.first() task.due_to = datetime.datetime.now() + datetime.timedelta(days=1, hours=3) task.created = datetime.datetime.now() task.save() return task
def index(request): """index""" form = TaskForm(instance=Task()) tasks = Task.objects.all().order_by('-id') paginate_by = 10 return render(request, 'main/index.html', {'form': form, 'time': timezone.now, 'tasks': tasks})
def create(self, validated_data): task = Task(**validated_data) task.created = datetime.datetime.now() task.due = datetime.datetime.now() + datetime.timedelta(days=1, hours=3) task.save() return task
async def giveaway(ctx, amount=None, timeout=30): if await channelcheck(server_list, ctx): return async with ctx.channel.typing(): if amount == None: embed = discord.Embed( title="Missing Arguments", description= f"To start a giveaway, you need to do `{bot_prefix}giveaway [amount] [time (in minutes)]`. ", color=bot_color) await ctx.send(embed=embed) return invalid = False try: amount = int(amount) timeout = int(timeout) except: invalid = True if amount <= 99 or timeout <= 1: invalid = True if invalid: embed = discord.Embed( title="Invalid Argument(s)", description= "One or more of your passed arguments are invalid. Did you do reach the 100 coin minimum?", color=bot_color) await ctx.send(embed=embed) return author_records = await sync_to_async(User.objects.filter )(DiscordID=ctx.author.id) user_coins = 0 if any(author_records): user_coins = author_records[0].Coins if user_coins >= amount: pass else: embed = discord.Embed( title="Not enough coins.", description= f"You only have {user_coins} out of {amount} coins in your wallet. You need to deposit coins to {bot_wallet} to do a giveaway.", color=bot_color) await ctx.send(embed=embed) return else: embed = discord.Embed( title="Not registered.", description=f"You need to be registered to do a giveaway", color=bot_color) await ctx.send(embed=embed) return await sync_to_async(author_records.update )(Coins=author_records[0].Coins - (amount)) enddate = utc.localize(datetime.datetime.utcnow() + datetime.timedelta(minutes=timeout)) announce = ctx.channel for server in server_list: if server.server_id == ctx.guild.id: announce = ctx.guild.get_channel(server.announcement_channel) embed = discord.Embed(title=f"Giveaway by {ctx.author.name}!", color=bot_color) embed.add_field(name='Ends', value=f"{enddate.strftime('%y-%m-%d %H:%M:%S')} GMT") embed.add_field(name='Amount', value=amount) message = await announce.send(embed=embed) await message.add_reaction("👍") info = { "host": ctx.author.id, "amount": amount, "guild": ctx.guild.id, "channel": announce.id, "message": message.id, } query = Task(Type="GIVEAWAY", Date=enddate, Info=json.dumps(info)) query.save()
def create(self, validated_data): task = Task(**validated_data) task.save() return task
def createTestTask(): task = Task(name="testtask", description="testing", weeklyfreq=1) task.save() return task
def create(self, validated_data): task = Task(**validated_data) task.owner = User.objects.first() task.save() return task
def handle(self, *args, **options): for infile in options['in_file']: data = yaml.load(infile) infile.close() if 'repeats' in data: # TODO: handle non-array repeats value for r in data['repeats']: new_r = Repeat() if 'name' in r: new_r.name = r['name'] if 'year' in r: new_r.year = self.n_from_in(r['year']) if 'month' in r: new_r.month = self.n_from_in(r['month']) if 'week' in r: new_r.week = self.n_from_in(r['week']) if 'day' in r: new_r.day = self.n_from_in(r['day']) new_r.save() r['new'] = new_r if 'tasks' in data: # TODO: handle non-array tasks for t in data['tasks']: new_t = Task() if 'dt' in t: if type(t['dt']) == date: t['dt'] = datetime.combine(t['dt'], datetime.min.time()) new_t.date_created = timezone.make_aware(t['dt'], timezone.get_default_timezone()) else: new_t.date_created = timezone.now() if 't' in t: new_t.name = t['t'] new_t.save() if 'schedules' in t: # TODO: handle non-array schedules section for s in t['schedules']: new_s = Schedule() if 'repeat' in s: new_s.repeat = s['repeat']['new'] if 'start_dt' in s: if type(s['start_dt']) == date: s['start_dt'] = datetime.combine(s['start_dt'], datetime.min.time()) new_s.start_date = timezone.make_aware(s['start_dt'], timezone.get_default_timezone()) else: new_s.start_date = new_t.date_created new_s.save() new_t.schedules.add(new_s) if 'statuses' in t: # TODO: handle non-array status section for s in t['statuses']: new_s = Status() if 'dt' in s: if type(s['dt']) == date: s['dt'] = datetime.combine(s['dt'], datetime.min.time()) new_s.date = timezone.make_aware(s['dt'], timezone.get_default_timezone()) else: new_s.date = new_t.date_created if 'status' in s: new_s.text = s['status'] if 'closes' in s: new_s.complete = s['closes'] new_s.task = new_t new_s.save() # raise CommandError('Poll "%s" does not exist' % poll_id) # self.stdout.write('Successfully closed poll "%s"' % poll_id)
def create_task(author=None, title='task_title_test', description='task_description_test', status=True): author = author or create_user_profile() task = Task(**locals()) task.save() return task