當前位置: 首頁>>代碼示例>>Python>>正文


Python urlresolvers.reverse方法代碼示例

本文整理匯總了Python中django.core.urlresolvers.reverse方法的典型用法代碼示例。如果您正苦於以下問題:Python urlresolvers.reverse方法的具體用法?Python urlresolvers.reverse怎麽用?Python urlresolvers.reverse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.urlresolvers的用法示例。


在下文中一共展示了urlresolvers.reverse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: close

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:24,代碼來源:order.py

示例2: accessories

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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()) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:22,代碼來源:order.py

示例3: __init__

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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 
開發者ID:fpsw,項目名稱:Servo,代碼行數:19,代碼來源:notes.py

示例4: site_login

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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"}) 
開發者ID:OpenMDM,項目名稱:OpenMDM,代碼行數:22,代碼來源:views.py

示例5: hijack_field

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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) 
開發者ID:arteria,項目名稱:django-hijack-admin,代碼行數:19,代碼來源:admin.py

示例6: item_link

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def item_link(self, job):
        return reverse('job-show', args=[job.pk]) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:4,代碼來源:views.py

示例7: get_absolute_url

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def get_absolute_url(self):
        return reverse('job-show', args=[str(self.id)]) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:4,代碼來源:models.py

示例8: test_index_returns_200

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def test_index_returns_200(self):
        response = self.client.get(reverse("job-home"))
        self.assertEquals(response.status_code, 200) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:5,代碼來源:test_views.py

示例9: test_index_list_active_jobs

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:6,代碼來源:test_views.py

示例10: test_show_returns_200

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def test_show_returns_200(self):
        response = self.client.get(reverse("job-show", args=[self.job.pk]))
        self.assertEquals(response.status_code, 200) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:5,代碼來源:test_views.py

示例11: test_show_inactive_job_returns_404

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:6,代碼來源:test_views.py

示例12: test_new_returns_200

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def test_new_returns_200(self):
        response = self.client.get(reverse("job-new"))
        self.assertEquals(response.status_code, 200) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:5,代碼來源:test_views.py

示例13: test_new_template

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def test_new_template(self):
        response = self.client.get(reverse("job-new"))
        self.assertTemplateUsed(response, "new.html") 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:5,代碼來源:test_views.py

示例14: test_create_new_job

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
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) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:7,代碼來源:test_views.py

示例15: test_edit_returns_200

# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse [as 別名]
def test_edit_returns_200(self):
        response = self.client.get(reverse("job-edit", args=[self.job.token]))
        self.assertEquals(response.status_code, 200) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:5,代碼來源:test_views.py


注:本文中的django.core.urlresolvers.reverse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。