Esempio n. 1
0
 def related_user(self, obj):
     """HTML link to related user account"""
     link = reverse("admin:auth_user_change", args=(obj.user.id,))
     # TODO: Needs l10n? Maybe not a priority for an admin page.
     return '<a href="%(link)s"><strong>User %(id)s</strong></a>' % dict(
         link=link, id=obj.user.id, username=obj.user.username
     )
Esempio n. 2
0
def devderby_tag_to_date_url(tag):
    """Turn a devderby tag like challenge:2011:june into a date-based URL"""
    # HACK: Not super happy with this, but it works for now
    if not tag:
        return ''
    parts = tag.split(':')
    return reverse('demos_devderby_by_date', args=(parts[-2], parts[-1]))
Esempio n. 3
0
def profile_edit(request, username):
    """View and edit user profile"""
    profile = get_object_or_404(UserProfile, user__username=username)
    if not profile.allows_editing_by(request.user):
        return HttpResponseForbidden()

    # Map of form field names to tag namespaces
    field_to_tag_ns = (
        ('interests', 'profile:interest:'),
        ('expertise', 'profile:expertise:')
    )

    if request.method != "POST":

        initial = dict(email=profile.user.email)

        # Load up initial websites with either user data or required base URL
        for name, meta in UserProfile.website_choices:
            val = profile.websites.get(name, '') or meta['prefix']
            initial['websites_%s' % name] = val

        # Form fields to receive tags filtered by namespace.
        for field, ns in field_to_tag_ns:
            initial[field] = ', '.join(t.name.replace(ns, '')
                                       for t in profile.tags.all_ns(ns))

        # Finally, set up the form.
        form = UserProfileEditForm(instance=profile, initial=initial)

    else:
        form = UserProfileEditForm(request.POST, request.FILES,
                                   instance=profile)
        if form.is_valid():
            profile_new = form.save(commit=False)

            # Gather up all websites defined by the model, save them.
            sites = dict()
            for name, meta in UserProfile.website_choices:
                field_name = 'websites_%s' % name
                field_value = form.cleaned_data.get(field_name, '')
                if field_value:
                    sites[name] = field_value
            profile_new.websites = sites

            # Save the profile record now, since the rest of this deals with
            # related resources...
            profile_new.save()

            # Update tags from form fields
            for field, tag_ns in field_to_tag_ns:
                tags = [t.lower() for t in parse_tags(
                                            form.cleaned_data.get(field, ''))]
                profile_new.tags.set_ns(tag_ns, *tags)

            return HttpResponseRedirect(reverse(
                    'devmo.views.profile_view', args=(profile.user.username,)))

    return jingo.render(request, 'devmo/profile_edit.html', dict(
        profile=profile, form=form, INTEREST_SUGGESTIONS=INTEREST_SUGGESTIONS
    ))
Esempio n. 4
0
def devderby_tag_to_date_url(tag):
    """Turn a devderby tag like challenge:2011:june into a date-based URL"""
    # HACK: Not super happy with this, but it works for now
    if not tag:
        return ''
    parts = tag.split(':')
    return reverse('demos_devderby_by_date', args=(parts[-2], parts[-1]))
