Esempio n. 1
0
def index(request):
  if request.POST:
    issue = Issue()
    form = IssueForm(request.POST, instance=issue)
    if (form.is_valid()):
      #send issue to GitHub
      title = form.cleaned_data.get('title')
      body = form.cleaned_data.get('body')
      url = 'https://api.github.com/repos/mcdermott-scholars/mcdermott/issues'
      auth = (settings.GITHUB_USERNAME, settings.GITHUB_PASSWORD)
      data = {'title': title, 'body': body}
      r = requests.post(url, auth=auth, data=json.dumps(data))
      messages.add_message(
        request,
        messages.SUCCESS if r.status_code==201 else messages.ERROR,
        'Issue submitted' if r.status_code==201 else 'Error submitting issue',
      )
      return redirect(reverse('issues:index'))
    else:
      form = IssueForm(request.POST, instance=issue)
  else:
    form = IssueForm()
  context = {
    'form': form,
  }
  return render(request, 'issues/index.html', context)
Esempio n. 2
0
def issueCall():
    form = IssueForm()
    if not ('username' in session):
        return redirect(url_for('login'))

    problemsdb = mongo.db.problems
    existing_posts = problemsdb.find({}).sort('name')
    i = 0;
    list = []
    problem_id_array = []
    pair = (i, 'None')
    list.append(pair)
    problem_id_array.append('CodeFlask')
    for existing_post in existing_posts:
        i = i + 1
        pair1 = (i, existing_post['name'])
        list.append(pair1)
        problem_id_array.append(existing_post['myid'])

    form.problemName.choices = list

    if form.validate_on_submit():
        title = form.title.data
        problemName = form.problemName.data
        problemID = problem_id_array[problemName]
        print(problemID)
        text = form.text.data
        user_name = session['username']
        issueID = uuid.uuid1().__str__()

        issue = mongo.db.Issues
        issue.insert({'IssueID': issueID,
                      'UserName': user_name,
                      'Title': title,
                      'ProblemID': problemID,
                      'text': text,
                      'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
                      'commentNumber': 0})
        # return redirect(url_for('issues'))

    issue_array = []
    i = mongo.db.Issues
    issuelist = i.find({}).sort('date', -1)
    for issue in issuelist:
        if issue['ProblemID'] != 'CodeFlask':
            pb = problemsdb.find_one({'myid': issue['ProblemID']})
            issue_array.append(
                Issue(issue['IssueID'], issue['UserName'], issue['Title'], issue['ProblemID'], pb['name'],
                      issue['text'], issue['date'] , issue['commentNumber']))
        else:
            issue_array.append(
                Issue(issue['IssueID'], issue['UserName'], issue['Title'], issue['ProblemID'], 'CodeFlask',
                      issue['text'], issue['date'],issue['commentNumber']))

    return form,issue_array
Esempio n. 3
0
def raise_issue():
	form = IssueForm()
	if form.validate_on_submit():
		issue = Issue(subject=form.subject.data,
                    description=form.description.data,
                    priority=form.priority.data,
                    department_id=form.department.data,
                    user=current_user._get_current_object())
		db.session.add(issue)
		db.session.commit()
		return redirect(url_for('issues.view'))
	return render_template('issues/raise.html', form = form, title = "Raise Issue")
Esempio n. 4
0
def project_issue_new(slug):
	form = IssueForm()
	project = Project.query.filter_by(slug=slug).first_or_404()
	if form.validate_on_submit():
		issue = Issue(project, current_user, form.urgency.data,
						form.title.data, form.text.data)
		db.session.add(issue)
		db.session.commit()
		flash("Created issue <a href=\"%s\">#%s</a>" %
				(url_for('project_issue', slug=project.slug, iid=issue.id), issue.id))
		return redirect(url_for('project_issue_new', slug=slug))
	return render_template('issue_new.html', project=project, form=form)
Esempio n. 5
0
def raise_issue():
    form = IssueForm()
    if form.validate_on_submit():
        issue = Issue(subject=form.subject.data,
                      description=form.description.data,
                      priority=form.priority.data,
                      department_id=form.department.data,
                      user=current_user._get_current_object())
        db.session.add(issue)
        db.session.commit()
        return redirect(url_for('issues.view'))
    return render_template('issues/raise.html', form=form, title="Raise Issue")
Esempio n. 6
0
def create_issue(request, employee, tab):
    issue_form = IssueForm
    if request.method == 'POST':
        issue_form = IssueForm(employee, False, data=request.POST)
        if issue_form.is_valid():
            issue_form.save()
            return redirect('/management/manage_issues')

    return render(request, 'management/create_issue.html', {
        'issue_form': issue_form,
        'models': IssueForm,
        'tab': tab,
    })
