def post(self, request, server_id): title = request.POST.get('title') new_channel = request.POST.get("name") server = Server.objects.get(id=server_id) if title is not None and len(title) <= 20: description = request.POST.get('description') assignments = request.POST.getlist('assignments') deadline = request.POST.get('deadline') server = Server.objects.get(id=server_id) server_task_id = Task.objects.filter(server=server).count() + 1 task = Task.objects.create(task_id=server_task_id, title=title, description=description, author=request.user, server=server) if deadline != "": task.deadline = deadline if len(assignments) == 0: task.assigned_for.add(request.user) else: for username in assignments: task.assigned_for.add(server.users.get(username=username)) task.save() response = redirect("server_tasks", server_id) response['Location'] += '?order=-deadline' return response elif (new_channel is not None and 0 < len(new_channel) <= 20 and Channel.objects.filter(name=new_channel, server=server).first() is None): if server is not None: channel = Channel(name=new_channel, server=server) channel.save() return redirect("room", pk=server_id, room_name=new_channel) else: return HttpResponseRedirect(self.request.path_info)
def post(self, request, server_id, id): new_channel = request.POST.get("name") server = Server.objects.get(id=server_id) task = Task.objects.get(id=id) if new_channel is not None and 0 < len(new_channel) <= 20 and Channel.objects.filter( name=new_channel, server=server).first() is None: if server is not None: channel = Channel(name=new_channel, server=server) channel.save() return redirect("room", pk=server_id, room_name=new_channel) elif request.POST.get("delete_task"): if request.user == task.author: task.delete() return redirect("server_tasks", server_id) elif request.POST.get("comment_task"): form = TaskCommentForm(request.POST) form.instance.task_type = "comment" form.instance.author = request.user form.instance.task = task if form.is_valid(): content = form.cleaned_data.get('content') if len(content.replace(" ", "").replace(" ", "").replace("<p>", "").replace("</p>", "")) == 0: return HttpResponseRedirect(self.request.path_info) form.save() elif request.POST.get("delete_message"): comment_id = request.POST.get("comment_id") comment = TaskComment.objects.get(id=comment_id) if comment.author == request.user: comment.delete() return HttpResponseRedirect(self.request.path_info)
def post(self, request, server_id, id): new_channel = request.POST.get("name") server = Server.objects.get(id=server_id) if new_channel is not None and 0 < len(new_channel) <= 20 and Channel.objects.filter( name=new_channel, server=server).first() is None: if server is not None: channel = Channel(name=new_channel, server=server) channel.save() return redirect("room", pk=server_id, room_name=new_channel) title = request.POST.get("title") description = request.POST.get("description") task = Task.objects.get(id=id) task.assigned_for.clear() assigned_list = request.POST.get("assigned_users_list") for user in json.loads(assigned_list): if User.objects.filter(username=user).first() in server.users.all(): task.assigned_for.add(User.objects.get(username=user)) if task.assigned_for.count() == 0: task.assigned_for.add(task.author) if len(title) <= 20: task.title = title if len(description) <= 4000: task.description = description task.save() return redirect("task_detail", server_id, id)
def create(request): c = Channel() newhash = base64.urlsafe_b64encode(hashlib.md5(str(time.time())).digest()) # Remove dashes and underscores to make this easier to type newhash = newhash.replace("-", "") newhash = newhash.replace("_", "") c.hash = newhash[0:6] c.name = "" c.pusher_key = "private-videochannel_" + c.hash c.save() return redirect("/channel/" + c.hash)