def create_material(request): kwargs = { 'form_class': MaterialDescriptionForm, } if request.GET.get('next', None): kwargs['post_save_redirect'] = request.GET.get('next') return create_update.create_object(request, **kwargs)
def exercise_list_add_or_update(request, list_id=None): if list_id: return update_object(request, model=ExerciseList, object_id=list_id, template_name='exercise_list_form.html', post_save_redirect='/') else: return create_object(request, model=ExerciseList, template_name='exercise_list_form.html', post_save_redirect='/')
def crear_nota(request): return create_object(request, model=Nota, template_name='crear.html', post_save_redirect=reverse("lista_de_notas") )
def add(request): ''' Allows the logged-in user to add videos to the site ''' perm = request.user.has_module_perms('videos') if request.method == 'POST': if perm: form = VideoFormPriv(request.POST, request.FILES) else: form = VideoForm(request.POST) if form.is_valid(): v = form.save( commit=False ) v.owner = request.user # stupid hack to get a unique slug if not Video.objects.filter( slug=slugify(v.title) ): v.slug = slugify(v.title) else: v.slug = slugify(v.title) + '-' +\ ''.join([choice('skyl-org') for i in range(8)]) v.save() return HttpResponseRedirect( reverse('videos_list') ) return create_object(request, form_class = VideoFormPriv if perm else VideoForm, extra_context = locals() )
def edit_singleton_model(request, templatename, redirect_to, formclass=None, model=None, extra_context=None, reload_bacula=True): if not '/' in redirect_to: redirect_to = reverse(redirect_to) if not formclass and model: formclass = forms.form(model) try: r = update_object(request, object_id=1, form_class=formclass, model=model, template_name=templatename, post_save_redirect=redirect_to, extra_context=extra_context) except Http404, error: r = create_object(request, form_class=formclass, model=model, template_name=templatename, post_save_redirect=redirect_to, extra_context=extra_context)
def new_category(*args, **kwargs): """Create a new category. Permission checking wrapper for generic view. """ return create_object(model=Category, post_save_redirect='/products/categories', *args, **kwargs)
def document_add(request): acc = request.user.get_profile() class SectionModelChoiceField(ModelChoiceField): def label_from_instance(self, obj): if acc.typ == const.RU_TYP: return obj.ru_title else: return obj.en_title class DocumentForm(ModelForm): section = SectionModelChoiceField(label=_(u'Секция'), widget=RadioSelect, queryset=Section.objects.all(), empty_label=None) class Meta: model = Document fields = ('title', 'filename', 'section', 'desc') def save(self): obj = super(DocumentForm, self).save(commit=False) obj.author = acc obj.save() obj.to_status(const.STATUS_DISCUSS, acc) return obj return create_object(request, form_class=DocumentForm, post_save_redirect=reverse('account'), template_name='account/document_form.html')
def new_product(*args, **kwargs): """Create a new product. Permission checking wrapper for generic view. """ return create_object(model=Product, post_save_redirect='/products', *args, **kwargs)
def blurb_add(request): return create_object( request, form_class = BlurbForm, login_required = True, template_name = 'blurbs/blurbs_add_edit.html', )
def test_view_create(request): return create_update.create_object( request, PermissionTestClass, template_name="permissions/empty.html", post_save_redirect=reverse("test_view_crud"), )
def add_order(request, customer_id): return create_update.create_object( request, model=Order, post_save_redirect=reverse('jazzpos.views.list_customers'), template_name='customer_add.html', )
def teacher_adduzleg(request): return create_update.create_object( request, model = Uzleg, post_save_redirect = reverse('home-teacher'), template_name = 'teacher/adduzleg.html' )
def create_xform(request, group_name=None): return create_object( request=request, form_class=CreateXForm, template_name="form.html", post_save_redirect=reverse("list_xforms"), )
def add(request, app_label, model_name, id): '''Add a pad to another object''' try: typ = ContentType.objects.get(app_label=app_label, model=model_name) obj = typ.get_object_for_this_type(id=id) except: return HttpResponseNotFound() if request.method == 'POST': pad_form = PadForm(request.POST) if pad_form.is_valid(): pad_inst = pad_form.save(commit=False) pad_inst.creator = request.user title = pad_form.cleaned_data["title"] pad_inst.guid = create_pad_guid(title) pad_inst.content_type = typ pad_inst.object_id = id pad_inst.save() textarea_inst = TextArea(pad=pad_inst, editor=request.user ) textarea_inst.save() return HttpResponseRedirect( pad_inst.get_absolute_url() ) else: pad_form = PadForm() return create_object( request, form_class = PadForm, template_name = 'pads/new.html', extra_context = locals(), )
def vocal_contest_guest(request): contest = VocalContest.objects.get_current() if contest\ and contest.status() == 'open'\ and contest.is_real: rvc = RealVocalContestGuest.objects.filter(user=request.user) if rvc: return update_object( request, form_class=RealVocalContestGuestForm, object_id=rvc[0].id, #should be login_required=True, template_name='vocal_contest/guest.html', post_save_redirect=reverse('vocal_contest_index'), extra_context={ 'contest': contest, 'edit': True }) else: return create_object( request, form_class=RealVocalContestGuestForm, login_required=True, template_name='vocal_contest/guest.html', post_save_redirect=reverse('vocal_contest_index'), extra_context={ 'contest': contest, }) else: return redirect(vocal_contest_index)
def course_add_or_update(request, course_id=None): if course_id: return update_object(request, model=Course, object_id=course_id, template_name='course_form.html', post_save_redirect='/') else: return create_object(request, model=Course, template_name='course_form.html', post_save_redirect='/')
def configuration(request): """ This view is used to create, display or edit configuration of our tool. Currently this view is used for setting path to local meta sploit framework, or setting the IP address and destination port of the remote meta sploit framework. This view is based on Django generic views. If configuration object does not exist in the database we create it. If exist, just display and update it. """ # if Configuration object exists in the model, we use # Django's generic view (django.views.generic.create_update.update_object) try: p = Configuration.objects.get() return update_object(request, model=Configuration, object_id="1", template_name="configuration.html", post_save_redirect="/", extra_context={ 'menuitems' : createMenu("config")} ) # else if Configuration object does not exist # it is probably first run, the database is empty and # we should initialize the configuration by creating # object using django[...] generic view for creating objects. except Configuration.DoesNotExist: return create_object(request, model=Configuration, template_name="configuration.html", post_save_redirect="/", extra_context={ 'menuitems' : createMenu("config")} )
def feedback(request): return create_object(request, model=Blog, template_name='feedback.html', post_save_redirect="list_feedback" )
def new(request): from django.views.generic.create_update import create_object return create_object( request, form_class=CompanyForm, template_name='new_company.html', )
def post_form(request, topic_id): topic = Topic.objects.get(id=topic_id) if topic.locked: return HttpResponseRedirect("/forum/topic/%d" % topic.id) if int(topic.state) != settings.STATE_PUBLISHED: return HttpResponseRedirect("/forum/topic/%d" % topic.id) return create_object(request, Post, login_required='true', extra_context={'topic': topic, 'STATE_DEFAULT': settings.STATE_DEFAULT})
def membership_add(request, band_slug): """ Add a member in the band """ band = get_object_or_404(Band, slug=band_slug) # Permissions if not request.user.has_perm('band.can_manage', band): return HttpResponseForbidden(_("You are not allowed to edit this band")) if request.method == 'POST': addform = BandMemberAddForm(request.POST) if addform.is_valid(): # Set band bandmember = addform.save(commit=False) bandmember.band = band # Save to DB bandmember.save() addform.save_m2m() # Assign rights to the user assign('band.can_manage', bandmember.user, band) return redirect(bandmember) return create_object(request, form_class=BandMemberAddForm, template_name='band/membership_add.html', extra_context={'band': band}, )
def create_entry(request): if request.method == 'POST': form = EntryForm(request.POST) entry = Entry() if form.is_valid(): entry.username = form.cleaned_data['username'] entry.email = form.cleaned_data['email'] entry.content = form.cleaned_data['content'] entry.ip_address = request.META['REMOTE_ADDR'] entry.save() return HttpResponseRedirect('/wrk/specs/guestbook/') else: context = { 'entry_form': form, } return render_to_response('guestbook/entry_form.html', context) else: form = EntryForm() context = { 'entry_form': form, } ### GENERIC VIEWS return create_object(request, Entry, extra_context=context)
def add_book(request): extra_context = {'action': 'add'} return create_object( request, form_class = BookForm, extra_context = extra_context, )
def vocal_contest_participate(request): """ if there is open contest: if it has rules: show rules first then show participation form """ contest = VocalContest.objects.get_current() if contest and contest.status() == 'open': if contest.rules and not request.method == 'POST': return render_to_response('flatpages/agree.html', {'flatpage': contest.rules}, context_instance=RequestContext(request)) else: if request.POST.has_key('__confirm__'): # confirmation form is submited. # so we delete it's data and show up participate form request.POST = {} request.method = 'GET' if contest.is_real: form_class = RealVocalContestParticipantForm else: form_class = VocalContestParticipantForm return create_object( request, form_class=form_class, login_required=True, template_name='vocal_contest/participate.html', extra_context={ 'contest': contest, }) else: return redirect(vocal_contest_index)
def build_create(request): """ Create a new build """ return create_object(request, model=Build, template_name='factory/build_form.html', post_save_redirect=reverse("build_list_all"))
def add_book(request): extra_context = {'action': 'add'} return create_object( request, form_class=BookForm, extra_context=extra_context, )
def new(request): """ Create a new Pad, with 1 initial "TextArea" for a given choice. """ if request.method == 'POST': pad_form = PadForm(request.POST) if pad_form.is_valid(): pad_inst = pad_form.save(commit=False) title = pad_form.cleaned_data["title"] # TODO is there a reason that this is not factored out to the # forms.py? pad_inst.creator = request.user pad_inst.guid = create_pad_guid(title) pad_inst.save() textarea_inst = TextArea(pad=pad_inst, editor=request.user ) textarea_inst.save() return HttpResponseRedirect( pad_inst.get_absolute_url() ) # Redirect after POST else: pad_form = PadForm() args = {"pad_form":pad_form, "user":request.user} return create_object( request, form_class = PadForm, template_name = 'pads/new.html', extra_context = args, #login_required = True, )
def student_sedev(request): return create_update.create_object( request, model = songoson_sedev, post_save_redirect = reverse('home-student'), template_name = 'student/studentSedev.html' )
def create_account(request): return create_object( request, form_class = get_account_form(request), post_save_redirect = reverse('list_accounts'), template_name = 'account_form.html', )
def role_create(request): check_permissions(request.user, [PERMISSION_ROLE_CREATE]) return create_object(request, model=Role, template_name='generic_form.html', post_save_redirect=reverse('role_list'))
def student_register(request): return create_update.create_object( request, form_class = StudentRegForm, post_save_redirect = reverse('home-student'), template_name = 'student/studentregister.html' )
def index(request): # 汎用ビューを利用 return create_object( request, form_class=GreetingForm, post_save_redirect=reverse('guestbook_index'), extra_context={'greeting_list': Greeting.objects.all()})
def episode_add(request, slug): ''' create a new episode ''' try: show = Show.objects.get(slug=slug, author=request.user) except: return HttpResponseRedirect(reverse('podcast_shows')) if request.method == 'POST': form = EpisodeForm(request.POST) if form.is_valid(): e = form.save(commit=False) e.show = show e.slug = slugify(e.title) e.save() #except: # e.slug = slugify(e.title) + \ # ''.join([choice('0123456789-_') for i in range(7)]) # e.save() #finally: return HttpResponseRedirect(reverse('podcast_episode', args=[slug, e.slug])) context={'show':show} return create_object(request, form_class=EpisodeForm,\ template_name="podcast/create_episode.html", \ extra_context=context)
def notes_create(request): """Membuat sebuah note baru""" return create_object(request, model=Notes, template_name='notes/create.html', post_save_redirect=reverse("notes_list"))
def create(request, post_save_redirect, acl_handler=DEFAULT_ACL_HANDLER, *args, **kwargs): """thin wrapper around django generic view to support reverse urls """ return create_object(request=request, post_save_redirect=reverse(post_save_redirect), extra_context=_process_rights(request, acl_handler), *args, **kwargs)
def teacher_addtopic(request): return create_update.create_object( request, form_class = SedevInfoForm, post_save_redirect = reverse('home-teacher'), template_name = 'teacher/TeacherSedevAdd.html' )
def create(request): return create_update.create_object( request, model=MaapPoint, form_class=MaapPointForm, template_name='maap/object_form.html', )
def project_category_create(request, template_name='projector/project_category/create.html'): logging.debug("project_category_create called") kwargs = { 'model' : ProjectCategory, 'template_name' : template_name, } return create_update.create_object(request, **kwargs)
def bankaccount_add(request, **kwargs): """Adds a new bank account. """ return create_update.create_object( request, form_class=BankAccountForm, template_name='sales/bankaccount_edit.html' )
def new(request): if request.method == 'POST': snippet_form = SnippetForm(request.POST) if snippet_form.is_valid(): new_snippet = snippet_form.save() return HttpResponseRedirect("/view/"+str(new_snippet.id)) else: return create_object(request, form_class=SnippetForm, template_name='new.html')
def person_create(request): # generic views response = create_update.create_object( request, form_class=PersonForm, template_name='etreg/person_form.html' # default ) return response
def topic_form(request, slug): forum = Forum.objects.get(slug=slug) return create_object(request, Topic, login_required='true', extra_context={ 'forum': forum, 'STATE_DEFAULT': settings.STATE_DEFAULT })
def phone_add(request): ''' FIXME: can't cancel ''' return create_object ( request, form_class = PhoneForm, template_name = 'core/phone_form.html', # FIXME: )
def contact_add(request, **kwargs): """Adds a new contact. """ return create_update.create_object( request, form_class=ContactForm, template_name='partners/contact_edit.html', extra_context={'object': Contact()}, )
def create(request): ''' Create a new message ''' return create_update.create_object( request, form_class=MessageForm, template_name="expedient/common/messaging/create.html", post_save_redirect=reverse("messaging_created"), )
def tag_add(request, **kwargs): """Adds a new tag. """ referer = clean_referer(request) if referer == reverse("tag_list"): referer = None return create_update.create_object(request, form_class=TagForm, post_save_redirect=referer, template_name='taxonomy/tag_edit.html')
def add_book(request): context_instance = RequestContext(request) user = resolve_variable('user', context_instance) if not settings.ALLOW_PUBLIC_ADD_BOOKS and not user.is_authenticated(): return redirect('/accounts/login/?next=/book/add') extra_context = {'action': 'add'} return create_object( request, form_class=BookForm, extra_context=extra_context, )
def detail_entreprise(request, object_id=None): psr = reverse('liste_entreprise') if object_id: return update_object(request, form_class=EntrepriseForm, object_id=object_id, post_save_redirect=psr) if '_addanother' in request.POST: psr = reverse('ajouter_entreprise') return create_object(request, form_class=EntrepriseForm, post_save_redirect=psr)
def create_project(request): context = {} if request.method == 'POST': form = ProjectCreateForm(request.POST) if form.is_valid(): project = form.save(commit = False) project.creator = request.user project.save() project.allowed_users.add(request.user) return redirect('/projects/') else: context['form'] = form return create_object(request, form_class = ProjectCreateForm, extra_context = context)
def post_form(request, topic_id): topic = Topic.objects.get(id=topic_id) if topic.locked: return HttpResponseRedirect("/forum/topic/%d" % topic.id) if int(topic.state) != settings.STATE_PUBLISHED: return HttpResponseRedirect("/forum/topic/%d" % topic.id) return create_object(request, Post, login_required='true', extra_context={ 'topic': topic, 'STATE_DEFAULT': settings.STATE_DEFAULT })
def notes_create(request): """Create new note""" return create_object( request, # model=Note form_class= NoteForm, # Needed to specify form_class instead of model so that the custom date widget for dropdown menu is displayed: https://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-create-update-create-object # extra_context={'kind': 'kind', 'url': 'url'}, template_name='notes/create.html', # post_save_redirect=reverse("notes_list") post_save_redirect= "/notes/archive/%(id)s/" # todo: add object.get_absolute_url() to models.py )
def new(request): ''' Create a new listing with request.user as owner ''' if request.method == 'POST': form = ListingForm(request.POST) if form.is_valid: l = form.save(commit=False) l.owner = request.user l.save() return HttpResponseRedirect(reverse('listings_all')) else: form = ListingForm() return create_object(request, form_class=ListingForm)
def custom_create(request): """ Calls create_object generic view with a custom form class. """ class SlugChangingArticleForm(forms.ModelForm): """Custom form class to overwrite the slug.""" class Meta: model = Article def save(self, *args, **kwargs): self.instance.slug = 'some-other-slug' return super(SlugChangingArticleForm, self).save(*args, **kwargs) return create_object( request, post_save_redirect='/views/create_update/view/article/%(slug)s/', form_class=SlugChangingArticleForm)
def request_add(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/staff/login/?return=%s' % request.get_full_path()) elif request.user.has_perm('requests.add_photorequest'): c = {} if request.user.has_perm('requests.change_photorequest'): c['edit_request'] = True return create_object( request, PhotoRequest, extra_context=c, template_name='staff/requests/photorequest_form.html') else: return render_to_response('staff/access_denied.html', { 'missing': 'add', 'staffapp': 'photo requests' }, context_instance=RequestContext(request))
def create_album(request): if request.user.is_authenticated(): class AddAlbumForm(AlbumForm): """ Для того что бы получить в классе формы к объекту request.user переопределяем класс AlbumForm во views """ def save(self): album = super(AddAlbumForm, self).save(commit=False) album.owner = request.user # при сохранение, поле заполняем данными из request album.save() return album return create_object( request, form_class=AddAlbumForm, post_save_redirect=reverse('gallery.views.upload_picture')) else: return HttpResponseRedirect('/account/login/')
def create_diagram(request, type_id, project_id, template_name = 'users/create_diagram_form.html'): context = {} if request.method == 'POST': project = get_object_or_404(Project, id=project_id) type = get_object_or_404(DiagramType, id=type_id) user = request.user # authorization if user != project.creator: return unauthorized() form = DiagramForm(request.POST) if form.is_valid(): diagram = form.save(commit = False) diagram.project = project diagram.creator = user diagram.type = type diagram.save() diagram.allowed_users.add(user) return redirect('/project/%i/' % diagram.project.id) else: context['form'] = form return create_object(request, form_class = DiagramForm, extra_context = context)