def create(request, p_id): user = request.user project = get_object_or_404(Project, pk=p_id) project.check_user_in_project_or_404(user) users_in_project = project.get_users() if not checkperm(PERMISSIONS_FILE_CREATE, user, project): return HttpResponseForbidden(_('Forbidden Access')) tags = utils.get_site_tags(project) users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_FILE_VIEW) if request.method == 'POST': form = NewFileForm(users_to_notify, tags, request.POST, request.FILES) if form.is_valid(): file = form.save(user, project) link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.file.views.view_file', kwargs={ 'p_id': project.id, 'file_id': file.id }), ) notification.send( file.notify_to.all(), "file_new", { 'link_url': link_url, 'file': file, 'file_name': os.path.basename( file.last_file_version.file_location.path).split( '_', 2)[-1] }) events_log(user, 'A', file.title, file) request.user.message_set.create( message=_('File "%s" successfully uploaded') % file.title) return HttpResponseRedirect( urlresolvers.reverse('rancho.file.views.list', args=[project.id])) else: form = NewFileForm(users_to_notify, tags) context = { 'project': project, 'users_in_project': users_in_project, 'form': form } return render_to_response('file/new_file.html', context, context_instance=RequestContext(request))
def edit(request, p_id, milestone_id): user = request.user project = get_object_or_404(Project, id = p_id) milestone = get_object_or_404(Milestone, id = milestone_id) users_in_project = project.get_users() if not checkperm(PERMISSIONS_MILESTONE_EDITDELETE, user, project, milestone) or milestone.project != project: return HttpResponseForbidden(_('Forbidden Access')) users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MILESTONE_VIEW) if request.method=='POST': form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_to_notify), request.POST) if form.is_valid(): user_id = int(form.cleaned_data['responsible']) if user_id != 0: milestone.responsible = get_object_or_404(User, id = user_id) else: milestone.responsible = None milestone.completion_date = None old_milestone_title = milestone.title milestone.title = form.cleaned_data['title'] milestone.due_date = form.cleaned_data['due_date'] milestone.send_notification_email = form.cleaned_data['send_notification_email'] milestone.save() if milestone.send_notification_email: link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.milestone.views.list', args = [p_id])) #link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),) if milestone.responsible: #just notify one person notification.send([milestone.responsible], "milestone_updated", {'link_url': link_url, 'milestone': milestone, 'old_milestone_title': old_milestone_title}) else: #notify entire project notification.send(users_to_notify, "milestone_updated", {'link_url': link_url, 'milestone': milestone, 'old_milestone_title': old_milestone_title }) events_log(user, 'U', milestone.title, milestone) request.user.message_set.create(message=_('Milestone successfully edited.')) else: responsible_index = 0 if milestone.responsible: responsible_index = milestone.responsible.id data = {'title': milestone.title, 'due_date': milestone.due_date.date(), 'responsible': responsible_index, 'send_notification_email': milestone.send_notification_email} form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_in_project), data) context = {'project': project, 'milestone': milestone, 'newMilestone': form, } return render_to_response("milestone/edit_milestone.html", context, context_instance = RequestContext(request))
def create(request, p_id): ''' Creates a new message ''' user = request.user project = get_object_or_404(Project, pk=p_id) project.check_user_in_project_or_404(user) users_in_project = project.get_users() if not checkperm(PERMISSIONS_MESSAGE_CREATE, user, project): return HttpResponseForbidden(_('Forbidden Access')) tags = utils.get_site_tags(project) users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MESSAGE_VIEW) if request.method == 'POST': form = MessageForm(users_to_notify, tags, request.POST) if form.is_valid(): msg = form.save(user, project) link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={ 'p_id': project.id, 'm_id': msg.id }), ) notification.send(msg.notify_to.all(), "message_new", { 'link_url': link_url, 'message': msg }) request.user.message_set.create(message=_("Message Created")) events_log(user, 'A', msg.title, msg) return HttpResponseRedirect( urlresolvers.reverse('rancho.message.views.list', args=[project.id])) else: form = MessageForm(users_to_notify, tags) context = { 'project': project, 'users_in_project': users_in_project, 'form': form } return render_to_response("message/new_message.html", context, context_instance=RequestContext(request))
def add_todo(request, p_id, todo_list): user = request.user project = get_object_or_404(Project, id = p_id) todo_list = get_object_or_404(ToDoList, id = todo_list) if not checkperm(PERMISSIONS_TODO_CREATE, user, project): return HttpResponseForbidden(_('Forbidden Access')) if request.method == 'GET': try: todo_desc = request.GET.get('todo_desc') todo_responsible = int(request.GET.get('todo_responsible')) except: return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id])) if not todo_desc: result = """<taconite> <show select="#empty_todo_error{{ todo_list }}"/> </taconite>""" result = loader.get_template_from_string(result).render(Context({'todo_list': todo_list.id})) return HttpResponse(result, mimetype='text/xml') if todo_responsible: todo_responsible = get_object_or_404(User, pk = todo_responsible) todo = ToDo() todo.creator = user if todo_responsible != 0: todo.responsible = todo_responsible todo.description = todo_desc todo.todo_list = todo_list todo.save() todo_list.number_of_todos+=1 todo_list.save() todo.position = todo_list.number_of_todos + 1 todo.save() events_log(user, 'A', todo.description, todo) #notify all users with perm link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.todo.views.view_todo_list', kwargs={'p_id': project.id, 'todo_list_id': todo_list.id}),) if todo.responsible: #just notify one person notification.send([todo.responsible], "todo_new", {'link_url': link_url, 'todo': todo, 'project': project, 'todo_list': todo_list}) else: #notify all users with perm users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_TODO_VIEW) notification.send(users_to_notify, "todo_new", {'link_url': link_url, 'todo': todo, 'project': project, 'todo_list': todo_list}) context = Context({'todo_list': todo_list.id, 'user': user, 'todo': todo, 'project': project}) result = loader.get_template('todo/add_todo.html').render(context) return HttpResponse(result, mimetype='text/xml')
def run_milestone_cron(): """ for each upcomming milestone send a menssage to its users remiding they are late """ DAYS = 2 for milestone in Milestone.objects.filter(sent_notification=False, due_date__range=(date.today(),date.today()+timedelta(DAYS))): milestone.sent_notification = True milestone.save() if milestone.send_notification_email: link_url = u"http://%s%s" % ( Site.objects.get_current(), urlresolvers.reverse('rancho.milestone.views.list', args = [milestone.project.id])) if milestone.responsible: #just notify one person notification.send([milestone.responsible], "milestone_datewarning", {'link_url': link_url, 'milestone': milestone }) else: #notify all users with perm users_to_notify = utils.get_users_to_notify(milestone.project, PERMISSIONS_MILESTONE_VIEW) notification.send(users_to_notify, "milestone_datewarning", {'link_url': link_url, 'milestone': milestone })
def create(request, p_id): user = request.user project = get_object_or_404(Project, id = p_id) users_in_project = project.get_users() if not checkperm(PERMISSIONS_MILESTONE_CREATE, user, project ): return HttpResponseForbidden(_('Forbidden Access')) users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MILESTONE_VIEW) if request.method == 'POST': form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_to_notify), request.POST) if form.is_valid(): mstone = form.save(user, project) if mstone.send_notification_email: #TODO: make a view milestone url to use here link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.milestone.views.list', args = [p_id])) #link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),) if mstone.responsible: #just notify one person notification.send([mstone.responsible], "milestone_new", {'link_url': link_url, 'milestone': mstone }) else: #notify all users with perm notification.send(users_to_notify, "milestone_new", {'link_url': link_url, 'milestone': mstone }) events_log(user, 'A', mstone.title, mstone) request.user.message_set.create(message=_('Milestone "%s" successfully created.') % mstone.title) return HttpResponseRedirect(urlresolvers.reverse('rancho.milestone.views.list', args = [p_id])) else: form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_in_project)) context = { 'project': project, 'newMilestone': form, } return render_to_response("milestone/create_milestone.html", context, context_instance=RequestContext(request))
def create(request,p_id): ''' Creates a new message ''' user = request.user project = get_object_or_404(Project, pk=p_id) project.check_user_in_project_or_404(user) users_in_project = project.get_users() if not checkperm(PERMISSIONS_MESSAGE_CREATE, user, project ): return HttpResponseForbidden(_('Forbidden Access')) tags = utils.get_site_tags(project) users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MESSAGE_VIEW) if request.method == 'POST': form = MessageForm(users_to_notify,tags, request.POST) if form.is_valid(): msg = form.save(user, project) link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),) notification.send(msg.notify_to.all(), "message_new", {'link_url': link_url, 'message': msg }) request.user.message_set.create(message=_("Message Created")) events_log(user, 'A', msg.title, msg) return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.list', args=[project.id])) else: form = MessageForm(users_to_notify, tags) context = {'project': project, 'users_in_project': users_in_project, 'form': form } return render_to_response("message/new_message.html", context, context_instance=RequestContext(request) )
def add_todo(request, p_id, todo_list): user = request.user project = get_object_or_404(Project, id=p_id) todo_list = get_object_or_404(ToDoList, id=todo_list) if not checkperm(PERMISSIONS_TODO_CREATE, user, project): return HttpResponseForbidden(_('Forbidden Access')) if request.method == 'GET': try: todo_desc = request.GET.get('todo_desc') todo_responsible = int(request.GET.get('todo_responsible')) except: return HttpResponseRedirect( urlresolvers.reverse('rancho.todo.views.list', args=[p_id])) if not todo_desc: result = """<taconite> <show select="#empty_todo_error{{ todo_list }}"/> </taconite>""" result = loader.get_template_from_string(result).render( Context({'todo_list': todo_list.id})) return HttpResponse(result, mimetype='text/xml') if todo_responsible: todo_responsible = get_object_or_404(User, pk=todo_responsible) todo = ToDo() todo.creator = user if todo_responsible != 0: todo.responsible = todo_responsible todo.description = todo_desc todo.todo_list = todo_list todo.save() todo_list.number_of_todos += 1 todo_list.save() todo.position = todo_list.number_of_todos + 1 todo.save() events_log(user, 'A', todo.description, todo) #notify all users with perm link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.todo.views.view_todo_list', kwargs={ 'p_id': project.id, 'todo_list_id': todo_list.id }), ) if todo.responsible: #just notify one person notification.send( [todo.responsible], "todo_new", { 'link_url': link_url, 'todo': todo, 'project': project, 'todo_list': todo_list }) else: #notify all users with perm users_to_notify = utils.get_users_to_notify( project, PERMISSIONS_TODO_VIEW) notification.send( users_to_notify, "todo_new", { 'link_url': link_url, 'todo': todo, 'project': project, 'todo_list': todo_list }) context = Context({ 'todo_list': todo_list.id, 'user': user, 'todo': todo, 'project': project }) result = loader.get_template('todo/add_todo.html').render(context) return HttpResponse(result, mimetype='text/xml')