Esempio n. 7
0
def edit(id):
	issue = Issue.query.get_or_404(id)
	if current_user.id != issue.user_id:
		abort(403)
	form = IssueForm(obj=issue)
	if form.validate_on_submit():
		issue.subject = form.subject.data
		issue.description = form.description.data
		issue.priority = form.priority.data
		issue.department_id = form.department.data
		issue.user=current_user._get_current_object()
		db.session.add(issue)
		db.session.commit()
		return redirect(url_for('issues.view'))
	form.description.data = issue.description
	form.subject.data = issue.subject
	return render_template('issues/edit.html', form=form, title="Edit Issue")
Esempio n. 8
0
def edit(id):
    issue = Issue.query.get_or_404(id)
    if current_user.id != issue.user_id:
        abort(403)
    form = IssueForm(obj=issue)
    if form.validate_on_submit():
        issue.subject = form.subject.data
        issue.description = form.description.data
        issue.priority = form.priority.data
        issue.department_id = form.department.data
        issue.user = current_user._get_current_object()
        db.session.add(issue)
        db.session.commit()
        return redirect(url_for('issues.view'))
    form.description.data = issue.description
    form.subject.data = issue.subject
    return render_template('issues/edit.html', form=form, title="Edit Issue")
Esempio n. 9
0
def index(request):
    if request.POST:
        issue = Issue()
        form = IssueForm(request.POST, instance=issue)
        if (form.is_valid()):
            #send issue to GitHub
            title = form.cleaned_data.get('title')
            body = form.cleaned_data.get('body')
            url = 'https://api.github.com/repos/mcdermott-scholars/mcdermott/issues'
            auth = (settings.GITHUB_USERNAME, settings.GITHUB_PASSWORD)
            data = {'title': title, 'body': body}
            r = requests.post(url, auth=auth, data=json.dumps(data))
            messages.add_message(
                request,
                messages.SUCCESS if r.status_code == 201 else messages.ERROR,
                'Issue submitted'
                if r.status_code == 201 else 'Error submitting issue',
            )
            return redirect(reverse('issues:index'))
        else:
            form = IssueForm(request.POST, instance=issue)
    else:
        form = IssueForm()
    context = {
        'form': form,
    }
    return render(request, 'issues/index.html', context)
Esempio n. 10
0
def view_project(id):
    project = Project.query.get_or_404(id)

    form = IssueForm()
    feedback_form = FeedbackForm()
    predictions = []
    model_path = os.path.join(app.config['MODEL_FOLDER'], '%s/svm.pkl' % id)
    trained = project.train_status != TS.NOT_TRAINED \
        and os.path.isfile(model_path)
    summary_or_description = form.summary.data or form.description.data

    if trained and form.validate_on_submit() and summary_or_description:
        issue = Document(form.summary.data, form.description.data)
        model = joblib.load(model_path)
        try:
            predictions = model.predict(issue, n=10)
        except ValueError:
            flash(
                "There is too little information provided. "
                "You need to add more text to the description or summary.",
                "error")

        feedback_form.summary.data = form.summary.data
        feedback_form.description.data = form.description.data
        existing_feedback = Feedback.query.get(
            Feedback.get_id_from_doc(issue, project=project))
        if existing_feedback:
            feedback_form.confirmed_recommendation.data = \
                existing_feedback.confirmed_recommendation

    if request.method == "POST" and not summary_or_description:
        err_msg = "Summary or description must not be empty."
        form.summary.errors.append(err_msg)
        form.description.errors.append(err_msg)

    fscore = tests.fscore(project.precision, project.recall)
    return render_template("project/view.html",
                           project=project,
                           fscore=fscore,
                           form=form,
                           predictions=predictions,
                           trained=trained,
                           feedback_form=feedback_form)
