Python django.core.urlresolvers.reverse() Examples

The following are 30 code examples for showing how to use django.core.urlresolvers.reverse(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.core.urlresolvers , or try the search function .

Example 1
Project: Servo   Author: fpsw   File: order.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def close(request, pk):
    """Close this Service Order."""
    order = get_object_or_404(Order, pk=pk)

    if request.method == 'POST':
        try:
            order.close(request.user)
        except Exception as e:
            messages.error(request, e)
            return redirect(order)

        if request.session.get("current_order_id"):
            del(request.session['current_order_id'])
            del(request.session['current_order_code'])
            del(request.session['current_order_customer'])

        messages.success(request, _('Order %s closed') % order.code)

        return redirect(order)

    data = {'order': order, 'action': reverse(close, args=[pk])}
    return render(request, "orders/close.html", data) 
Example 2
Project: Servo   Author: fpsw   File: order.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def accessories(request, pk, device_id):
    from django.utils import safestring

    if request.POST.get('name'):
        a = Accessory(name=request.POST['name'])
        a.order_id = pk
        a.device_id = device_id
        a.save()

    choice_list = []
    choices = Accessory.objects.distinct('name')

    for c in choices:
        choice_list.append(c.name)

    action = reverse('orders-accessories', args=[pk, device_id])
    selected = Accessory.objects.filter(order_id=pk, device_id=device_id)
    choices_json = safestring.mark_safe(json.dumps(choice_list))

    return render(request, 'devices/accessories_edit.html', locals()) 
Example 3
Project: Servo   Author: fpsw   File: notes.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(NoteForm, self).__init__(*args, **kwargs)
        note = kwargs['instance']
        self.fields['sender'] = forms.ChoiceField(
            label=_('From'),
            choices=note.get_sender_choices(),
            widget=forms.Select(attrs={'class': 'span12'})
        )

        self.fields['body'].widget = AutocompleteTextarea(
            rows=20,
            choices=Template.templates()
        )

        if note.order:
            url = reverse('notes-render_template', args=[note.order.pk])
            self.fields['body'].widget.attrs['data-url'] = url 
Example 4
Project: OpenMDM   Author: OpenMDM   File: views.py    License: Apache License 2.0 6 votes vote down vote up
def site_login(request):
    """
    Logs in current user
    :param request:
    :return render:
    """
    if request.method == "POST":
        user = None
        user_login = request.POST['login']
        user_password = request.POST['password']
        print("Login tryout by "+user_login)
        if user_login != "" and user_password != "":
            user = authenticate(username=user_login, password=user_password)
        if user is not None:
            login(request, user)
            return HttpResponseRedirect(reverse('public_gate:home'))
        else:
            # User.objects.create_user(user_login, '', user_password).save()
            return render(request, 'public_gate/home.html', {"error_message": "Wrong login/password combination"})
    return render(request, 'public_gate/home.html', {"error_message": "One or more fields are empty"}) 
Example 5
Project: django-hijack-admin   Author: arteria   File: admin.py    License: MIT License 6 votes vote down vote up
def hijack_field(self, obj):
        hijack_attributes = hijack_settings.HIJACK_URL_ALLOWED_ATTRIBUTES

        if 'user_id' in hijack_attributes:
            hijack_url = reverse('hijack:login_with_id', args=(obj.pk, ))
        elif 'email' in hijack_attributes:
            hijack_url = reverse('hijack:login_with_email', args=(obj.email, ))
        else:
            hijack_url = reverse('hijack:login_with_username', args=(obj.username, ))

        button_template = get_template(hijack_admin_settings.HIJACK_BUTTON_TEMPLATE)
        button_context = {
            'hijack_url': hijack_url,
            'username': str(obj),
        }

        return button_template.render(button_context) 
Example 6
Project: pythonjobs.ie   Author: kimeraapp   File: views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def item_link(self, job):
        return reverse('job-show', args=[job.pk]) 
Example 7
Project: pythonjobs.ie   Author: kimeraapp   File: models.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_absolute_url(self):
        return reverse('job-show', args=[str(self.id)]) 
Example 8
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_index_returns_200(self):
        response = self.client.get(reverse("job-home"))
        self.assertEquals(response.status_code, 200) 
Example 9
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_index_list_active_jobs(self):
        mommy.make(Job, status=0)
        response = self.client.get(reverse("job-home"))
        self.assertEquals(len(response.context["jobs"]), 1) 
Example 10
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_show_returns_200(self):
        response = self.client.get(reverse("job-show", args=[self.job.pk]))
        self.assertEquals(response.status_code, 200) 
Example 11
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_show_inactive_job_returns_404(self):
        job = mommy.make(Job, status=0)
        response = self.client.get(reverse("job-show", args=[job.pk]))
        self.assertEquals(response.status_code, 404) 
Example 12
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_new_returns_200(self):
        response = self.client.get(reverse("job-new"))
        self.assertEquals(response.status_code, 200) 
Example 13
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_new_template(self):
        response = self.client.get(reverse("job-new"))
        self.assertTemplateUsed(response, "new.html") 
Example 14
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_create_new_job(self):
        self.job.pk = 0
        params = model_to_dict(self.job)
        response = self.client.post(reverse("job-new"), params)
        self.assertEquals(response.status_code, 302) 
Example 15
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_edit_returns_200(self):
        response = self.client.get(reverse("job-edit", args=[self.job.token]))
        self.assertEquals(response.status_code, 200) 
Example 16
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_feed_link_returns_job_link(self):
        job_link = reverse('job-show', args=[self.job.pk])
        self.assertEquals(JobsFeed.item_link(self, self.job), job_link) 
Example 17
Project: tracker_project   Author: abarto   File: models.py    License: MIT License 5 votes vote down vote up
def geojson_feature(self):
        return Feature(
            geometry=loads(self.location.geojson),
            id='Incident:{pk}'.format(pk=self.pk),
            properties={
                'name': self.name,
                'description': self.description,
                'severity': self.get_severity_display(),
                'created': str(self.created),
                'closed': self.closed,
                'model': 'Incident',
                'pk': self.pk,
                'url': reverse('tracker:incident-detail', kwargs={'pk': self.pk}),
            }
        ) 
Example 18
Project: tracker_project   Author: abarto   File: models.py    License: MIT License 5 votes vote down vote up
def geojson_feature(self):
        return Feature(
            geometry=loads(self.polygon.geojson),
            id='AreaOfInterest:{pk}'.format(pk=self.pk),
            properties={
                'name': self.name,
                'severity': self.get_severity_display(),
                'centroid': self.polygon.centroid.geojson,
                'model': 'AreaOfInterest',
                'pk': self.pk,
                'url': reverse('tracker:area-of-interest-detail', kwargs={'pk': self.pk}),
            }
        ) 
Example 19
Project: tracker_project   Author: abarto   File: forms.py    License: MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(ReportIncidentForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()

        self.helper.form_action = reverse('tracker:report-incident')
        self.helper.render_hidden_fields = True
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-10'
        self.helper.add_input(Submit('submit', 'Report', css_class='btn-lg btn-block')) 
Example 20
Project: tracker_project   Author: abarto   File: forms.py    License: MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(IncidentForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()

        if kwargs.get('instance', None) is not None:
            self.helper.form_action = reverse('tracker:incident-update', kwargs={'pk': kwargs['instance'].pk})
        else:
            self.helper.form_action = reverse('tracker:incident-create')

        self.helper.render_hidden_fields = True
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-10'
        self.helper.add_input(Submit('submit', 'Save', css_class='pull-right')) 
Example 21
Project: tracker_project   Author: abarto   File: forms.py    License: MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(AreaOfInterestForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()

        if kwargs.get('instance', None) is not None:
            self.helper.form_action = reverse('tracker:area-of-interest-update', kwargs={'pk': kwargs['instance'].pk})
        else:
            self.helper.form_action = reverse('tracker:area-of-interest-create')

        self.helper.render_hidden_fields = True
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-10'
        self.helper.add_input(Submit('submit', 'Save', css_class='pull-right')) 
Example 22
Project: contributr   Author: Djenesis   File: models.py    License: MIT License 5 votes vote down vote up
def get_absolute_url(self):
        return reverse('blog:detail', kwargs={'slug': self.slug}) 
Example 23
Project: contributr   Author: Djenesis   File: test_blog.py    License: MIT License 5 votes vote down vote up
def test_call_blog(client):
    """
    Asserts whether the blog page sends a 200 HTTP status code as response

    200 means that the HTTP request was successful. The URL and port
    may vary. The fixture above the function allows the function to
    access the database.
    """
    response = client.get(reverse("blog:index"))
    assert response.status_code == 200 
Example 24
Project: contributr   Author: Djenesis   File: test_blog.py    License: MIT License 5 votes vote down vote up
def test_call_blog_subpage(client):
    """
    Asserts whether subpages of the blog page 404

    404 means that no page is returned. This is the expected behaviour,
    because we don't have subpages for the blog at the moment.
    """
    response = client.get(reverse("blog:index") + "december")
    assert response.status_code == 404 
Example 25
Project: Servo   Author: fpsw   File: account.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def view_calendar(request, pk, view, start_date=None):
    data = prepare_calendar_view(request, pk, view, start_date)
    data['base_url'] = reverse(view_calendar, args=[pk, view])
    return render(request, "accounts/view_calendar.html", data) 
Example 26
Project: Servo   Author: fpsw   File: order.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def parts(request, order_id, device_id, queue_id):
    """
    Selects parts for this device in this order
    """
    order = Order.objects.get(pk=order_id)
    device = Device.objects.get(pk=device_id)
    title = device.description
    url = reverse('devices-parts', args=[device_id, order_id, queue_id])

    if order.queue is not None:
        request.session['current_queue'] = order.queue.pk

    return render(request, "orders/parts.html", locals()) 
Example 27
Project: Servo   Author: fpsw   File: search.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def orders(request):
    """
    Searches local service orders
    """
    query = request.GET.get("q")

    if not query or len(query) < 3:
        messages.error(request, _('Search query is too short'))
        return redirect(reverse('orders-index'))

    request.session['search_query'] = query

    # Redirect Order ID:s to the order
    try:
        order = Order.objects.get(code__iexact=query)
        return redirect(order)
    except Order.DoesNotExist:
        pass

    orders = Order.objects.filter(
        Q(code=query) | Q(devices__sn__contains=query) |
        Q(customer__fullname__icontains=query) |
        Q(customer__phone__contains=query) |
        Q(repair__confirmation=query) |
        Q(repair__reference=query)
    )

    data = {
        'title': _('Orders'),
        'subtitle': _(u'%d results for "%s"') % (orders.count(), query)
    }

    page = request.GET.get('page')
    data['orders'] = paginate(orders.distinct(), page, 100)

    return render(request, "orders/index.html", data) 
Example 28
Project: Servo   Author: fpsw   File: repair.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_admin_url(self):
        return reverse('admin-edit_checklist', args=[self.pk]) 
Example 29
Project: Servo   Author: fpsw   File: repair.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_absolute_url(self):
        if self.submitted_at is None:
            url = 'repairs-edit_repair'
        else:
            url = 'repairs-view_repair'

        return reverse(url, args=[self.order.pk, self.pk]) 
Example 30
Project: Servo   Author: fpsw   File: product.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_absolute_url(self):
        if self.pk is None:
            return reverse("products-view_product", kwargs={'code': self.code})

        return reverse("products-view_product", kwargs={'pk': self.pk})