Python django.core.urlresolvers.reverse() Examples
The following are 30
code examples of django.core.urlresolvers.reverse().
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 also want to check out all available functions/classes of the module
django.core.urlresolvers
, or try the search function
.
Example #1
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
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 #2
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
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 #3
Source File: notes.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
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
Source File: admin.py From django-hijack-admin with MIT License | 6 votes |
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 #5
Source File: views.py From django-accounting with MIT License | 5 votes |
def get(self, request, *args, **kwargs): orga = organization_manager.get_selected_organization(self.request) if orga is None: return HttpResponseRedirect(reverse('books:organization-selector')) return super().get(request, *args, **kwargs)
Example #6
Source File: steps.py From django-accounting with MIT License | 5 votes |
def get_action_url(self): return reverse('books:invoice-create')
Example #7
Source File: views.py From django-accounting with MIT License | 5 votes |
def get_success_url(self): return reverse("reports:settings-list")
Example #8
Source File: steps.py From django-accounting with MIT License | 5 votes |
def get_action_url(self): return reverse('people:client-create')
Example #9
Source File: steps.py From django-accounting with MIT License | 5 votes |
def get_action_url(self): return reverse('reports:settings-business')
Example #10
Source File: steps.py From django-accounting with MIT License | 5 votes |
def get_action_url(self): return reverse('books:tax_rate-create')
Example #11
Source File: steps.py From django-accounting with MIT License | 5 votes |
def get_action_url(self): return reverse('books:organization-create')
Example #12
Source File: views.py From django-accounting with MIT License | 5 votes |
def post(self, request, *args, **kwargs): steps = self.get_steps(request) uncompleted_steps = filter(lambda s: not s.completed(request), steps) if not len(uncompleted_steps): return super().post(request, *args, **kwargs) # unmark the session as getting started request.sessions['getting_started_done'] = True return HttpResponseRedirect(reverse('books:dashboard'))
Example #13
Source File: steps.py From django-accounting with MIT License | 5 votes |
def get_action_url(self): return reverse('reports:settings-financial')
Example #14
Source File: views.py From django-accounting with MIT License | 5 votes |
def get_success_url(self): return reverse('books:estimate-detail', args=[self.object.pk])
Example #15
Source File: views.py From django-accounting with MIT License | 5 votes |
def get_success_url(self): related_obj = self.object.content_object if isinstance(related_obj, Invoice): return reverse("books:invoice-detail", args=[related_obj.pk]) elif isinstance(related_obj, Bill): return reverse("books:bill-detail", args=[related_obj.pk]) logger.warning("Unsupported related object '{}' for " "payment '{}'".format(self.object, related_obj)) return reverse("books:dashboard")
Example #16
Source File: views.py From django-accounting with MIT License | 5 votes |
def post(self, request, *args, **kwargs): orga = self.get_object() organization_manager.set_selected_organization(self.request, orga) return HttpResponseRedirect(reverse('books:dashboard'))
Example #17
Source File: calendar.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_absolute_url(self): return reverse('calendars.view', args=[self.pk])
Example #18
Source File: test_example.py From django-pusherable with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_pusher_templatetags(self, Pusher): request = self.factory.get(reverse("example", kwargs={"pk": self.object.pk})) request.user = self.user response = PusherableExampleDetail.as_view()(request, pk=self.object.pk) channel = u"{model}_{pk}".format( model=self.object._meta.model_name, pk=self.object.pk ) self.assertContains(response, "js.pusher.com/2.2/pusher.min.js") self.assertContains(response, "pusher.subscribe('{channel}');".format( channel=channel ))
Example #19
Source File: test_figures_home_view.py From figures with MIT License | 5 votes |
def test_registered_users(self, username, status_code): '''Test that only active staff and superuser users can access the Figures page and that users that don't pass the test get redirected to ''' request = self.factory.get(reverse('figures-home')) request.user = get_user_model().objects.get(username=username) response = figures_home(request) assert response.status_code == status_code, "username={}".format(username) if status_code == 302: assert response['location'] == UNAUTHORIZED_USER_REDIRECT_URL
Example #20
Source File: test_figures_home_view.py From figures with MIT License | 5 votes |
def test_anonymous_user(self): '''Verify that anonymous users (not logged in) get redirected to login ''' request = self.factory.get(reverse('figures-home')) request.user = AnonymousUser() response = figures_home(request) assert response.status_code == 302 assert response['location'].startswith(self.redirect_startswith)
Example #21
Source File: views.py From djreservation with GNU General Public License v3.0 | 5 votes |
def deleteProduct(request, pk): product = get_object_or_404(Product, pk=pk) product.delete() messages.success(request, _('Product deleted successful')) return redirect(reverse("finish_reservation"))
Example #22
Source File: views.py From OpenMDM with Apache License 2.0 | 5 votes |
def site_logout(request): """ Logs out current user :param request: :return render: """ logout(request) return HttpResponseRedirect(reverse('public_gate:home')) ######################################################################## # # # Property List Views # # ########################################################################
Example #23
Source File: views.py From OpenMDM with Apache License 2.0 | 5 votes |
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 #24
Source File: forms.py From django-payfast with MIT License | 5 votes |
def notify_url(): return full_url(reverse('payfast_notify'))
Example #25
Source File: test_example.py From chatterbot-live-example with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): super(ApiIntegrationTestCase, self).setUp() self.api_url = reverse('chatterbot:chatterbot') # Clear the response queue before tests ChatterBotView.chatterbot.conversation_sessions.get_default().conversation.flush()
Example #26
Source File: test_example.py From chatterbot-live-example with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): super(ApiTestCase, self).setUp() self.api_url = reverse('chatterbot:chatterbot')
Example #27
Source File: test_example.py From chatterbot-live-example with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): super(ViewTestCase, self).setUp() self.url = reverse('main')
Example #28
Source File: queue.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_admin_url(self): return reverse('admin-edit_status', args=[self.pk])
Example #29
Source File: queue.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_admin_url(self): return reverse('admin-edit_queue', args=[self.pk])
Example #30
Source File: purchases.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_absolute_url(self): from django.core.urlresolvers import reverse if self.submitted_at: return reverse("purchases-view_po", args=[self.pk]) return reverse("purchases-edit_po", args=[self.pk])