ModeratePost, ) urlpatterns = patterns( "", # Syndication feeds url("^feeds/posts/$", LastPosts(), name="feed_posts"), url("^feeds/topics/$", LastTopics(), name="feed_topics"), ) urlpatterns += patterns( "pybb.views", # Index, Category, Forum url("^$", IndexView.as_view(), name="index"), url("^category/(?P<pk>\d+)/$", CategoryView.as_view(), name="category"), url("^forum/(?P<pk>\d+)/$", ForumView.as_view(), name="forum"), # User url("^users/(?P<username>[^/]+)/$", UserView.as_view(), name="user"), url("^block_user/([^/]+)/$", "block_user", name="block_user"), # Profile url("^profile/edit/$", ProfileEditView.as_view(), name="edit_profile"), # Topic url("^topic/(?P<pk>\d+)/$", TopicView.as_view(), name="topic"), url("^topic/(?P<pk>\d+)/stick/$", StickTopicView.as_view(), name="stick_topic"), url("^topic/(?P<pk>\d+)/unstick/$", UnstickTopicView.as_view(), name="unstick_topic"), url("^topic/(?P<pk>\d+)/close/$", CloseTopicView.as_view(), name="close_topic"), url("^topic/(?P<pk>\d+)/open/$", OpenTopicView.as_view(), name="open_topic"), # Add topic/post url("^forum/(?P<forum_id>\d+)/topic/add/$", AddPostView.as_view(), name="add_topic"), url("^topic/(?P<topic_id>\d+)/post/add/$", AddPostView.as_view(), name="add_post"),
feeds = {'posts': LastPosts, 'topics': LastTopics} urlpatterns = patterns( '', # Syndication feeds url('^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}, name='feed'), ) urlpatterns += patterns( 'pybb.views', # Index, Category, Forum url('^$', IndexView.as_view(), name='index'), url('^category/(?P<pk>\d+)/$', CategoryView.as_view(), name='category'), url('^forum/(?P<pk>\d+)/$', ForumView.as_view(), name='forum'), # User url('^users/(?P<username>[^/]+)/$', UserView.as_view(), name='user'), url('^block_user/([^/]+)/$', 'block_user', name='block_user'), # Profile url('^profile/edit/$', ProfileEditView.as_view(), name='edit_profile'), # Topic url('^topic/(?P<pk>\d+)/$', TopicView.as_view(), name='topic'), url('^topic/(?P<pk>\d+)/stick/$', StickTopicView.as_view(), name='stick_topic'), url('^topic/(?P<pk>\d+)/unstick/$',
from pybb.feeds import LastPosts, LastTopics from views import IndexView, CategoryView, ForumView, TopicView, AddPostView, EditPostView,\ UserView, PostView, DeletePostView, StickTopicView, UnstickTopicView,\ CloseTopicView, OpenTopicView, ModeratePost urlpatterns = patterns('', # Syndication feeds url('^feeds/posts/$', LastPosts(), name='feed_posts'), url('^feeds/topics/$', LastTopics(), name='feed_topics'), ) urlpatterns += patterns('pybb.views', # Index, Category, Forum url('^$', IndexView.as_view(), name='index'), url('^category/(?P<pk>\d+)/$', CategoryView.as_view(), name='category'), url('^forum/(?P<pk>\d+)/$', ForumView.as_view(), name='forum'), # User url('^users/(?P<username>[^/]+)/$', UserView.as_view(), name='user'), url('^block_user/([^/]+)/$', 'block_user', name='block_user'), # Profile # url('^profile/edit/$', ProfileEditView.as_view(), name='edit_profile'), # Topic url('^topic/(?P<pk>\d+)/$', TopicView.as_view(), name='topic'), url('^topic/(?P<pk>\d+)/stick/$', StickTopicView.as_view(), name='stick_topic'), url('^topic/(?P<pk>\d+)/unstick/$', UnstickTopicView.as_view(), name='unstick_topic'), url('^topic/(?P<pk>\d+)/close/$', CloseTopicView.as_view(), name='close_topic'), url('^topic/(?P<pk>\d+)/open/$', OpenTopicView.as_view(), name='open_topic'),
from django.conf.urls import patterns, url from views import CategoryView, ItemView, IndexView, CheckoutView urlpatterns = patterns('', url(r'^about/', 'store.views.about', name='about'), url(r'^contact/', 'store.views.contact', name='contact'), url(r'^thanks/', 'store.views.thanks', name='thanks'), url(r'^purchase/success/', 'store.views.purchase_success', name='store_purchase_success'), url(r'^collection/(?P<slug>[-a-zA-Z0-9_]{1,50})/$', CategoryView.as_view(), name='store_category'), url(r'^item/(?P<pk>\d+)/$', ItemView.as_view(), name='store_item'), url(r'^item/(?P<pk>\d+)/purchase$', CheckoutView.as_view(), name='store_item_purchase'), url(r'^$', IndexView.as_view(), name='index'), )
from django.contrib.auth.decorators import login_required from django.conf.urls.defaults import patterns, url from views import ( SignUpView, CategoryView, InviteView ) urlpatterns = patterns('organizer.views', url(r'^$', 'dashboard', name='or_dash' ), url(r'^signup/$', SignUpView.as_view(), name='or_signup' ), url(r'^category/$', login_required( CategoryView.as_view()), name='or_category' ), url(r'^invite/$', login_required( InviteView.as_view()), name='or_invite' ), url(r'^setup/$', 'setup', name='or_setup' ), url(r'^dash/$', 'dashboard', name='or_dash' ), url(r'^leadb/$', 'leadb', name='or_leadb' ), url(r'^status/$', 'status', name='or_status' ), url(r'^events/$', 'events', name='or_events' ), url(r'^landing/$', 'landing', name='or_landing' ), )
from django.conf.urls import patterns, url from django.views.generic.simple import direct_to_template from views import FunficsView, CategoryView, GenreView urlpatterns = patterns('', url(r'^login/$', direct_to_template, {'template': 'login.html'}, "login"), url(r'^funfics/$', FunficsView.as_view(), name='funfics'), url(r'^categories/(?P<pk>\d+)/', CategoryView.as_view(), name='category'), url(r'^genre/(?P<pk>\d+)/', GenreView.as_view(), name='genre'), url(r'^$', direct_to_template, {'template': 'home.html'}, "home"), )
class RegexConverter(BaseConverter): '''Sets up regex to be used in the add_url_rule ''' def __init__(self, url_map, *items): super(RegexConverter, self).__init__(url_map) self.regex = items[0] app.url_map.converters['regex'] = RegexConverter app.add_url_rule("/", view_func=HomeView.as_view('home_view')) app.add_url_rule("/json", view_func=HomeView.as_view('home_json')) app.add_url_rule("/xml", view_func=HomeView.as_view('home_xml')) # /category app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()), view_func=CategoryView.as_view('category_view')) app.add_url_rule('/<regex("{}"):category>/json'.format(utils.get_cat_regex()), view_func=CategoryView.as_view('category_json')) app.add_url_rule('/<regex("{}"):category>/xml'.format(utils.get_cat_regex()), view_func=CategoryView.as_view('category_xml')) # /category/item_id app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()) + '/<int:item_id>', view_func=ItemView.as_view('item_view')) app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()) + '/<int:item_id>/json', view_func=ItemView.as_view('item_json')) app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()) + '/<int:item_id>/xml', view_func=ItemView.as_view('item_xml')) # /category/item_id/delete
urlpatterns = [ url(r'^$', BlogList.as_view(), name="blog_list"), url(r'^(?P<pk>\d+)/$', BlogView.as_view(), name="blog"), url(r'^new/$', login_required(CreateBlog.as_view()), name="create_blog"), url(r'^(?P<pk>\d+)/edit/$', login_required(UpdateBlog.as_view()), name="edit_blog"), url(r'^(?P<pk>\d+)/new/$', login_required(CreatePostInBlog.as_view()), name="create_post_in_blog"), url(r'^post/(?P<pk>\d+)/$', PostView.as_view(), name="post"), url(r'^post/(?P<pk>\d+)/comments/$', PostCommentsView.as_view(), name="post_comments"), url(r'^post/new/$', login_required(CreatePost.as_view()), name="create_post"), url(r'^post/(?P<pk>\d+)/edit/$', login_required(UpdatePost.as_view()), name="edit_post"), url(r'^post/(?P<pk>\d+)/likes/$', csrf_exempt(PostLikeCountView.as_view()), name="post_likes"), url(r'^post/(?P<pk>\d+)/likes/add/$', likes_add, name="post_new_like"), url(r'^category/(?P<pk>\d+)/$', CategoryView.as_view(), name="category"), url(r'^category/new/$', login_required(CreateCategory.as_view()), name="create_category"), ]
def quiz_app() -> None: main = QuizRouter().main()['main'] if not main: print("No Quiz option selected") return elif main[0] == "CREATE": rows = CategoryView().read_all() if not rows: create = CategoryRouter().create() name = create['name'] if not name: print("create ERROR - every quiz needs a Category") return if not CategoryView().create(name): print("name ERROR - No name for Category") return rows = CategoryView().read_all() row_id = MainRouter().category(rows)['id'] if row_id: cat_id = row_id[0].split(' - ')[0].strip() create = QuizRouter().create() if all(create.values()): question = create['question'] options = create['options'] answer = create['answer'] if QuizView().create(cat_id, question, options, answer): print("OK") else: print("create ERROR") else: print( "fields ERROR - question, option and answer is required to create a quiz" ) else: print("row selection ERROR - category is required") elif main[0] == "READ": rows = QuizView().read_all() if not rows: print("read ERROR") return MainRouter().quiz(rows) elif main[0] == "UPDATE": rows = QuizView().read_all() row_id = MainRouter().quiz(rows)['quiz'] if row_id: print("row selection ERROR") return id = row_id[0].split(' - ')[0].strip() update = QuizRouter().update(id) update = {k: v for k, v in update.items() if v} if not update or not all(update.values()): print("update ERROR - at least a field is needed for update") return if not QuizView().update(id, **update): print("update ERROR") return print("OK - UPDATED") elif main[0] == "DELETE": rows = QuizView().read_all() row_id = MainRouter().quiz(rows)['id'] if not row_id: print("row selection ERROR") return id = row_id[0].split(' - ')[0].strip() delete = QuizRouter().delete(id)['DELETE'] if not delete: print("No row affected") return if not QuizView().delete(id): print("Ok - no row affected") return print("OK - DELETED") return
def category_app() -> None: main = CategoryRouter().main()['main'] if not main: print("No Category option selected") elif main[0] == "CREATE": create = CategoryRouter().create() name = create['name'] if not name: print("name ERROR") return if not CategoryView().create(name): print("create ERROR") return print("OK - CREATED") elif main[0] == "READ": rows = CategoryView().read_all() if not rows: print("read ERROR") return MainRouter().category(rows) elif main[0] == "UPDATE": rows = CategoryView().read_all() row_id = MainRouter().category(rows)['id'] if not row_id: print("row selection ERROR") return id = row_id[0].split(' - ')[0].strip() update = CategoryRouter().update(id) if not CategoryView().update(id, **update): print("update ERROR") return print("OK - UPDATE") elif main[0] == "DELETE": rows = CategoryView().read_all() row_id = MainRouter().category(rows)['id'] if not row_id: print("row selection ERROR") return id = row_id[0].split(' - ')[0].strip() delete = CategoryRouter().delete(id)['DELETE'] if not delete: print("No row affected") return if not CategoryView().delete(int(id)): print("Ok - no row affected") return print("OK - DELETE") return
'''Sets up regex to be used in the add_url_rule ''' def __init__(self, url_map, *items): super(RegexConverter, self).__init__(url_map) self.regex = items[0] app.url_map.converters['regex'] = RegexConverter app.add_url_rule("/", view_func=HomeView.as_view('home_view')) app.add_url_rule("/json", view_func=HomeView.as_view('home_json')) app.add_url_rule("/xml", view_func=HomeView.as_view('home_xml')) # /category app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()), view_func=CategoryView.as_view('category_view')) app.add_url_rule( '/<regex("{}"):category>/json'.format( utils.get_cat_regex()), view_func=CategoryView.as_view('category_json')) app.add_url_rule( '/<regex("{}"):category>/xml'.format( utils.get_cat_regex()), view_func=CategoryView.as_view('category_xml')) # /category/item_id app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()) + '/<int:item_id>', view_func=ItemView.as_view('item_view')) app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()) + '/<int:item_id>/json', view_func=ItemView.as_view('item_json')) app.add_url_rule('/<regex("{}"):category>'.format(utils.get_cat_regex()) + '/<int:item_id>/xml', view_func=ItemView.as_view('item_xml'))
Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from . import views from views import CategoryView, RelatedView, DifferentView, CompletedtView, RecommendView # from django.conf.urls.defaults import * from django.conf import settings urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^category/(?P<category>\w+)/$', CategoryView.as_view(), name='category'), url(r'^more/(?P<article_id>\w+)/$', RelatedView.as_view(), name='related'), url(r'^skip/(?P<article_id>\w+)/$', DifferentView.as_view(), name='different'), url(r'^completed/(?P<article_id>\w+)/$', CompletedtView.as_view(), name='completed'), url(r'^recommendations/$', RecommendView.as_view(), name='recommend'), ]
from django.conf.urls import patterns,include,url # from django.views.decorators.csrf import csrf_exempt # from django.contrib.auth.decorators import login_required from views import (HomeView, LoginView, SignUpView, LogOutView, CategoryView) urlpatterns = patterns('', url(r'^$', HomeView.as_view(), name="home"), url(r'^login/$', LoginView.as_view(), name='login'), url(r'^signup/$', SignUpView.as_view(), name='signup'), url(r'^logout/$', LogOutView.as_view(), name='logout'), url(r'^get_category/$', CategoryView.as_view()), )