def subscribe(request): if request.POST: form = SubscribeForm(request.POST) if form.is_valid(): if form.cleaned_data['action'] == 'subscribe': mailsubject = "subscribe" # Default is get mail and not digest, in which case we send a regular # subscribe request. In other cases, we send subscribe-set which also # sets those flags. if form.cleaned_data['receive'] and not form.cleaned_data['digest']: mailtxt = "subscribe %s\n" % form.cleaned_data['lists'] else: tags = [] if not form.cleaned_data['receive']: tags.append('nomail') if form.cleaned_data['digest']: tags.append('digest') mailtxt = "subscribe-set %s %s\n" % (form.cleaned_data['lists'], ",".join(tags)) else: mailtxt = "unsubscribe %s\n" % form.cleaned_data['lists'] mailsubject = "unsubscribe" send_simple_mail(form.cleaned_data['email'], settings.LISTSERVER_EMAIL, mailsubject, mailtxt) return render_to_response('lists/subscribed.html', { }, NavContext(request, "community")) else: # GET, so render up the form form = SubscribeForm() return render_to_response('lists/subscribe_form.html', { 'form': form, 'operation': 'Subscribe', 'jquery': True, 'form_intro': """ <b>Note 1:</b> Please ensure you read the <a href="https://wiki.postgresql.org/wiki/Archives_Policy">Archive Policy</a> before posting to the lists.</p> <p><b>Note 2:</b> Please do not subscribe to mailing lists using e-mail accounts protected by mail-back anti-spam systems. These are extremely annoying to the list maintainers and other members, and you may be automatically unsubscribed.""" }, NavContext(request, "community"))
def root(request): features = Feature.objects.all().select_related().order_by( 'group__groupsort', 'group__groupname', 'featurename') groups = [] lastgroup = -1 currentgroup = None for f in features: if f.group.id != lastgroup: if currentgroup: groups.append(currentgroup) lastgroup = f.group.id currentgroup = { 'group': f.group, 'features': [], } currentgroup['features'].append(f) if currentgroup: groups.append(currentgroup) eol_versions = [ v.tree for v in Version.objects.filter(supported=False, testing=False) ] return render_to_response('featurematrix/featurematrix.html', { 'groups': groups, 'eol_versions': eol_versions, }, NavContext(request, 'about'))
def item(request, itemid, throwaway=None): news = get_object_or_404(NewsArticle, pk=itemid) if not news.approved: raise Http404 return render_to_response('news/item.html', { 'obj': news, }, NavContext(request, 'about'))
def main(request): events = Event.objects.select_related('country').filter( approved=True).filter(training=False, enddate__gt=date.today()).order_by( 'enddate', 'startdate', ) training = Event.objects.select_related('country').filter( approved=True).filter(training=True, enddate__gt=date.today()).order_by( 'enddate', 'startdate', ) return render_to_response( 'events/archive.html', { 'title': 'Upcoming events', 'eventblocks': ( { 'name': 'Events', 'events': events, 'link': '', }, { 'name': 'Training', 'events': training, 'link': 'training/', }, ), }, NavContext(request, 'about'))
def item(request, itemid, throwaway=None): event = get_object_or_404(Event, pk=itemid) if not event.approved: raise Http404 return render_to_response('events/item.html', { 'obj': event, }, NavContext(request, 'about'))
def region(request, servtype, regionname): regname = [n for r, n in regions if r == regionname] if not regname: raise Http404 regname = regname[0] what = servtype == 'support' and 'support' or 'hosting' whatname = servtype == 'support' and 'Professional Services' or 'Hosting Providers' title = "%s - %s" % (whatname, regname) support = servtype == 'support' # DB model is a bit funky here, so use the extra-where functionality to filter properly. # Field names are cleaned up earlier, so it's safe against injections. services = ProfessionalService.objects.select_related('org').filter( approved=True).extra(where=[ "region_%s AND provides_%s" % (regionname, what), ]) return render_to_response( 'profserv/list.html', { 'title': title, 'support': support, 'what': what, 'whatname': whatname, 'regionname': regname, 'services': services, }, NavContext(request, 'support'))
def change_email(request): tokens = EmailChangeToken.objects.filter(user=request.user) token = len(tokens) and tokens[0] or None if request.method == 'POST': form = ChangeEmailForm(request.user, data=request.POST) if form.is_valid(): # If there is an existing token, delete it if token: token.delete() # Create a new token token = EmailChangeToken(user=request.user, email=form.cleaned_data['email'], token=generate_random_token()) token.save() send_template_mail(settings.NOTIFICATION_FROM, form.cleaned_data['email'], 'Your postgresql.org community account', 'account/email_change_email.txt', { 'token': token , 'user': request.user, } ) return HttpResponseRedirect('done/') else: form = ChangeEmailForm(request.user) return render_to_response('account/emailchangeform.html', { 'form': form, 'token': token, }, NavContext(request, "account"))
def results(request, surveyid, junk=None): survey = get_object_or_404(Survey, pk=surveyid) surveylist = Survey.objects.all().order_by('-posted') return render_to_response('survey/results.html', { 'survey': survey, 'surveylist': surveylist, }, NavContext(request, 'community'))
def submitbug(request): if request.method == 'POST': form = SubmitBugForm(request.POST) if form.is_valid(): c = connection.cursor() c.execute("SELECT nextval('bug_id_seq')") bugid = c.fetchall()[0][0] send_template_mail(form.cleaned_data['email'], settings.BUGREPORT_EMAIL, 'BUG #%s: %s' % (bugid, form.cleaned_data['shortdesc']), 'misc/bugmail.txt', { 'bugid': bugid, 'bug': form.cleaned_data, }, usergenerated=True) return render_to_response('misc/bug_completed.html', { 'bugid': bugid, }, NavContext(request, 'support')) else: form = SubmitBugForm( initial={ 'name': '%s %s' % (request.user.first_name, request.user.last_name), 'email': request.user.email, }) versions = Version.objects.filter(supported=True) return render_to_response( 'base/form.html', { 'form': form, 'formitemtype': 'bug report', 'operation': 'Submit', 'form_intro': template_to_string('misc/bug_header.html', { 'supportedversions': versions, }), }, NavContext(request, 'support'))
def root(request, servtype): title = servtype == 'support' and 'Professional Services' or 'Hosting Providers' what = servtype == 'support' and 'support' or 'hosting' support = servtype == 'support' return render_to_response('profserv/root.html', { 'title': title, 'support': support, 'regions': regions, 'what': what, }, NavContext(request, 'support'))
def productlist(request, catid, junk=None): category = get_object_or_404(Category, pk=catid) products = Product.objects.select_related('org', 'licencetype').filter( category=category, approved=True) return render_to_response( 'downloads/productlist.html', { 'category': category, 'products': products, 'productcount': len(products), }, NavContext(request, 'download'))
def listobjects(request, objtype): if not objtypes.has_key(objtype): raise Http404("Object type not found") o = objtypes[objtype] return render_to_response('account/objectlist.html', { 'objects': o['objects'](request.user), 'title': o['title'], 'submit_header': o.has_key('submit_header') and o['submit_header'] or None, 'suburl': objtype, }, NavContext(request, 'account'))
def community(request): s = Survey.objects.filter(current=True) try: s = s[0] except: s = None planet = ImportedRSSItem.objects.filter(feed__internalname="planet").order_by("-posttime")[:7] return render_to_response('core/community.html', { 'survey': s, 'planet': planet, }, NavContext(request, 'community'))
def commentform(request, itemid, version, filename): if request.method == 'POST': form = DocCommentForm(request.POST) if form.is_valid(): send_template_mail( form.cleaned_data['email'], settings.DOCSREPORT_EMAIL, '%s' % form.cleaned_data['shortdesc'], 'docs/docsbugmail.txt', { 'version': version, 'filename': filename, 'details': form.cleaned_data['details'], }, usergenerated=True, ) return render_to_response('docs/docsbug_completed.html', {}, NavContext(request, 'docs')) else: form = DocCommentForm( initial={ 'name': '%s %s' % (request.user.first_name, request.user.last_name), 'email': request.user.email, }) return render_to_response( 'base/form.html', { 'form': form, 'formitemtype': 'documentation correction', 'operation': 'Submit', 'form_intro': template_to_string('docs/docsbug.html', { 'user': request.user, }), }, NavContext(request, 'docs'))
def home(request): myarticles = NewsArticle.objects.filter(org__managers=request.user, approved=False) myevents = Event.objects.filter(org__managers=request.user, approved=False) myorgs = Organisation.objects.filter(managers=request.user, approved=False) myproducts = Product.objects.filter(org__managers=request.user, approved=False) myprofservs = ProfessionalService.objects.filter(org__managers=request.user, approved=False) return render_to_response('account/index.html', { 'newsarticles': myarticles, 'events': myevents, 'organisations': myorgs, 'products': myproducts, 'profservs': myprofservs, }, NavContext(request, 'account'))
def confirm_change_email(request, tokenhash): tokens = EmailChangeToken.objects.filter(user=request.user, token=tokenhash) token = len(tokens) and tokens[0] or None if token: # Valid token find, so change the email address request.user.email = token.email request.user.save() token.delete() return render_to_response('account/emailchangecompleted.html', { 'token': tokenhash, 'success': token and True or False, }, NavContext(request, "account"))
def signup(request): if request.user.is_authenticated(): return HttpServerError("You must log out before you can sign up for a new account") if request.method == 'POST': # Attempt to create user then, eh? form = SignupForm(get_client_ip(request), data=request.POST) if form.is_valid(): # Attempt to create the user here # XXX: Do we need to validate something else? log.info("Creating user for {0} from {1}".format(form.cleaned_data['username'], get_client_ip(request))) user = User.objects.create_user(form.cleaned_data['username'].lower(), form.cleaned_data['email'].lower(), last_login=datetime.now()) user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] # generate a random value for password. It won't be possible to log in with it, but # it creates more entropy for the token generator (I think). user.password = generate_random_token() user.save() # Now generate a token token = default_token_generator.make_token(user) log.info("Generated token {0} for user {1} from {2}".format(token, form.cleaned_data['username'], get_client_ip(request))) # Generate an outgoing email send_template_mail(settings.NOTIFICATION_FROM, form.cleaned_data['email'], 'Your new postgresql.org community account', 'account/new_account_email.txt', { 'uid': urlsafe_base64_encode(force_bytes(user.id)), 'token': token, 'user': user} ) return HttpResponseRedirect('/account/signup/complete/') else: form = SignupForm(get_client_ip(request)) return render_to_response('base/form.html', { 'form': form, 'formitemtype': 'Account', 'form_intro': """ To sign up for a free community account, enter your preferred userid and email address. Note that a community account is only needed if you want to submit information - all content is available for reading without an account. """, 'savebutton': 'Sign up', 'operation': 'New', 'recaptcha': True, }, NavContext(request, 'account'))
def index(request): """ contains list of PUGs, in country/locale alphabetical order """ pug_list = [] for pug in PUG.objects.filter(approved=True).order_by('country__name', 'locale').all(): if pug_list and pug_list[-1].get('country') == pug.country.name: pug_list[-1]['pugs'].append(pug) else: pug_list.append({ 'country': pug.country.name, 'pugs': [pug] }) return render_to_response('pugs/index.html', { 'pug_list': pug_list, }, NavContext(request, 'community'))
def _eventarchive(request, training, title): # Hardcode to the latest 100 events. Do we need paging too? events = Event.objects.select_related('country').filter( approved=True).filter(training=training, enddate__lte=date.today()).order_by( '-enddate', '-startdate', )[:100] return render_to_response( 'events/archive.html', { 'title': '%s Archive' % title, 'archive': True, 'eventblocks': ({ 'name': title, 'events': events, }, ), }, NavContext(request, 'about'))
def profile(request): # We always have the user, but not always the profile. And we need a bit # of a hack around the normal forms code since we have two different # models on a single form. (profile, created) = UserProfile.objects.get_or_create(pk=request.user.pk) # We may have a contributor record - and we only show that part of the # form if we have it for this user. try: contrib = Contributor.objects.get(user=request.user.pk) except Contributor.DoesNotExist: contrib = None contribform = None if request.method == 'POST': # Process this form userform = UserForm(data=request.POST, instance=request.user) profileform = UserProfileForm(data=request.POST, instance=profile) if contrib: contribform = ContributorForm(data=request.POST, instance=contrib) if userform.is_valid() and profileform.is_valid() and (not contrib or contribform.is_valid()): userform.save() profileform.save() if contrib: contribform.save() return HttpResponseRedirect("/account/") else: # Generate form userform = UserForm(instance=request.user) profileform = UserProfileForm(instance=profile) if contrib: contribform = ContributorForm(instance=contrib) return render_to_response('account/userprofileform.html', { 'userform': userform, 'profileform': profileform, 'contribform': contribform, }, NavContext(request, "account"))
def fallback(request, url): if url.find('..') > -1: raise Http404('Page not found.') if not re_staticfilenames.match(url): raise Http404('Page not found.') try: t = loader.get_template('pages/%s.html' % url) except TemplateDoesNotExist: try: t = loader.get_template('pages/%s/en.html' % url) except TemplateDoesNotExist: raise Http404('Page not found.') # Guestimate the nav section by looking at the URL and taking the first # piece of it. try: navsect = url.split('/',2)[0] except: navsect = '' return HttpResponse(t.render(NavContext(request, navsect)))
def servers(request): servers = Server.objects.select_related().all() return render_to_response('sponsors/servers.html', { 'servers': servers, }, NavContext(request, 'about'))
def archive(request, paging=None): news = NewsArticle.objects.filter(approved=True) return render_to_response('news/newsarchive.html', { 'news': news, }, NavContext(request, 'about'))
def sponsors(request): sponsors = Sponsor.objects.select_related().filter( sponsortype__sortkey__gt=0).order_by('sponsortype__sortkey', '?') return render_to_response('sponsors/sponsors.html', { 'sponsors': sponsors, }, NavContext(request, 'about'))
def versions(request): return render_to_response('support/versioning.html', { 'versions': Version.objects.filter(tree__gt=0).filter(testing=0), }, NavContext(request, 'support'))
def manualarchive(request): versions = Version.objects.filter(testing=0, supported=False, tree__gt=0).order_by('-tree') return render_to_response('docs/archive.html', { 'versions': [_VersionPdfWrapper(v) for v in versions], }, NavContext(request, 'docs'))
def manuals(request): versions = Version.objects.filter( Q(supported=True) | Q(testing__gt=0, tree__gt=0)).order_by('-tree') return render_to_response('docs/manuals.html', { 'versions': [_VersionPdfWrapper(v) for v in versions], }, NavContext(request, 'docs'))
file_maintainer = (node.has_key('CURRENT_MAINTAINER') and node['CURRENT_MAINTAINER']['t'] == 'f') and node['CURRENT_MAINTAINER']['c'] or None del node return render_to_response( 'downloads/ftpbrowser.html', { 'basepath': subpath.rstrip('/'), 'directories': directories, 'files': sorted(files), 'breadcrumbs': breadcrumbs, 'readme': file_readme, 'messagefile': file_message, 'maintainer': file_maintainer, }, NavContext(request, 'download')) # Accept an upload of the ftpsite pickle. This is fairly resource consuming, # and not very optimized, but that's why we limit it so that only the ftp # server(s) can post it. # There is no concurrency check - the ftp site better not send more than one # file in parallel. @csrf_exempt def uploadftp(request): if request.method != 'PUT': return HttpServerError("Invalid method") if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS: return HttpServerError("Invalid client address") # We have the data in request.body. Attempt to load it as # a pickle to make sure it's properly formatted
def root(request): versions = Version.objects.filter( Q(supported=True) | Q(testing__gt=0, tree__gt=0)).order_by('-tree') return render_to_response('docs/index.html', { 'versions': versions, }, NavContext(request, 'docs'))
def categorylist(request): categories = Category.objects.all() return render_to_response('downloads/categorylist.html', { 'categories': categories, }, NavContext(request, 'download'))