Esempio n. 11
0
def edit_issue(request, issue_id):
    if request.method == 'POST':
        form = IssueForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            issue = Issue(pk=issue_id)
            issue.save_edited(cd, request.user)
            return HttpResponseRedirect("/" + str(issue.id))
    else:
        issue = Issue.objects.filter(id=issue_id,
                                   author=request.user).exclude(status='deleted')[0]
        form = IssueForm(
            initial={'label': issue.label,
                     'text': issue.text,
                     'expiration': issue.expiration}
        )
        form.fields['receiver'].queryset = User.objects.exclude(id=request.user.id)
        if issue.receiver:
            is_common = False
            receivers = issue.receiver.all()
            form.fields['receiver'].initial = receivers
        else:
            is_common = True
        comments = comments_gettext_loop(Comment.objects.filter(issue=issue).order_by('date'))
        if issue.expiration:
            # Probably, we can do it in template
            expiration_time = str(issue.expiration.time().hour) + ":" + \
                              str(issue.expiration.time().minute)
            expiration_date = issue.expiration.date().isoformat()
        else:
            expiration_date = expiration_time = None
        counter = count_issues(request)
        return render_to_response('edit_issue.html', {'form': form,
                                                      'receivers': receivers,
                                                      'user': request.user,
                                                     'is_common': is_common,
                                                     'expiration_date': expiration_date,
                                                     'expiration_time': expiration_time,
                                                     'comments': comments,
                                                     'counter': counter,
                                                     'issue_id': issue.id,
                                                     'tomorrow': get_tomorrow()})
Esempio n. 12
0
def projects_childissue(num):
    base_issue = Issue.objects(number=num)[0]
    project = Project.objects(id=base_issue.project_id)[0]
    issue = Issue()
    form = IssueForm(request.form, issue)
    if form.validate_on_submit():
        form.populate_obj(issue)
        counter = Counter.objects(id_for="issue")[0]
        counter.set_next_id()
        counter.save()
        issue.number = counter.number
        issue.author = session['user_id']
        issue.base_issue = num
        issue.save()
        return redirect('projects/issues/' + str(num))
    return render_template('projects_childissue.html',
                           project=project,
                           base_issue=base_issue,
                           issue=issue,
                           form=form)
Esempio n. 13
0
def project_show(num):
    project = Project.objects(number=num)[0]
    issues = Issue.objects(project_id=str(project.id))
    for issue in issues:
        issue.comments_count = len(issue.comments)
    issue = Issue()
    form = IssueForm(request.form, issue)
    if form.validate_on_submit():
        counter = Counter.objects(id_for="issue")[0]
        counter.set_next_id()
        counter.save()
        form.populate_obj(issue)
        issue.number = counter.number
        issue.author = session['user_id']
        issue.save()
        return redirect('/projects/' + str(project.number))
    return render_template('projects_show.html',
                           project=project,
                           issues=issues,
                           form=form)
Esempio n. 14
0
def projects_childissue(num):
    base_issue = Issue.objects(number=num)[0]
    project = Project.objects(id=base_issue.project_id)[0]
    issue = Issue()
    form = IssueForm(request.form, issue)
    if form.validate_on_submit():
        form.populate_obj(issue)
        counter = Counter.objects(id_for="issue")[0]
        counter.set_next_id()
        counter.save()
        issue.number = counter.number
        issue.author = session['user_id']
        issue.base_issue = num
        issue.save()
        return redirect('projects/issues/' + str(num))
    return render_template('projects_childissue.html',
                            project=project,
                            base_issue=base_issue,
                            issue=issue,
                            form=form)
Esempio n. 15
0
def project_show(num):
    project = Project.objects(number=num)[0]
    issues = Issue.objects(project_id=str(project.id))
    for issue in issues:
        issue.comments_count = len(issue.comments)
    issue = Issue()
    form = IssueForm(request.form, issue)
    if form.validate_on_submit():
        counter = Counter.objects(id_for="issue")[0]
        counter.set_next_id()
        counter.save()
        form.populate_obj(issue)
        issue.number = counter.number
        issue.author = session['user_id']
        issue.save()
        return redirect('/projects/' + str(project.number))
    return render_template('projects_show.html',
                           project=project,
                           issues=issues,
                           form=form)
Esempio n. 16
0
def new_issue(request):
    current_user = request.user
    context = {}
    contact_form = ContactForm()

    if request.method == 'POST' and ('new_issue' in request.POST or 'continue_editing' in request.POST):
        form = IssueForm(request.POST)
        if form.is_valid():
            if 'continue_editing' in request.POST:
                return save_issue(form, current_user, continue_editing=True)
            return save_issue(form, current_user)

    elif request.method == 'POST' and 'new_contact' in request.POST:
        contact_form = ContactForm(request.POST)     
        if contact_form.is_valid():
            curr_region = get_object_or_404(Region, pk=contact_form['region'].value())
            contact = contact_form.save(commit=False)
            contact.region = curr_region
            contact.save()
            contact_form = ContactForm()
            submitted_data = request.POST.copy()
            submitted_data['contact'] = contact.id
            form = IssueForm(submitted_data)
            context['created_contact'] = contact
        else:
            form = IssueForm(request.POST)

    else:
        initial_data = {'opened': date.today(),
                        'control': date.today() + timedelta(days=7),
                        'assignee': current_user.id,
                        'project': 1,
                        'service_type': 4,
                        'status': 1,
                        'priority': 3,
                        'formed': False}
        form = IssueForm(initial=initial_data)

    context['form'] = form
    context['contact_form'] = contact_form
    return render(request, 'helpdesk/new_issue.html', context)