Esempio n. 5
0
def profile_edit(request, username):
    """View and edit user profile"""
    profile = get_object_or_404(UserProfile, user__username=username)
    if not profile.allows_editing_by(request.user):
        return HttpResponseForbidden()

    # Map of form field names to tag namespaces
    field_to_tag_ns = (
        ('interests', 'profile:interest:'),
        ('expertise', 'profile:expertise:')
    )

    if request.method != 'POST':

        initial = dict(email=profile.user.email)

        # Load up initial websites with either user data or required base URL
        for name, meta in UserProfile.website_choices:
            initial['websites_%s' % name] = profile.websites.get(name, '')

        # Form fields to receive tags filtered by namespace.
        for field, ns in field_to_tag_ns:
            initial[field] = ', '.join(t.name.replace(ns, '')
                                       for t in profile.tags.all_ns(ns))

        # Finally, set up the form.
        form = UserProfileEditForm(instance=profile, initial=initial)

    else:
        form = UserProfileEditForm(request.POST, request.FILES,
                                   instance=profile)
        if form.is_valid():
            profile_new = form.save(commit=False)

            # Gather up all websites defined by the model, save them.
            sites = dict()
            for name, meta in UserProfile.website_choices:
                field_name = 'websites_%s' % name
                field_value = form.cleaned_data.get(field_name, '')
                if field_value and field_value != meta['prefix']:
                    sites[name] = field_value
            profile_new.websites = sites

            # Save the profile record now, since the rest of this deals with
            # related resources...
            profile_new.save()

            # Update tags from form fields
            for field, tag_ns in field_to_tag_ns:
                tags = [t.lower() for t in parse_tags(
                                            form.cleaned_data.get(field, ''))]
                profile_new.tags.set_ns(tag_ns, *tags)

            return HttpResponseRedirect(reverse(
                    'devmo.views.profile_view', args=(profile.user.username,)))

    return render(request, 'devmo/profile_edit.html', dict(
        profile=profile, form=form, INTEREST_SUGGESTIONS=INTEREST_SUGGESTIONS
    ))
Esempio n. 6
0
File: feeds.py Progetto: tantek/kuma
    def write(self, outfile, encoding):
        request = self.feed['request']

        # Check for a callback param, validate it before use
        callback = request.GET.get('callback', None)
        if callback is not None:
            if not validate_jsonp.is_valid_jsonp_callback_value(callback):
                callback = None

        items_out = []
        for item in self.items:

            # Include some of the simple elements from the preprocessed feed item
            item_out = dict((x, item[x]) for x in (
                'link',
                'title',
                'pubdate',
                'author_name',
                'author_link',
            ))

            item_out['author_avatar'] = item['obj'].creator.get_profile(
            ).gravatar

            # Linkify the tags used in the feed item
            item_out['categories'] = dict(
                (x,
                 request.build_absolute_uri(
                     reverse('demos_tag', kwargs={'tag': x})))
                for x in item['categories'])

            # Include a few more, raw from the submission object itself.
            item_out.update((x, str(getattr(item['obj'], x))) for x in (
                'summary',
                'description',
            ))

            item_out['featured'] = item['obj'].featured

            # Include screenshot as an absolute URL.
            item_out['screenshot'] = request.build_absolute_uri(
                item['obj'].screenshot_1.url)

            # HACK: This .replace() should probably be done in the model
            item_out['thumbnail'] = request.build_absolute_uri(
                item['obj'].screenshot_1.url).replace('screenshot',
                                                      'screenshot_thumb')

            #TODO: What else might be useful in a JSON feed of demo submissions?
            # Comment, like, view counts may change too much for caching to be useful

            items_out.append(item_out)

        data = items_out

        if callback: outfile.write('%s(' % callback)
        outfile.write(json.dumps(data, default=self._encode_complex))
        if callback: outfile.write(')')
Esempio n. 7
0
    def write(self, outfile, encoding):
        request = self.feed['request']

        # Check for a callback param, validate it before use
        callback = request.GET.get('callback', None)
        if callback is not None:
            if not validate_jsonp.is_valid_jsonp_callback_value(callback):
                callback = None

        items_out = []
        for item in self.items:

            # Include some of the simple elements from the preprocessed feed item
            item_out = dict( (x, item[x]) for x in (
                'link', 'title', 'pubdate', 'author_name', 'author_link',
            ))

            item_out['author_avatar'] = item['obj'].creator.get_profile().gravatar

            # Linkify the tags used in the feed item
            item_out['categories'] = dict(
                (x, request.build_absolute_uri(reverse('demos_tag', kwargs={'tag':x})))
                for x in item['categories']
            )

            # Include a few more, raw from the submission object itself.
            item_out.update( (x, unicode(getattr(item['obj'], x))) for x in (
                'summary', 'description',
            ))

            item_out['featured'] = item['obj'].featured

            # Include screenshot as an absolute URL.
            item_out['screenshot'] = request.build_absolute_uri(
                item['obj'].screenshot_url(1))

            # HACK: This .replace() should probably be done in the model
            item_out['thumbnail'] = request.build_absolute_uri(
                item['obj'].thumbnail_url(1))

            #TODO: What else might be useful in a JSON feed of demo submissions?
            # Comment, like, view counts may change too much for caching to be useful

            items_out.append(item_out)

        data = items_out

        if callback: outfile.write('%s(' % callback)
        outfile.write(json.dumps(data, default=self._encode_complex))
        if callback: outfile.write(')')
