User Controls
Posts That Were Thanked by NARCassist
-
2017-07-30 at 4:56 AM UTC in The Retarded Thread: Click Here for AIDS
Originally posted by anra your iq is like low 130s, just like 75% of the forum
why do you think that iq means very much?
its like i have a big fucking chunk of a cobalt blue diamond. it has just been taken out of the ground, so its unpolished, uncut, and unprocessed. its a cool diamond! its cobalt blue which looks fucking sick, and would only look better after becoming a shiny, angular, piece of expensive. but i just sit and circlejerk about my diamond rock and how much it could be worth or how nice it would look after some work, or generally fucking off instead of making those visions into reality.
thats you and your dumb gay iq. instead of making a contribution to society you would rather just sit like a wart on the ass end of a bridge troll and just talk about how smart you are when people who "are dumb" are running laps around you in life. -
2017-07-29 at 11:33 PM UTC in (Django) Class based view for splitting view logic based on HTTP methodsKinda unlikely anyone here is going to care, but I have this piece of code I've been copy pasting between Django projects for years because it addresses a really common situation in a way I think is quite neat relative to the approach you typically see used in the docs and such. Might be worth some SEO points or something. Also possibly useful to the couple of you who poke through the ISS code now and then because it's used pervasively there.
The situation is you have some view (the thing that handles an incoming HTTP request) and you want to do something different when a client does a GET request vs. a POST request vs. something else. This is done constantly with form handling, GET should present a form POST should validate the form and either represent with error messaging or take some action if the form is valid. The usual approach is to look at the request method in your view and branch according to what you want to do. It typically looks like this (taken from django docs):
def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')
# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()
return render(request, 'name.html', {'form': form})
If these alternative paths get long however this quickly becomes unreadable. Half the function is doing one thing and half is doing something else. Gets worse the more methods you're trying to support. So enter MethodSplitView:
class MethodSplitView(object):
"""
A flexible class for splitting handling of different HTTP methods being
dispatched to the same view into separate class methods. Subclasses may
define a separate class method for each HTTP method the view handles (e.g.
GET(self, request, ...), POST(self, request, ...) which will be called with
the usual view signature when that sort of request is made.
Subclasses may also define a `pre_method_check` method which, if it returns
a HttpResponse, will be used to response to the request instead of
delegating to the corresponding method.
"""
def __call__(self, request, *args, **kwargs):
if getattr(self, 'active_required', False):
if not request.user.is_active:
return HttpResponseForbidden('You must be an active user '
'to do this')
if getattr(self, 'staff_required', False):
if not request.user.is_staff:
return HttpResponseForbidden('You must be staff to do this.')
meth = getattr(self, request.method, None)
if not meth:
return HttpResponseBadRequest('Request method %s not supported'
% request.method)
response_maybe = self.pre_method_check(request, *args, **kwargs)
if isinstance(response_maybe, HttpResponse):
return response_maybe
return meth(request, *args, **kwargs)
def pre_method_check(request, *args, **kwargs):
return None
@classmethod
def as_view(cls):
if getattr(cls, 'require_login', False):
return login_required(cls())
else:
return cls()
https://gist.github.com/RyanJenkins/258723c74485fb01ee85272075bad967
Essentially this the behavior here is to look at the request method and pick a method from the subclass with the appropriate name and delegate request handling to that. So submission logic lives in one method, inquiry logic in another. On the whole it's a lot easier to visually parse quickly. One downside is that sharing logic between multiple methods is harder here, in my experience the vast majority of shared logic between methods is in the form of some kind of auth check (is the user logged in, do the have the appropriate privileges, etc) so I added a `pre_method_check` method that subclasses can specify to do this check and optionally return a response (preventing delegation to other methods). There are more opportunities for reducing boilerplate but generally at the cost of flexibility, empirically this seems to be the sweet spot and any other logic sharing can be delegated to private methods that request handling method call.
For a concrete example, here's the user registration method using this "pattern" (kinda hate that word):
class RegisterUser(utils.MethodSplitView):
def pre_method_check(self, request, *args, **kwargs):
if not utils.get_config('enable_registration'):
return render(request, 'generic_message.html', {
'page_title': 'Registration Closed',
'heading': 'Registration Closed',
'message': ('Registration is temporarily closed. Check back '
'later to register a new account. If you think '
'this is in error, please contact the '
'administrator.')
})
def GET(self, request):
form = forms.RegistrationForm()
ctx = {'form': form}
return render(request, 'register.html', ctx)
def POST(self, request):
form = forms.RegistrationForm(request.POST)
if form.is_valid():
poster = form.save()
poster = authenticate(username = form.cleaned_data['username'],
password = form.cleaned_data['password1'])
login(request, poster)
return HttpResponseRedirect('/')
else:
ctx = { 'form': form }
return render(request, 'register.html', ctx) -
2017-07-29 at 10:56 PM UTC in i'm totally head over heels in love right now
-
2017-07-29 at 7:55 PM UTC in what triggers your thrist ???7Up commercials trigger my thirst. I personally dislike alcohol. The trade off sucks, a mediocre buzz for a shitty hang-over.
-
2017-07-29 at 7:16 PM UTC in John McCain is an American hero
Originally posted by Captain Falcon Like literally basic facts about even the nature of Obamacare holy shit lol.
Basic facts according to you? Aren't you supposed to be rich? You know all about economics right? So tell me, what happens when you force insurance companies to take on people with pre-existing conditions? 1. Premiums go up massively. 2. Everyone just cancels their plan until they get sick. To keep the fucking scam going Obamacare just forces everyone to get healthcare and pay the premiums. That's the real reason for Obamacare. You're delusional if you actually believe the government is this big old humanitarian organization that gives a single shit about the welfare of it's citizens. -
2017-07-29 at 8:44 AM UTC in Your ideal breakfast.anyone who argues pigs are filthy hasnt been on a farm and seen the rest of the animals
-
2017-07-29 at 8:16 AM UTC in Your ideal breakfast.I never eat breakfast at all, intermittent fasting.
Pigs are only filthy due to the abhorrent conditions the vast majority are kept in. Regardless, it's not as if fecal matter becomes intrinsically enmeshed into muscle tissue. Any exposure is largely external.
What about cows? Do you know how fucking filthy the CAFOs they're kept in are? -
2017-07-29 at 5:45 AM UTC in i'm totally head over heels in love right nowYou should have a coffee together.
-
2017-07-29 at 5:38 AM UTC in i think i have a little dilemma developing.
-
2017-07-29 at 2:40 AM UTC in i'm totally head over heels in love right nownice, i haven't done H in a couple years, I used to be all about it. like 8/9 years ago. About 6 months ago I went to the area near the university where I would score and they really "cleaned" up that area.
the main drug around here everyone is into now is meff. its funny how some people are with their drug of choice are, a lot of meff heads around here have a superiority complex and look down on heroin users but once twacked or they've been doing it awhile won't mind slamming.
my drug buddy who is now dead used to do heroin with me and quit and just started smoking meff all day errrr day. Going on about how he will never do heroin again. I eventually stopped hanging out with him because he was a drug jedi and starting getting annoying when we'd smoke speed.
I found out months later that he started doing heroin again and died. For being college educated and coming from a very well off family the guy was kind of a ree ree. -
2017-07-29 at 2:07 AM UTC in i'm totally head over heels in love right nowThat looks fucking disgusting.
-
2017-07-29 at 1:57 AM UTC in i think i have a little dilemma developing.
-
2017-07-28 at 11:49 PM UTC in i think i have a little dilemma developing.Just pay her to fuck and get it over with. You don't want to date a hooker. You might think you do, but you don't. Not really. Pay her, fuck her, and don't forget the condom.
...falling for a hooker.
If I were there I'd have to smack you upside the damn head on principle. The fuck is wrong with you, man? -
2017-07-28 at 4:07 PM UTC in Are other planets even real?I had the exact same thought as the OP.
-
2017-07-28 at 2:43 PM UTC in The Retarded Thread: Click Here for AIDS
Originally posted by anra i operate on a whole different level than you. it's irritating that you think you possess any genuine intelligence. you rehearse facts with absolutely 0 ability to extrapolate for personal conclusions. its like if life was a 3D simulation your cpu can only render it in 2D. i literally see you as like a cardboard cutout of a human who cant understand anything beyond whats immediately presented. case closed.
Lol sub-average IQ confirmed. Does operating on a whole other level include chugging Listerine and getting your ass kicked by your dad when you tried to murder your parents? -
2017-07-28 at 2:12 PM UTC in The Retarded Thread: Click Here for AIDSSploo, why are you so insecure about being your stupidity, baby boy
-
2017-07-28 at 1:15 PM UTC in Anyone gonts here ever been to a strip club?Why would you throw a ping pong ball at a stripper?
Did they shoot them back with their pussies? -
2017-07-28 at 7:54 AM UTC in The Retarded Thread: Click Here for AIDSwow such a hardcore lil boy
try real man drugs you goddamn loser -
2017-07-28 at 6:09 AM UTC in Say something positive about the poster above youposts some thoughtful stuff when he's not trying to force memes and gimmicks
Originally posted by RisiR † He will die one day.
Usually a good guy, has posted some of the most amusing stuff on the site. Gets highly unpredictable sometimes, probably benzo-related
Originally posted by infinityshock nigger cock sucking faggot jedi fag
has a lot of insight relating to military and geopolitics, though it's often hard to see past the monotonous rapethreats.
Originally posted by cerakote is really good at getting banned for taboo
surprisingly functional for a meth user. aside from gaychan memes has some interesting posts. also the only one who argues with IS in an amusing fashion.
Originally posted by Captain Falcon My favourite poster on the site.
Nut up and be positive, you gays.
Most intelligent Paki I've talked to. I actually believe that he's rich through selling his advertising business - dunno if that makes me retarded, but seems reasonable to me.
***Forgot Bill Krozby
Originally posted by Bill Krozby ^RETARD!
Would probably find this guy repellant in real life; he sounds like a wifebeater with zero impulse control.
As a poster he's improved a lot since he slowed down on the drinking; posts some decent stuff but relies too much on expecting people to watch videos instead of actually starting a discussion
Post last edited by aldra at 2017-07-28T06:25:05.563553+00:00 -
2017-07-28 at 3:36 AM UTC in i think i have a little dilemma developing.