Esempio n. 17
0
def edit_issue(request, issue_id):
    current_issue = get_object_or_404(Issue, pk=issue_id)
    contact_form = ContactForm()
    form = IssueForm(instance=current_issue)

    if request.method == 'POST' and ('new_issue' in request.POST or 'continue_editing' in request.POST):
        current_assignee = current_issue.assignee
        form = IssueForm(request.POST or None, instance=current_issue)
        if form.is_valid():
            form.save()
            if current_assignee != current_issue.assignee:
                issue_assign.delay(current_issue)
            if 'continue_editing' in request.POST:
                return HttpResponseRedirect(reverse('helpdesk:edit_issue', args=[current_issue.id]))
            return HttpResponseRedirect(reverse('helpdesk:issue', args=[current_issue.id]))

    elif request.method == 'POST' and 'new_contact' in request.POST:
        contact_form = ContactForm(request.POST)
        if contact_form.is_valid():
            new_contact = contact_form.save(commit=False)
            new_contact.region = current_issue.region
            new_contact.save()
            contact_form = ContactForm()
            current_issue.contact = new_contact
            current_issue.save()
            form = IssueForm(instance=current_issue)

    return render(request, 'helpdesk/new_issue.html', {'form': form,
                                                       'current_issue': current_issue,
                                                       'contact_form': contact_form})
Esempio n. 18
0
def issues_edit(request, instance_pk=None):
    if instance_pk is not None:
        instance = get_object_or_404(Issue, pk=instance_pk)
    else:
        instance = None
    
    if request.method == 'POST':
        form = IssueForm(request.POST, instance=instance)
        if form.is_valid():
            issue = form.save(commit=False)
            issue.user = request.user
            issue.save()
            #
            form.save_m2m()
            # return a message
            messages.success(request, 'Issue Created')
            # return a redirect
            return HttpResponseRedirect(reverse('journals:journal_today'))
    
    if request.method == 'GET':
        form = IssueForm(instance=instance)
    
    return render_to_response('journals/issues_edit.html', RequestContext(request,{
        'form' : form,
        'instance' : instance,
    }))
Esempio n. 19
0
def view_project(id):
    project = Project.query.get_or_404(id)

    form = IssueForm()
    feedback_form = FeedbackForm()
    predictions = []
    model_path = os.path.join(app.config['MODEL_FOLDER'], '%s/svm.pkl' % id)
    trained = project.train_status != TS.NOT_TRAINED \
        and os.path.isfile(model_path)
    summary_or_description = form.summary.data or form.description.data

    if trained and form.validate_on_submit() and summary_or_description:
        issue = Document(form.summary.data, form.description.data)
        model = joblib.load(model_path)
        try:
            predictions = model.predict(issue, n=10)
        except ValueError:
            flash("There is too little information provided. "
                  "You need to add more text to the description or summary.",
                  "error")

        feedback_form.summary.data = form.summary.data
        feedback_form.description.data = form.description.data
        existing_feedback = Feedback.query.get(
            Feedback.get_id_from_doc(issue, project=project))
        if existing_feedback:
            feedback_form.confirmed_recommendation.data = \
                existing_feedback.confirmed_recommendation

    if request.method == "POST" and not summary_or_description:
        err_msg = "Summary or description must not be empty."
        form.summary.errors.append(err_msg)
        form.description.errors.append(err_msg)

    fscore = tests.fscore(project.precision, project.recall)
    return render_template("project/view.html", project=project, fscore=fscore,
                           form=form, predictions=predictions, trained=trained,
                           feedback_form=feedback_form)
Esempio n. 20
0
def index(request, fltr='all', add_task=None):
    counter = count_issues(request)
    # filter issues according to status
    issues = filter_issues(fltr, request.user)
    if request.method == 'POST':
        form = IssueForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            issue = Issue()
            issue.add(cd, request.user)
            return HttpResponseRedirect("/")
    else:
        form = IssueForm()
        form.fields['receiver'].queryset = User.objects.exclude(
            id=request.user.id)
    return render_to_response('index.html',
                              {'issues': issues,
                               'form': form,
                               'user': request.user,
                               'tomorrow': get_tomorrow(),
                               'counter': counter,
                               'page_type': 'index',
                               'add_task': add_task}
    )
