def change_password(request, enc): if request.method == 'GET': return helpers.req_render_to_response(request, 'user/change_password.html', {'form': forms.ChangePasswordForm()}) form = forms.ChangePasswordForm(request.POST) if form.is_valid(): request.user.set_password(form.cleaned_data['password1']) request.user.save() return helpers.req_render_to_response(request, 'user/change_password_done.html', {'created': True, 'username': request.user.username}) return helpers.req_render_to_response(request, 'user/change_password.html', {'form': form})
def help_article(request, question_id): question = Question.objects.get(id=question_id) controller.record_stat(request, 'view_help_website', '0', question_id) return req_render_to_response(request, 'help/help_article.html', { 'question': question, })
def handle_poll_submit(request): if not request.method == 'POST': log.sec_req(request, "Tried to hit poll submit URL by GET.") raise Http404 poll_id = request.POST['poll_id'] vote_id = request.POST['vote_id'] current_poll = FlowgramPoll.objects.get(id=poll_id) # increment votes and save if vote_id == current_poll.candidate_id_1: current_poll.votes_1 += 1 elif vote_id == current_poll.candidate_id_2: current_poll.votes_2 += 1 elif vote_id == current_poll.candidate_id_3: current_poll.votes_3 += 1 current_poll.save() current_poll_fg1 = Flowgram.objects.get(id=current_poll.candidate_id_1) current_poll_fg2 = Flowgram.objects.get(id=current_poll.candidate_id_2) current_poll_fg3 = Flowgram.objects.get(id=current_poll.candidate_id_3) return req_render_to_response(request, 'includes/modules/other_content/poll_module_results.incl', { 'current_poll': current_poll, 'current_poll_fg1': current_poll_fg1, 'current_poll_fg2': current_poll_fg2, 'current_poll_fg3': current_poll_fg3, })
def show_full_newsfeed(request, enc, username): user = get_object_or_404(auth_models.User, username=username) user_properties = webhelpers.get_user_properties(user, True) context = webhelpers.translate_user_properties(user_properties) favs = models.Favorite.objects.filter(owner=user) fav_fgs = [favorite.flowgram for favorite in favs if favorite.flowgram.public][:4] # Get User profiles items from list of subscriptions subscription_profiles = [] for sub in controller.get_user_subscriptions(user): subscription_user = models.UserProfile.objects.get(user=sub["user"]) avatar_url= models.UserProfile.avatar_100(subscription_user) subscription_profiles.append({'username': subscription_user.user, 'avatar_url': avatar_url}) # Get User profiles items from list of subscribers subscriber_profiles = [] for sub in controller.get_user_subscribers(user): subscriber_user = models.UserProfile.objects.get(user=sub["subscriber"]) avatar_url= models.UserProfile.avatar_100(subscriber_user) subscriber_profiles.append({'username':subscriber_user.user, 'avatar_url':avatar_url}) context.update({'u': user, 'subs_active': localsettings.FEATURE['subscriptions_fw'], 'mostviewed': cached_sets.most_viewed()[:6], 'fav_fgs': fav_fgs, 'profile_views': user_properties['profile'].views, 'subscription_profiles': subscription_profiles, 'subscriber_profiles': subscriber_profiles, 'newsfeed_display': newsfeed.render(request.user, user, False)}) return helpers.req_render_to_response(request, 'user/show_profile_newsfeed_full.html', context)
def create_toolbar_landing(request, enc): (browser, version) = webhelpers.get_brower_and_version(request) return helpers.req_render_to_response( request, "create/toolbar_landing.html", {"domain_name": localsettings.MASTER_DOMAIN_NAME, "browser": browser, "browser_version": version}, )
def reset_password_makenew(request, enc, user, key): from flowgram.core.mail import validate_password_reset_hash if request.method == 'POST': if not validate_password_reset_hash(user, key): raise Http404 new_password = request.POST['new_password'] user.set_password(new_password) user.save() helpers.add_good_message(request, "Your new password was set.") return HttpResponseRedirect('/you/') if not user or not key: helpers.add_bad_message(request, "Please make sure you copied the whole URL from your email.") return HttpResponseRedirect('/reset/') if not validate_password_reset_hash(user, key): helpers.add_bad_message( request, 'Please make sure you copied the whole URL from your email. If the email is more than one day old, request a new email on this page.') return HttpResponseRedirect('/reset/') return helpers.req_render_to_response(request, 'user/enter_new_password.html', {'user': user, 'key': key})
def help(request): category_list = Category.objects.all() controller.record_stat(request, 'view_help_website', '0', 'help index') return req_render_to_response(request, 'help/help.html', { 'category_list': category_list, })
def nojs(request): user_agent = request.META.get('HTTP_USER_AGENT', '') (browser, version) = webhelpers.get_brower_and_version(request) return req_render_to_response(request, "system/nojs.html", {'domain_name': localsettings.MASTER_DOMAIN_NAME, 'browser': browser, 'browser_version': version})
def show_user(request, enc, user): user_properties = webhelpers.get_user_properties(user, True) profile = user_properties['profile'] profile.views += 1 profile.save() profile_views = profile.views newsfeed_display = newsfeed.render(request.user, user, True) context = { 'u': user, 'subs_active': localsettings.FEATURE['subscriptions_fw'], 'send_to_details': localsettings.FEATURE['send_to_details'], 'activesecondary': 'profile', 'mostviewed': cached_sets.most_viewed()[:6], 'profile_views': profile_views, 'newsfeed_display': newsfeed_display, 'posts': webhelpers.get_latest_fg_blog_posts(), } context.update(webhelpers.translate_user_properties(user_properties)) if user == request.user: return helpers.req_render_to_response(request, 'user/show_profile_owner.html', context) else: favs = models.Favorite.objects.filter(owner=user) fav_fgs = [favorite.flowgram for favorite in favs if favorite.flowgram.public][:4] fgs = models.Flowgram.from_published.filter(owner=user, public=True).order_by('-published_at')[:6] # Checking if user is sub'd to this user. is_subscribed = models.Subscription.objects.filter(user=user, subscriber=request.user) context.update({ 'is_subscribed': is_subscribed, 'fgs': fgs, 'active': 'browse', 'pageowner' : False, 'display_filters_suppress': True, 'fg_timestamp': False, 'fav_fgs': fav_fgs, 'news_list': newsfeed.get_rendered_news_feed(request.user, user, 'S') }) return helpers.req_render_to_response(request, 'user/show_profile.html', context)
def delete_flowgram(request, enc, flowgram): if request.method == 'POST': list_page = flowgram.owner.get_profile().url() helpers.add_bad_message(request, "Flowgram \"%s\" was deleted" % flowgram.title) flowgram.delete() return HttpResponseRedirect('/you/') else: return helpers.req_render_to_response(request, 'dialogs/delete_fg.html', {'fg': flowgram})
def tutorials_index(request, enc): tutorials = Tutorial.objects.filter(active=True).order_by('position') return helpers.req_render_to_response( request, "tutorials/tutorial_index.html", { 'tutorials': tutorials, })
def standalone_page(request, enc, directory_name, page_name): template_path = 'standalone/' + directory_name + '/' + page_name + '.html' return helpers.req_render_to_response( request, template_path, { })
def view_subscriptions(request): u = request.user p = u.get_profile() if request.method == 'POST': f = NotifyForm(request.POST) if f.is_valid(): cleaned = f.cleaned_data p.notification_freq = cleaned['notification_freq'] p.notify_by_email = cleaned['notify_by_email'] p.has_public_news_feed = cleaned['has_public_news_feed'] p.save() url = "/subscriptions/" add_good_message(request, "Your settings have been successfully updated.") return HttpResponseRedirect(url) initial = { 'notification_freq': p.notification_freq, 'notify_by_email': p.notify_by_email, 'has_public_news_feed': p.has_public_news_feed, } f = NotifyForm(initial=initial) # Get User profiles items from list of subscriptions user_subscriptions = controller.get_user_subscriptions(u) subscription_profiles = [] for sub in user_subscriptions: subscription_user = UserProfile.objects.get(user=sub["user"]) avatar_url= UserProfile.avatar_100(subscription_user) subscription_profiles.append({'username':subscription_user.user,'avatar_url':avatar_url}) # Get User profiles items from list of subscribers subscribers = controller.get_user_subscribers(u) subscriber_profiles = [] for sub in subscribers: subscriber_user = UserProfile.objects.get(user=sub["subscriber"]) avatar_url= UserProfile.avatar_100(subscriber_user) subscriber_profiles.append({'username':subscriber_user.user,'avatar_url':avatar_url}) # For secondary nav include activesecondary = 'subscriptions' show_unsubscribe = True return req_render_to_response(request, 'user/view_subscriptions.html', { 'subscription_profiles':subscription_profiles, 'activesecondary': activesecondary, 'subs_active':subs_active, 'profile':p, 'form': f, 'u':u, 'show_unsubscribe': show_unsubscribe, 'subscriber_profiles':subscriber_profiles, 'mostviewed': cached_sets.most_viewed()[:6], })
def delete_press(request, enc, current_press_id): if request.method == 'GET': return helpers.req_render_to_response( request, 'dialogs/delete_press.html', {'current_press_item': models.FlowgramPress.objects.get(id=current_press_id)}) else: models.FlowgramPress.objects.get(id=current_press_id).delete() helpers.add_good_message(request, "You deleted a press item. Congratulations.") return HttpResponseRedirect('/adminpress')
def delete_tutorial(request, enc, tutorial_id): tutorial = Tutorial.objects.get(id=tutorial_id) if request.method == 'GET': return helpers.req_render_to_response( request, 'dialogs/delete_tutorial.html', {'tutorial': tutorial,}) else: Tutorial.objects.get(id=tutorial_id).delete() helpers.add_good_message(request, "You deleted a tutorial. Congratulations.") return HttpResponseRedirect('/admintutorials')
def reset_password_post(request, enc, user, email): from flowgram.core.mail import reset_password if email: try: user = auth_models.User.objects.get(email=email) except auth_models.User.DoesNotExist: helpers.add_bad_message(request, "No account was found for that email address.") return helpers.req_render_to_response(request, 'user/reset_password.html') if not user: helpers.add_bad_message(request, "You must enter your username or email.") return helpers.req_render_to_response(request, 'user/reset_password.html') if reset_password(user): helpers.add_good_message(request, "Your password reset email has been sent. Follow the emailed instructions.") return helpers.req_render_to_response(request, 'user/reset_password.html') else: helpers.add_bad_message(request, "We were unable to reach your account email address.") return helpers.req_render_to_response(request, 'user/reset_password.html')
def export_youtube_step1(request, enc, export_to_video_request_id): export_to_video_request = get_object_or_404(models.ExportToVideoRequest, id=export_to_video_request_id) return helpers.req_render_to_response( request, "flowgram/export_youtube_step1.html", { "flowgram": export_to_video_request.flowgram, "auth_sub_url": uploadtoyoutube.get_auth_sub_url(export_to_video_request_id), "preview_url": "http://%s/%s.wmv" % (localsettings.S3_BUCKETS[localsettings.S3_BUCKET_UPLOAD], export_to_video_request_id), }, )
def tutorial(request, enc, tutorial_id): tutorial = Tutorial.objects.get(id=tutorial_id) video_path = '' if tutorial.video_path: video_path = tutorialhelpers.get_tutorial_video_path(tutorial) return helpers.req_render_to_response( request, "tutorials/view_tutorial.html", { 'tutorial': tutorial, 'video_path': video_path, })
def view_press(request, prid=''): press_list = FlowgramPress.objects.filter().order_by('-link_date') fgpr_press_list = press_list.filter(press_category='R') featured_press_list = press_list.filter(press_category='F') more_press_list = press_list.filter(press_category='M') press_display = 'index' if not prid == '': press_display = 'pr' pr = FlowgramPress.objects.get(id=prid) return req_render_to_response(request, 'about_us/press.html', { 'pr': pr, 'press_display': press_display, }) return req_render_to_response(request, 'about_us/press.html', { 'fgpr_press_list': fgpr_press_list, 'featured_press_list': featured_press_list, 'more_press_list': more_press_list, 'press_display': press_display, })
def admin_featured(request, enc): area = int(request.GET.get('area', 0)) if request.method == 'POST': form = request.POST['form'] if form == 'create_new': fgid = request.POST['id'] rank = float(request.POST['rank']) area = int(request.POST['area']) try: fg = models.Flowgram.objects.get(id=fgid) except models.Flowgram.DoesNotExist: models.add_bad_message(request, "Invalid Flowgram ID %s" % fgid) else: models.Featured.objects.create(area=area, flowgram=fg, rank=rank) elif form == 'modify': to_delete = [] for (key, value) in request.POST.items(): if key.find('__') == -1: continue (feat_id, attr) = key.split('__') feat = models.Featured.objects.get(id=feat_id) if attr == 'id': fgid = value if not fgid: to_delete.append(feat) continue try: fg = models.Flowgram.objects.get(id=fgid) except models.Flowgram.DoesNotExist: models.add_bad_message(request, "Invalid Flowgram ID %s" % fgid) break feat.flowgram = fg feat.save() elif attr == 'pri': feat.rank = float(value) feat.save() else: raise Http500 for feat in to_delete: feat.delete() else: raise Http500 featured = models.Featured.objects.filter(area=area) return helpers.req_render_to_response( request, "admin/admin_featured.html", { 'featured':featured, 'area': area, 'areas': models.FEATURED_AREAS, })
def jobs(request, available_position=''): if available_position == '': position = '' elif available_position == '/': position = '' elif available_position == 'appdev': position = 'appdev' elif available_position == 'producer': position = 'producer' else: position = '' return req_render_to_response(request, "about_us/jobs.html", { 'position': position, })
def export_to_video_check(request, enc, export_to_video_request_id): export_to_video_request = models.ExportToVideoRequest.objects.get(id=export_to_video_request_id) if export_to_video_request.status_code == models.StatusCode.ERROR: return helpers.req_render_to_response( request, "flowgram/export_to_video_error.html", {"title": export_to_video_request.flowgram.title} ) if export_to_video_request.status_code == models.StatusCode.DONE: return helpers.req_render_to_response( request, "flowgram/export_to_video_done.html", {"title": export_to_video_request.flowgram.title} ) unfinished_status_codes = [models.StatusCode.UNPROCESSED, models.StatusCode.PROCESSING] num_prior_unprocessed_tasks = 0 if export_to_video_request.status_code != models.StatusCode.PROCESSING: unfinished_tasks = models.ExportToVideoRequest.objects.filter(status_code__in=unfinished_status_codes) similar_tasks = unfinished_tasks.filter( flowgram=export_to_video_request.flowgram, use_highlight_popups=export_to_video_request.use_highlight_popups ).order_by("timestamp") if similar_tasks.count(): num_prior_unprocessed_tasks = unfinished_tasks.filter(timestamp__lt=similar_tasks[0].timestamp).count() return helpers.req_render_to_response( request, "flowgram/export_to_video_check.html", { "title": export_to_video_request.flowgram.title, "status": "currently processing" if export_to_video_request.status_code == models.StatusCode.PROCESSING else "in our queue, waiting to be processed", "approx_wait": 10 if export_to_video_request.status_code == models.StatusCode.PROCESSING else num_prior_unprocessed_tasks * 3 + 10, }, )
def login(request, enc): next = request.GET.get('next', '/') if request.user.is_authenticated(): return helpers.redirect(next) next_greeting = '' if next.find('create') >= 0: next_greeting = "Please login or register to get started making Flowgrams. It's quick and easy!" elif next.find('subscribe') >= 0: next_greeting = "Please login or register to subscribe to a user. It's quick and easy!" if request.method == 'POST': succeeded = False form = forms.LoginForm(request.POST) if form.is_valid(): user = auth.authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) assert(user) auth.login(request, user) request.session[settings.PERSISTENT_SESSION_KEY] = form.cleaned_data['remember_user'] succeeded = True if not succeeded: request.session['processed_login_form'] = form.as_p() controller.record_stat(request, 'view_login_website', '0', 'unsuccessful') return HttpResponseRedirect('/login') next = request.POST.get('next', '') if next: controller.record_stat(request, 'view_login_website', '0', 'successful, next url = %s' % next) return helpers.redirect(next) controller.record_stat(request, 'view_login_website', '0', 'successful, next url = /') return HttpResponseRedirect('/') else: form = forms.LoginForm() reg_form = forms.RegistrationFormStep1() return helpers.req_render_to_response(request, 'login/login.html', {'next': next, 'next_greeting': next_greeting, 'reg_form': reg_form, 'which_form_reg': 'register_step_1'})
def show_flowgram(request, enc, flowgram): can_edit = permissions.can_edit(request.user, flowgram) context = { 'fg': flowgram, 'can_edit': can_edit, 'subs_active': localsettings.FEATURE['subscriptions_fw'], 'show_delete': can_edit, 'active': 'you' if request.user == flowgram.owner else 'browse', 'mostviewed': cached_sets.most_viewed()[:6], 'send_to_details': localsettings.FEATURE['send_to_details'] } context.update(webhelpers.get_flowgram_stats(flowgram)) controller.record_stat(request, 'view_flowgram_det_website', '0', flowgram.id) return helpers.req_render_to_response( request, 'flowgram/show_flowgram.html', context)
def show_tag(request, tag_name): tags = Tag.objects.filter(name=tag_name).order_by('-flowgram', '-created_at') fgs = [] previous_fgid = '' current_fgid = '' for tag in tags: fg = tag.flowgram current_fgid = tag.flowgram.id if current_fgid != previous_fgid: fgs.append(tag.flowgram) previous_fgid = current_fgid return req_render_to_response(request, 'flowgram/show_tag.html', { 'name': tag_name, 'fgs': fgs, 'send_to_details': localsettings.FEATURE['send_to_details'], })
def edit_avatar(request): random.shuffle(BUILTIN_AVATARS) form = AvatarForm() if request.method == 'POST': if "upload_form" in request.POST.keys(): form = AvatarForm(request.POST, request.FILES) if form.is_valid(): avatar.save_uploaded_avatar(request.user.get_profile(), form) else: # if "builtin_form" in request.POST.keys(): builtin_name = request.POST['name'] if builtin_name != 'XXX': p = request.user.get_profile() avatar.save_builtin_avatar(p, builtin_name) return req_render_to_response(request, "user/edit_avatar.html", { 'form': form, 'builtin_avatars' : BUILTIN_AVATARS, })
def dashboard_index(request): error_records = [] pass_records = [] records = DashboardServiceRecord.objects.all() if not records: log.debug('dashboard service recorder not running, check servicechecker.py in /flowgram/flowgram/core/dashboard') for record in records: if record.service_status == False: error_records.append(record) else: pass_records.append(record) return req_render_to_response(request, "dashboard/index.html", { 'error_records': error_records, 'pass_records':pass_records })
def contact_us_email(request): if request.method != 'POST': return req_render_to_response(request, 'about_us/contact_us_email.html') name = request.POST.get('name', '') if name == '': name='Anonymous' email = request.POST.get('email', '') subject = request.POST.get('subject', '') if subject == '': subject='I am not big on typing or words.' comments = request.POST.get('comments', '') controller.record_stat(request, 'add_feedback_website', '0', '') add_to_mail_queue( '*****@*****.**', '*****@*****.**', 'Contact via FG Contact Us/Feedback form', 'FROM: %s <%s> | SUBJECT: %s | COMMENTS: %s' % (name, email, subject, comments)) return HttpResponseRedirect('/about_us/contact_us_confirm/')
def export_youtube_step3(request, enc, export_to_video_request_id, token, title, description, category, private): export_to_video_request = get_object_or_404(models.ExportToVideoRequest, id=export_to_video_request_id) flowgram = export_to_video_request.flowgram keywords = WHITE_SPACE_OR_COMMAS_REGEX.sub(", ", request.POST.get("keywords")) models.UploadToYouTubeRequest.objects.create( token=token, request_user=request.user if request.user.is_authenticated() else None, export_to_video_request=export_to_video_request, flowgram=flowgram, title=title, description=description, keywords=keywords, category=category, private=private, ) return helpers.req_render_to_response(request, "flowgram/export_youtube_step3.html", {})
def inviter(request, enc, recipients, email_body): from django.template import Context, Template from flowgram.queueprocessors.sendemailrequestprocessor import add_to_mail_queue if request.method == 'GET': context = {'from_email' : request.user.email, 'default_email' : DEFAULT_INVITATION + request.user.username} return helpers.req_render_to_response(request, 'admin/inviter.html', context) for recipient in helpers.get_email_addresses_from_comma_separated_string(recipients): context = {} if localsettings.FEATURE['use_regcode']: context['regcode'] = models.Regcode.objects.create(sender=request.user).code # TODO(westphal): Figure out and remove or document: Why are we using unicode and then a # non-unicode string. body = '%s' % unicode(Template(email_body).render(Context(context))) add_to_mail_queue(request.user.email, recipient, "Invitation to Flowgram.com", body) helpers.add_good_message(request, 'Emails added to queue.') return HttpResponseRedirect('/a/inviter/')