def ticket_edit(request, project_slug=None, ticket_number=None): is_new = not ticket_number if is_new: ticket = Ticket() else: ticket = get_object_or_404(Ticket, number=ticket_number, project__slug=project_slug) images = ticket.attachments.filter(kind='image').order_by('created') files = ticket.attachments.exclude(kind='image').order_by('created') estimate = TicketEstimate.objects.filter(ticket=ticket) if is_new: initial_data = { 'project': request.GET.get('project'), 'fix_version': request.GET.get('version'), 'estimate': estimate and estimate[0].hours or '', } else: initial_data = { 'estimate': estimate and estimate[0].hours or '', } ticket_form = TicketForm(instance=ticket, initial=initial_data) def get_redirect_path(ticket): if not ticket.pk: return redirect('/') return request.POST.get('next') or\ redirect('carrot_ticket', project_slug=ticket.project.slug, ticket_number=ticket.number) if request.method == 'POST': if request.POST.get('action') == 'save': ticket_form = TicketForm(request.POST, files=request.FILES, instance=ticket) if ticket_form.is_valid(): ticket = ticket_form.save(commit=False) if not ticket.pk or not ticket.reporter: ticket.reporter = request.user ticket.save(user=request.user) if request.user.carrotprofile.role() == 'pm': if ticket_form.cleaned_data['estimate']: te = TicketEstimate.objects.get_or_create(ticket=ticket)[0] te.hours = int(ticket_form.cleaned_data['estimate']) te.save() if ticket_form.cleaned_data['file']: TicketAttachment.objects.create(ticket=ticket, file=ticket_form.cleaned_data['file']) return get_redirect_path(ticket) if request.POST.get('action', 'cancel') == 'cancel': return get_redirect_path(ticket) data = { 'new': is_new, 'ticket': ticket, 'files': files, 'images': images, 'ticket_form': ticket_form, 'all_versions': Version.objects.filter(is_completed=False).select_related(), } return TemplateResponse(request, 'carrot/tickets/ticket_edit.html', data)
cbt = cbt['ticket'] notes = codebase.ticket_notes(args[0], cbt['ticket_id']) options = { 'summary': cbt['summary'], 'kind': cbt['ticket_type'].lower(), 'number': cbt['ticket_id'] } if notes: options['description'] = '\n'.join(note['ticket_note']['content'] for note in notes) options.update(common_options) ticket = Ticket.objects.filter(**common_options).filter(summary=options['summary']) if len(ticket): ticket = ticket[0] else: ticket = Ticket() for k, v in options.items(): setattr(ticket, k, v) ticket.save() print ticket #login to download attach cookie_handler = urllib2.HTTPCookieProcessor() opener = urllib2.build_opener(cookie_handler) resp = opener.open(settings.CARROT_CODEBASE_LOGIN_URL, urllib.urlencode({'username': settings.CARROT_CODEBASE_LOGIN, 'password': settings.CARROT_CODEBASE_PASSWORD})) for note in notes: attach = note['ticket_note'].get('attachment', {})