Esempio n. 8
0
File: feeds.py Progetto: tantek/kuma
    def write(self, outfile, encoding):
        request = self.feed["request"]

        # Check for a callback param, validate it before use
        callback = request.GET.get("callback", None)
        if callback is not None:
            if not validate_jsonp.is_valid_jsonp_callback_value(callback):
                callback = None

        items_out = []
        for item in self.items:

            # Include some of the simple elements from the preprocessed feed item
            item_out = dict((x, item[x]) for x in ("link", "title", "pubdate", "author_name", "author_link"))

            item_out["author_avatar"] = item["obj"].creator.get_profile().gravatar

            # Linkify the tags used in the feed item
            item_out["categories"] = dict(
                (x, request.build_absolute_uri(reverse("demos_tag", kwargs={"tag": x}))) for x in item["categories"]
            )

            # Include a few more, raw from the submission object itself.
            item_out.update((x, str(getattr(item["obj"], x))) for x in ("summary", "description"))

            item_out["featured"] = item["obj"].featured

            # Include screenshot as an absolute URL.
            item_out["screenshot"] = request.build_absolute_uri(item["obj"].screenshot_1.url)

            # HACK: This .replace() should probably be done in the model
            item_out["thumbnail"] = request.build_absolute_uri(item["obj"].screenshot_1.url).replace(
                "screenshot", "screenshot_thumb"
            )

            # TODO: What else might be useful in a JSON feed of demo submissions?
            # Comment, like, view counts may change too much for caching to be useful

            items_out.append(item_out)

        data = items_out

        if callback:
            outfile.write("%s(" % callback)
        outfile.write(json.dumps(data, default=self._encode_complex))
        if callback:
            outfile.write(")")
Esempio n. 9
0
 def related_user(self, obj):
     """HTML link to related user account"""
     link = reverse('admin:auth_user_change', args=(obj.user.id, ))
     # TODO: Needs l10n? Maybe not a priority for an admin page.
     return ('<a href="%(link)s"><strong>User %(id)s</strong></a>' %
             dict(link=link, id=obj.user.id, username=obj.user.username))
Esempio n. 10
0
File: feeds.py Progetto: sumlaj/kuma
 def item_author_link(self, submission):
     return self.request.build_absolute_uri(
         reverse('demos.views.profile_detail',
                 args=(submission.creator.username, )))
Esempio n. 11
0
def my_profile(request):
    user = request.user
    return HttpResponseRedirect(reverse(
            'devmo.views.profile_view', args=(user.username,)))
Esempio n. 12
0
File: feeds.py Progetto: sumlaj/kuma
 def item_link(self, submission):
     return self.request.build_absolute_uri(
         reverse('demos.views.detail', args=(submission.slug, )))
Esempio n. 13
0
File: views.py Progetto: kkdeep/kuma
def my_profile(request):
    user = request.user
    return HttpResponseRedirect(
        reverse('devmo.views.profile_view', args=(user.username, )))
Esempio n. 14
0
 def get_absolute_url(self):
     return reverse('demos.views.detail', kwargs={'slug':self.slug})
Esempio n. 15
0
 def get_absolute_url(self):
     return reverse("demos.views.detail", kwargs={"slug": self.slug})
Esempio n. 16
0
 def get_absolute_url(self):
     return reverse('demos.views.detail', kwargs={'slug':self.slug})
Esempio n. 17
0
 def item_link(self, submission):
     return self.request.build_absolute_uri(
         reverse('kuma.demos.views.detail',
         args=(submission.slug,)))
Esempio n. 18
0
 def item_author_link(self, submission):
     return self.request.build_absolute_uri(
         reverse('kuma.demos.views.profile_detail',
         args=(submission.creator.username,)))