def save_issue(request): requester = models.Ti_user.objects.get(id=request.user.id) title = request.POST.get('title') description = request.POST.get('description') severity = request.POST.get('severity') department = models.Department.objects.get(department_name=request.POST.get('department')) issue = Issue(title = title, description = description, requester = requester, assigned_group = department, Severity = severity) issue.save() print issue.id comments = models.Comment.objects.filter(issue_id=issue.id).order_by('-created_time') return HttpResponseRedirect('/issue/%s' %issue.id)
def test_issue_creation(self): c = Category.objects.all()[0] i = Issue(summary="Test", description="Test", reporter_name="User", reporter_email="*****@*****.**", urgent=True, category=c) i.save() iid = i.id i = Issue.objects.get(id=iid) self.failUnlessEqual(i.summary, "Test")
def reconcile_db_with_gh(*args, **kwargs): ghc = GitHubConnector() issues = ghc.get_all_issues() repos = ghc.get_all_repos() for repo in repos: r = Repo(github_id=repo.id, name=repo.name) r.save() for issue in issues: i = Issue(github_id=issue.id) i.title = issue.title i.number = issue.number i.repo = Repo.objects.get(name=issue.repository[1]) i.save() print "Not only did your task run successfully, but you're damned good looking too."
def paynow(request): languages = [] for lang in Issue.LANGUAGES: languages.append(lang[0]) issuetracker = request.POST.get('issuetracker') issueurl = request.POST.get('issueUrl') issuetitle = request.POST.get('title') issuesummary = request.POST.get('summary') language = request.POST.get('language') bounty = request.POST.get('bounty') message = '' if not bounty: message = "Bounty is required." if not issuesummary: message = "Summary is required." if not issuetitle: message = "Title is required." if not issueurl: message = "Issue URL is required." if not message: userprofile = UserProfile() issuesaver = Issue() issuesaver.title = issuetitle issuesaver.content = issuesummary issuesaver.language = language issuesaver.notified_user = False issuesaver.status = "open" issuesaver.user = request.user issuesaver.save() bountysaver = Bounty() bountysaver.price = bounty bountysaver.issue = issuesaver bountysaver.user = request.user bountysaver.save() return render(request, 'post.html', { 'languages': languages, 'message': 'Successfully registered on DB.' }) else: return render(request, 'post.html', { 'languages': languages, 'message': message })
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))
def add_issue_to_database(request): issue = request.session.get('issue', False) service = Service.objects.get(name=issue['service']) try: db_issue = Issue.objects.get(service=service, number=issue['number'], project=issue['project']) if db_issue.status == "paid": error = "I see that issue has been closed and paid already." messages.error(request, error) return False except: db_issue = Issue(service=service, number=issue['number'], project=issue['project'], user=issue.has_key('user') and issue['user'] or '', title=issue['title'], content=issue['content'][:350], status=issue['status']) filename, file = get_image_for_issue(service, issue) if filename: db_issue.image.save(filename, file) db_issue.save() if not settings.DEBUG: create_comment(db_issue) ends = issue['limit'] hour_day = ends[-1] number = ends.rstrip(hour_day) if hour_day == "h": limit = datetime.timedelta(hours=int(number)) else: limit = datetime.timedelta(days=int(number)) bounty = Bounty(user=request.user, issue=db_issue, price=issue['bounty'], ends=datetime.datetime.now() + limit) bounty.save() alert_watchers_increase(db_issue, int(request.GET.get('bounty', 0))) del request.session['issue'] return True
def create_new(board, issue, user): saved = Issue() saved.board = board saved.repository = issue['repository'] saved.issueid = str(issue['number']) saved.title = str(issue['title'].encode('utf-8')) saved.url = "https://github.com/" + issue['repository'] + "/issues/" + str( issue['number']) saved.created = issue['created_at'].split("T")[0] saved.updated = issue['updated_at'].split("T")[0] if "assignee" not in issue or not issue["assignee"]: saved.assigned = "None" else: print issue['assignee'] saved.assigned = issue['assignee']['login'] saved.status = issue['state'] saved.changed = False saved.release = "New" saved.comments = "None" saved.save()
def add_issue_to_database(request): issue = request.session.get('issue', False) service = Service.objects.get(name=issue['service']) try: db_issue = Issue.objects.get(service=service, number=issue['number'], project=issue['project']) if db_issue.status == "paid": error = "I see that issue has been closed and paid already." messages.error(request, error) return False except: db_issue = Issue( service=service, number=issue['number'], project=issue['project'], user=issue.has_key('user') and issue['user'] or '', title=issue['title'], content=issue['content'][:350], status = issue['status']) filename, file = get_image_for_issue(service, issue) if filename: db_issue.image.save(filename, file) db_issue.save() if not settings.DEBUG: create_comment(db_issue) ends = issue['limit'] hour_day = ends[-1] number = ends.rstrip(hour_day) if hour_day == "h": limit = datetime.timedelta(hours=int(number)) else: limit = datetime.timedelta(days=int(number)) bounty = Bounty(user=request.user, issue=db_issue, price=issue['bounty'], ends=datetime.datetime.now()+limit ) bounty.save() alert_watchers_increase(db_issue, int(request.GET.get('bounty', 0))) del request.session['issue'] return True
def test_m2m_and_m2o(self): r = User.objects.create(username="******") g = User.objects.create(username="******") i1 = Issue(num=1) i1.client = r i1.save() i2 = Issue(num=2) i2.client = r i2.save() i2.cc.add(r) i3 = Issue(num=3) i3.client = g i3.save() i3.cc.add(r) self.assertQuerysetEqual(Issue.objects.filter(client=r.id), [ 1, 2, ], lambda i: i.num) self.assertQuerysetEqual(Issue.objects.filter(client=g.id), [ 3, ], lambda i: i.num) self.assertQuerysetEqual(Issue.objects.filter(cc__id__exact=g.id), []) self.assertQuerysetEqual(Issue.objects.filter(cc__id__exact=r.id), [ 2, 3, ], lambda i: i.num) # These queries combine results from the m2m and the m2o relationships. # They're three ways of saying the same thing. self.assertQuerysetEqual( Issue.objects.filter(Q(cc__id__exact=r.id) | Q(client=r.id)), [ 1, 2, 3, ], lambda i: i.num) self.assertQuerysetEqual( Issue.objects.filter(cc__id__exact=r.id) | Issue.objects.filter(client=r.id), [ 1, 2, 3, ], lambda i: i.num) self.assertQuerysetEqual( Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)), [ 1, 2, 3, ], lambda i: i.num)
def test_m2m_and_m2o(self): r = User.objects.create(username="******") g = User.objects.create(username="******") i1 = Issue(num=1) i1.client = r i1.save() i2 = Issue(num=2) i2.client = r i2.save() i2.cc.add(r) i3 = Issue(num=3) i3.client = g i3.save() i3.cc.add(r) self.assertQuerysetEqual( Issue.objects.filter(client=r.id), [ 1, 2, ], lambda i: i.num ) self.assertQuerysetEqual( Issue.objects.filter(client=g.id), [ 3, ], lambda i: i.num ) self.assertQuerysetEqual( Issue.objects.filter(cc__id__exact=g.id), [] ) self.assertQuerysetEqual( Issue.objects.filter(cc__id__exact=r.id), [ 2, 3, ], lambda i: i.num ) # These queries combine results from the m2m and the m2o relationships. # They're three ways of saying the same thing. self.assertQuerysetEqual( Issue.objects.filter(Q(cc__id__exact = r.id) | Q(client=r.id)), [ 1, 2, 3, ], lambda i: i.num ) self.assertQuerysetEqual( Issue.objects.filter(cc__id__exact=r.id) | Issue.objects.filter(client=r.id), [ 1, 2, 3, ], lambda i: i.num ) self.assertQuerysetEqual( Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)), [ 1, 2, 3, ], lambda i: i.num )
def get_taiga_status(request, nomeProjeto): try: # Linka o projeto do Taiga com o projeto Knowleds projeto_knowleds = ProjetoKnowLeds.objects.get(nome_webhook=nomeProjeto) except: pass if request.method == 'POST': print ('POST') r = json.load(request) if r['action'] == 'create' : # Se for SPRINT if r['type'] == 'milestone': projeto = projeto_save(r['data']['project'], projeto_knowleds) sprint_save(r['data'], projeto) # Se for USER HISTORY elif r['type'] == 'userstory': projeto = projeto_save(r['data']['project'], projeto_knowleds) print('ALGO MUDOU: ' + str(r)) userstory_save(r['data'],projeto) # Se for TASK elif r['type'] == 'task': projeto = projeto_save( r['data']['project'], projeto_knowleds) userStory = userstory_save(r['data']['user_story'], projeto) task = Task() # Atributos para salvar task.ident = r['data']['id'] task.titulo = r['data']['subject'] task.descricao = r['data']['description'] task.userStory = userStory task.tags = r['data']['tags'] task.is_closed = r['data']['status']['is_closed'] try: ##identificar qual user task.user = r['data']['assigned_to']['username'] except: pass textoTag = task.titulo + ' precisa de ajuda, voce sabe a solucao' for tag in task.getTags(): if tag == 'ajuda' or tag == 'Ajuda' or tag == 'AJUDA': print('Mandando o email...') send_mail('Ajuda em UserStory', textoTag, '*****@*****.**', ['*****@*****.**'], fail_silently=False) task.save() # Se for ISSUE elif r['type'] == 'issue': projeto = projeto_save(r['data']['project'], projeto_knowleds) issue = Issue() # Atributos para salvar issue.ident = r['data']['id'] issue.titulo = r['data']['subject'] issue.descricao = r['data']['description'] issue.setTags(r['data']['tags']) issue.is_closed = r['data']['status']['is_closed'] issue.projeto = projeto issue.save() textoTag = issue.titulo + ' precisa de ajuda, voce sabe a solucao' for tag in issue.getTags(): if tag == 'ajuda' or tag == 'Ajuda' or tag == 'AJUDA': print('Mandando o email...') send_mail('Ajuda em UserStory', textoTag, '*****@*****.**', ['*****@*****.**'], fail_silently=False) elif r['action'] == 'change': # Se for USER HISTORY if r['type'] == 'userstory': projeto = projeto_save(r['data']['project'], projeto_knowleds) userstory_save(r['data'],projeto) # Se for TASK elif r['type'] == 'task': if Task.objects.filter(ident=r['data']['id']): task = Task.objects.filter(ident=r['data']['id'])[0] else: task = Task() projeto = projeto_save( r['data']['project'], projeto_knowleds) userStory = userstory_save(r['data']['user_story'], projeto) print("\n\nOlha aqui o user story: " + str(userStory)) # Atributos para salvar task.ident = r['data']['id'] task.titulo = r['data']['subject'] task.descricao = r['data']['description'] task.userStory = userStory task.tags = r['data']['tags'] task.is_closed = r['data']['status']['is_closed'] try: ##identificar qual user task.user = r['data']['assigned_to']['username'] except: pass task.save() """ texto = '' for t in Task.objects.all().filter(sprint_id=r['data']['milestone']['id']): texto += 'Tarefa: ' + t.titulo + ': \n' + 'Descricao: '+ t.descricao + '\n \n \n' # Se a tarefa encerrar o Sprint entra aqui # para ENVIAR o EMAIL email = Projeto.objects.get(nomeFantasia = 'Teste').email print('Olha como esta o status: ' + str(r['data']['milestone']['closed'])) if r['data']['milestone']['closed']: sprint = 'O Sprint: ' + r['data']['milestone']['name'] + ' foi encerrado' send_mail(sprint, texto, '[email protected], [email protected],', [email], fail_silently=False) textoTag = task.titulo + ' precisa de ajuda, voce sabe a solucao' for tag in task.getTags(): if tag == 'ajuda' or tag == 'Ajuda' or tag == 'AJUDA': print('Mandando o email...') send_mail('Ajuda em UserStory', textoTag, '*****@*****.**', ['*****@*****.**'], fail_silently=False) """ # Se for ISSUE elif r['type'] == 'issue': projeto = projeto_save(r['data']['project'], projeto_knowleds) try: issue = Issue.objects.get(ident=r['data']['id']) except: issue = Issue() pass issue.ident = r['data']['id'] issue.titulo = r['data']['subject'] issue.descricao = r['data']['description'] issue.setTags(r['data']['tags']) issue.is_closed = r['data']['status']['is_closed'] issue.projeto = projeto issue.save() textoTag = issue.titulo + ' precisa de ajuda, voce sabe a solucao' for tag in issue.getTags(): if tag == 'ajuda' or tag == 'Ajuda' or tag == 'AJUDA': print('Mandando o email...') send_mail('Ajuda em UserStory', textoTag, '*****@*****.**', ['*****@*****.**'], fail_silently=False) #Se for SPRINT elif r['type'] == 'milestone': projeto = projeto_save(r['data']['project'], projeto_knowleds) sprint_save(r['data'], projeto) return Response("POST", status=status.HTTP_201_CREATED) elif request.method == 'GET': return Response("GET")
def update_issues(): """Fetch a list of "recent" petitions on Althingi and update our database accordingly. """ session_num = get_last_session_num() session, created = Session.objects.get_or_create(session_num=session_num) if created: print 'Added session: %s' % session_num else: print 'Already have session: %s' % session_num issue_list_xml = minidom.parse(urllib.urlopen(ISSUE_LIST_URL % session_num)) issues_xml = issue_list_xml.getElementsByTagName(u'mál') for issue_xml in issues_xml: name = issue_xml.getElementsByTagName(u'málsheiti')[0].firstChild.nodeValue description = issue_xml.getElementsByTagName(u'efnisgreining')[0].firstChild description = description.nodeValue if description != None else 'engin lýsing útgefin' issue_type = issue_xml.getElementsByTagName(u'málstegund')[0].getAttribute(u'málstegund') issue_num = int(issue_xml.getAttribute(u'málsnúmer')) issue_try = Issue.objects.filter(issue_num=issue_num, session=session) if issue_try.count() > 0: issue = issue_try[0] print 'Already have issue: %s' % issue else: issue = Issue() issue.issue_num = issue_num issue.issue_type = issue_type issue.name = name issue.description = description issue.session = session issue.save() print 'Added issue: %s' % issue # Import the issue's documents. issue_xml = minidom.parse(urllib.urlopen(ISSUE_URL % (session_num, issue.issue_num))) docs_xml = issue_xml.getElementsByTagName(u'þingskjöl')[0].getElementsByTagName(u'þingskjal') lowest_doc_num = 0 # Lowest document number will always be the main document of the issue. for doc_xml in docs_xml: # Make sure that this is indeed the correct issue. if int(doc_xml.getAttribute(u'málsnúmer')) != issue.issue_num or int(doc_xml.getAttribute(u'þingnúmer')) != session_num: continue doc_num = int(doc_xml.getAttribute(u'skjalsnúmer')) doc_type = doc_xml.getElementsByTagName(u'skjalategund')[0].firstChild.nodeValue time_published = doc_xml.getElementsByTagName(u'útbýting')[0].firstChild.nodeValue + "+00:00" paths_xml = doc_xml.getElementsByTagName(u'slóð') html_paths_xml = paths_xml[0].getElementsByTagName(u'html') pdf_paths_xml = paths_xml[0].getElementsByTagName(u'pdf') if len(html_paths_xml) == 0: print 'Document not published: %d' % doc_num continue path_html = html_paths_xml[0].firstChild.nodeValue path_pdf = pdf_paths_xml[0].firstChild.nodeValue if lowest_doc_num == 0: lowest_doc_num = doc_num elif lowest_doc_num > doc_num: lowest_doc_num = doc_num doc_try = Document.objects.filter(doc_num=doc_num, issue=issue) if doc_try.count() > 0: doc = doc_try[0] print 'Already have document: %s' % doc else: doc = Document() doc.doc_num = doc_num doc.doc_type = doc_type doc.time_published = time_published doc.path_html = path_html doc.path_pdf = path_pdf doc.issue = issue doc.save() print '- Added document: %s' % doc if lowest_doc_num == 0: issue.delete() print '- Has no documents, being removed' continue main_doc = Document.objects.get(issue=issue, doc_num=lowest_doc_num) main_doc.is_main = True main_doc.save() print '- Main document determined to be: %s' % main_doc