def get_context_data(self, **kwargs): kwargs = super(EditProfileView, self).get_context_data(**kwargs) kwargs.update({"cloudmade_key": settings.CLOUDMADE_API_KEY}) if not self.request.user.is_authenticated(): return self.render_to_response({'error': 'You have to login to proceed this operation.'}) try: profile = models.Profile.objects.get(user=self.request.user) except models.Profile.DoesNotExist: return self.render_to_response({'error': 'No profile for an user with username <%s>'%self.request.user.username}) mtags = tagdict(profile.machinetags.all()) profile_form = forms.ProfileForm(initial={'name': profile.name, 'email': profile.user.email, 'bio': profile.bio, 'page_url': profile.page_url if profile.is_paid else profile.user.username, 'hide_from_search': profile.hide_from_search, 'skills': ', '.join([s.name for s in profile.skills.all()]), 'available_for': profile.available_for, 'service_facebook': mtags['services']['facebook'], 'service_linkedin': mtags['services']['linkedin'], 'service_freelancercom': mtags['services']['freelancercom'], 'service_flickr': mtags['services']['flickr']}) kwargs.update({'profile_form': profile_form}) kwargs.update({'profile': profile}) return kwargs
def get_context_data(self, **kwargs): kwargs = super(ProfileView, self).get_context_data(**kwargs) try: profile = models.Profile.objects.get(page_url=kwargs['params']['username']) if not profile.is_paid and profile.page_url != profile.user.username: raise models.Profile.DoesNotExist except models.Profile.DoesNotExist: profile = get_object_or_404(models.Profile, user__username=kwargs['params']['username']) profile.profile_views += 1 profile.save() kwargs.update({"cloudmade_key": settings.CLOUDMADE_API_KEY}) mtags = tagdict(profile.machinetags.all()) # Set up convenient iterables for IM and services ims = [] for key, value in mtags.get('im', {}).items(): shortname, name, icon = app_settings.IMPROVIDERS_DICT.get(key, ('', '', '')) if not shortname: continue # Bad machinetag ims.append({ 'shortname': shortname, 'name': name, 'value': value, }) ims.sort(lambda x, y: cmp(x['shortname'], y['shortname'])) services = {} for key, value in mtags.get('services', {}).items(): shortname, name, icon = app_settings.SERVICES_DICT.get(key, ('', '', '')) if not shortname: continue # Bad machinetag #services.append({ # 'shortname': shortname, # 'name': name, # 'value': value, #}) services[shortname] = {'name': name, 'value': value} #services.sort(lambda x, y: cmp(x['shortname'], y['shortname'])) kwargs.update({ 'is_owner': self.request.user.username == kwargs['params']['username'], 'profile': profile, 'mtags': mtags, 'ims': ims, 'services': services, 'user': self.request.user, 'closest_users': None, #profile.get_nearest(20), }) return kwargs
def profile(request, username): person = get_object_or_404(DjangoPerson, user__username=username) person.profile_views += 1 # Not bothering with transactions; only a stat person.save() mtags = tagdict(person.machinetags.all()) # Set up convenient iterables for IM and services ims = [] for key, value in mtags.get("im", {}).items(): shortname, name, icon = IMPROVIDERS_DICT.get(key, ("", "", "")) if not shortname: continue # Bad machinetag ims.append({"shortname": shortname, "name": name, "value": value}) ims.sort(lambda x, y: cmp(x["shortname"], y["shortname"])) services = [] for key, value in mtags.get("services", {}).items(): shortname, name, icon = SERVICES_DICT.get(key, ("", "", "")) if not shortname: continue # Bad machinetag services.append({"shortname": shortname, "name": name, "value": value}) services.sort(lambda x, y: cmp(x["shortname"], y["shortname"])) # Set up vars that control privacy stuff privacy = { "show_im": (mtags["privacy"]["im"] == "public" or not request.user.is_anonymous()), "show_email": ( mtags["privacy"]["email"] == "public" or (not request.user.is_anonymous() and mtags["privacy"]["email"] == "private") ), "hide_from_search": mtags["privacy"]["search"] != "public", "show_last_irc_activity": bool(person.last_active_on_irc and person.irc_tracking_allowed()), } # Should we show the 'Finding X' section at all? show_finding = services or privacy["show_email"] or (privacy["show_im"] and ims) return render( request, "profile.html", { "person": person, "api_key": settings.GOOGLE_MAPS_API_KEY, "is_owner": request.user.username == username, "skills_form": SkillsForm(initial={"skills": edit_string_for_tags(person.skilltags)}), "mtags": mtags, "ims": ims, "services": services, "privacy": privacy, "show_finding": show_finding, }, )
def edit_finding(request, username): person = get_object_or_404(DjangoPerson, user__username = username) if request.method == 'POST': form = FindingForm(request.POST, person=person) if form.is_valid(): user = person.user user.email = form.cleaned_data['email'] user.save() person.machinetags.filter(namespace = 'profile').delete() if form.cleaned_data['blog']: person.add_machinetag( 'profile', 'blog', form.cleaned_data['blog'] ) if form.cleaned_data['looking_for_work']: person.add_machinetag( 'profile', 'looking_for_work', form.cleaned_data['looking_for_work'] ) for fieldname, (namespace, predicate) in \ MACHINETAGS_FROM_FIELDS.items(): person.machinetags.filter( namespace = namespace, predicate = predicate ).delete() if form.cleaned_data.has_key(fieldname) and \ form.cleaned_data[fieldname].strip(): value = form.cleaned_data[fieldname].strip() person.add_machinetag(namespace, predicate, value) return redirect(reverse('user_profile', args=[username])) else: mtags = tagdict(person.machinetags.all()) initial = { 'email': person.user.email, 'blog': mtags['profile']['blog'], 'looking_for_work': mtags['profile']['looking_for_work'], } # Fill in other initial fields from machinetags for fieldname, (namespace, predicate) in \ MACHINETAGS_FROM_FIELDS.items(): initial[fieldname] = mtags[namespace][predicate] form = FindingForm(initial=initial, person=person) return render(request, 'edit_finding.html', { 'form': form, 'person': person, })
def edit_finding(request, username): person = get_object_or_404(DjangoPerson, user__username=username) if request.method == "POST": form = FindingForm(request.POST, person=person) if form.is_valid(): user = person.user user.email = form.cleaned_data["email"] user.save() person.machinetags.filter(namespace="profile").delete() if form.cleaned_data["blog"]: person.add_machinetag("profile", "blog", form.cleaned_data["blog"]) if form.cleaned_data["looking_for_work"]: person.add_machinetag("profile", "looking_for_work", form.cleaned_data["looking_for_work"]) for fieldname, (namespace, predicate) in MACHINETAGS_FROM_FIELDS.items(): person.machinetags.filter(namespace=namespace, predicate=predicate).delete() if form.cleaned_data.has_key(fieldname) and form.cleaned_data[fieldname].strip(): value = form.cleaned_data[fieldname].strip() person.add_machinetag(namespace, predicate, value) return HttpResponseRedirect("/%s/" % username) else: mtags = tagdict(person.machinetags.all()) initial = { "email": person.user.email, "blog": mtags["profile"]["blog"], "looking_for_work": mtags["profile"]["looking_for_work"], } # Fill in other initial fields from machinetags for fieldname, (namespace, predicate) in MACHINETAGS_FROM_FIELDS.items(): initial[fieldname] = mtags[namespace][predicate] form = FindingForm(initial=initial, person=person) return render(request, "edit_finding.html", {"form": form, "person": person})
def profile(request, username): person = get_object_or_404(DjangoPerson, user__username = username) person.profile_views += 1 # Not bothering with transactions; only a stat person.save() mtags = tagdict(person.machinetags.all()) # Set up convenient iterables for IM and services ims = [] for key, value in mtags.get('im', {}).items(): shortname, name, icon = IMPROVIDERS_DICT.get(key, ('', '', '')) if not shortname: continue # Bad machinetag ims.append({ 'shortname': shortname, 'name': name, 'value': value, }) ims.sort(lambda x, y: cmp(x['shortname'], y['shortname'])) services = [] for key, value in mtags.get('services', {}).items(): shortname, name, icon = SERVICES_DICT.get(key, ('', '', '')) if not shortname: continue # Bad machinetag services.append({ 'shortname': shortname, 'name': name, 'value': value, }) services.sort(lambda x, y: cmp(x['shortname'], y['shortname'])) # Set up vars that control privacy stuff privacy = { 'show_im': ( mtags['privacy']['im'] == 'public' or not request.user.is_anonymous() ), 'show_email': ( mtags['privacy']['email'] == 'public' or (not request.user.is_anonymous() and mtags['privacy']['email'] == 'private') ), 'hide_from_search': mtags['privacy']['search'] != 'public', 'show_last_irc_activity': bool(person.last_active_on_irc and person.irc_tracking_allowed()), } # Should we show the 'Finding X' section at all? show_finding = services or privacy['show_email'] or \ (privacy['show_im'] and ims) return render(request, 'profile.html', { 'person': person, 'is_owner': request.user.username == username, 'skills_form': SkillsForm(initial={ 'skills': edit_string_for_tags(person.skilltags) }), 'mtags': mtags, 'ims': ims, 'services': services, 'privacy': privacy, 'show_finding': show_finding, })