Esempio n. 21
0
def manageissue(request,issueid=None):
    if request.method == "POST":
        form = IssueForm(request.POST)
        if form.is_valid():

            if issueid is None:
                issue = form.save(commit=False)
                issue.owner = request.user
                issue.save()
            else:
		if Issue.objects.filter(id=int(issueid), owner = request.user).exists():
                    issue = form.save(commit=False)
                    issue.owner = request.user
		    issue.id = issueid
                    issue.save(force_update=True)
                    IssueItem.objects.filter(issueid=issue.id).delete()
            
                else:
                    return HttpResponseForbidden("You do not have permission to edit this Issue.")

            for i, val in enumerate(request.REQUEST.getlist("item-title")) :
        
                if IssueItem.objects.filter(issueid=issue.id, url=request.REQUEST.getlist("item-url")[i]).count() > 0:
                    item = IssueItem.objects.filter(issueid=issue.id, url=request.REQUEST.getlist("item-url")[i])[0]
                else:
                    item = IssueItem.objects.create(issueid=issue.id)

                item.url = request.REQUEST.getlist("item-url")[i]
                item.title = request.REQUEST.getlist("item-title")[i]
                item.description = request.REQUEST.getlist("item-description")[i]
                item.img = request.REQUEST.getlist("item-img")[i]
                item.ordernumber = i;
                item.save()

            return HttpResponseRedirect('/issuelist/')

    elif request.method == 'DELETE':
        issue = get_object_or_404( Issue, id=int(issueid) )

        if issue.owner != request.user:
            return HttpResponseForbidden("You do not have permission to edit this Issue.")

        else:
            issue.delete()
            return HttpResponseRedirect('/issuelist/')
    else:
        if issueid is None:
            form = IssueForm()
        else:
            issue = Issue.objects.get(id=issueid, owner=request.user)

            form = IssueForm(instance=issue)

    return render_to_response('manageissue.html', {'form': form, 'issueid': issueid}, context_instance=RequestContext(request))
Esempio n. 22
0
def add_edit_issue(request, *args, **kwargs):
    """Adds/Edits issues"""
    
    project_name = kwargs['project_name']
    project = get_object_or_404(CollabProject, slug=project_name)
    project_id = project.id
    
    issueset_id = kwargs['issueset_id']
    issueset = get_object_or_404(IssueSet, id__exact=issueset_id)

    if not is_allowed(request,  project_id,  Issue._meta.verbose_name,  'Editable'):
        return handle_privilege(request, "You do not have privileges to edit issues!", issueset.get_absolute_url())

    if 'issue_id' in kwargs:
        issue_id = kwargs['issue_id']
        issue = get_object_or_404(Issue, id=issue_id)
        # Check if the issue exists in that project AND issue set!
        if issue.issueset.project.id != project.id or issue.issueset.id != issueset.id:
            return handle_privilege(request, "The issue does not match the project or issue list!", project.get_absolute_url())
        edit = True
        instance=issue
    else:
        edit = False
        instance=None

    if request.method == 'POST':
        form = IssueForm(request.POST, instance=instance, issueset=issueset)
        if form.is_valid():
            if not edit:
                issue = Issue()
                message = "The issue was added."
            else:
                message = "The issue was modified."
            issue = form.save(commit=False)
            
            if not edit:
                issue.reporter = request.user

#            issue.issueset = issueset
            issue.save()
            request.user.message_set.create(message=message)
            return HttpResponseRedirect(issue.get_absolute_url())
    else:
        form = IssueForm(initial={'issueset': issueset.pk},  instance=instance, issueset=issueset)
    return render_to_response('issues/add_edit_issue.html', {'form': form,  'edit': edit,  'project': project, 'issueset': issueset, 'issue': instance}, context_instance=RequestContext(request))
Esempio n. 23
0
def edit_issue(request, employee, tab, issue_id):
    issue = Issue.objects.get(id=issue_id)
    if issue.current == None:
        issue_form = IssueForm(employee=employee, edit=True, instance=issue, initial={'assigned_to': None})
    else:
        issue_form = IssueForm(employee=employee, edit=True, instance=issue, initial={'assigned_to': issue.current.worker})

    #if we have already posted
    if request.method == 'POST':
        issue_form = IssueForm(employee, True, request.POST, instance=issue)
        if issue_form.is_valid():
            issue_form.save();
            return redirect('/management/manage_issues')
    return render(request, 'management/edit_issue.html', {
        'issue': issue,
        'issue_id': issue_id,
        'issue_form': issue_form,
        'tab': tab
    })