Advertisement
Guest User

Untitled

a guest
Feb 5th, 2017
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. ^([A-Fa-f0-9]{8}))(-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}
  2.  
  3. <form action="{% url 'polls:vote' question.question_id %}" method="post">
  4.  
  5. from django.conf.urls import url
  6.  
  7. from . import views
  8.  
  9. app_name= 'polls'
  10. urlpatterns = [
  11. #ex: /polls/
  12. url(r'^$',views.index, name='index'),
  13. #ex: /polls/uuid
  14. url(r'^(?P<question_id>^([A-Fa-f0-9]{8})(-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12})/$', views.detail, name='detail'),
  15. #ex: /polls/uuid/results/
  16. url(r'^(?P<question_id>^([A-Fa-f0-9]{8})(-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12})/results/$', views.results, name='results'),
  17. #ex: /polls/uuid/vote
  18. url(r'^(?P<question_id>^([A-Fa-f0-9]{8})(-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12})/vote/$', views.vote, name='vote'),
  19. ]
  20.  
  21. from django.conf.urls import url
  22. from . import views
  23.  
  24. app_name= 'polls'
  25. urlpatterns = [
  26. url(r'^$',views.index, name='index'),
  27. #ex: polls/5/results/
  28. url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
  29. #ex: /polls/5/volte
  30. url(r'^(?P<question_id>(^([A-Fa-f0-9]{8}))(-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12})/vote/$', views.vote, name='vote'),
  31. #ex: polls/5/
  32. url(r'^(?P<question_id>[^/]+)/$',views.detail, name='detail'),
  33. ]
  34.  
  35. from django.shortcuts import render
  36.  
  37. # Create your views here.
  38.  
  39. from django.shortcuts import render, get_object_or_404
  40. from .models import Question, Choice
  41. from django.shortcuts import get_object_or_404, render
  42.  
  43.  
  44. def index(request):
  45. #latest_question_list = Question.objects.order_by('-pub_date')[5:]
  46. latest_question_list = Question.objects()
  47. context = {
  48. 'latest_question_list': latest_question_list,
  49. }
  50. return render(request, 'polls/index.html', context)
  51.  
  52.  
  53. def detail(request, question_id):
  54. question = get_object_or_404(Question, pk=question_id)
  55. return render(request, 'polls/detail.html', {'question':question})
  56.  
  57.  
  58. def vote(request, question_id):
  59. question = get_object_or_404(Question, pk=question_id)
  60. try:
  61. selected_choice = get_object_or_404(Choice, pk=question_id)
  62. #selected_choice = question.choice_set.get(pk=request.POST['choice'])
  63. except (KeyError, Choice.DoesNotExist):
  64. # Redisplay the question voting form.
  65. return render(request, 'polls/detail.html', {
  66. 'question': question,
  67. 'error_message': "You didn't select a choice.",
  68. })
  69. else:
  70. selected_choice.votes += 1
  71. selected_choice.save()
  72. # Always return an HttpResponseRedirect after successfully dealing
  73. # with POST data. This prevents data from being posted twice if a
  74. # user hits the Back button.
  75. return HttpResponseRedirect(
  76. reverse('polls:results', args=(question.question_id,))
  77. )
  78.  
  79. def results(request, question_id):
  80. question = get_object_or_404(Question, pk=question_id)
  81. return render(request, 'polls/results.html', {'question': question})
  82.  
  83. <h1>{{ question.question_text }}</h1>
  84.  
  85. {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
  86.  
  87. <form action="{% url 'polls:vote' question.question_id %}" method="post">
  88. {% csrf_token %}
  89. {% for choice in question.choice_set.all %}
  90. <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
  91. <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
  92. {% endfor %}
  93. <input type="submit" value="Vote" />
  94. </form>
  95.  
  96. from django.db import models
  97.  
  98. # Create your models here
  99.  
  100. import uuid
  101. from cassandra.cqlengine import columns
  102. from cassandra.cqlengine import models
  103.  
  104.  
  105. from django_cassandra_engine.models import DjangoCassandraModel
  106.  
  107. class User(models.Model):
  108. username = columns.Text(primary_key=True)
  109. password = columns.Text()
  110. email = columns.Text()
  111. fullname = columns.Text()
  112. is_staff = columns.Boolean(default=False)
  113.  
  114. class ExampleModel(DjangoCassandraModel):
  115. example_id = columns.UUID(primary_key=True, default=uuid.uuid4)
  116. example_type = columns.Integer(index=True)
  117. created_at = columns.DateTime()
  118. description = columns.Text(required=False)
  119.  
  120. class Question(DjangoCassandraModel):
  121. def __str__(self):
  122. return self.question_text
  123. question_id = columns.UUID(primary_key=True)
  124. question_text = columns.Text()
  125. pub_date = columns.TimeUUID()
  126.  
  127. class Choice(DjangoCassandraModel):
  128. def __str__(self):
  129. return self.choise_text
  130. question = columns.UUID(primary_key=True)
  131. choice_text = columns.Text()
  132. votes = columns.Integer(index=True,default=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement