Beispiel #1
0
def snippet_details(request, pk):
    """
    Details of the Snippet
    """
        
    # Get the object from the `pk`, raises a Http404 if not found
    obj = get_object_or_404(Snippet, pk=pk)
    
    ##
    # Check the parameters passed in the URL and process accordingly
    if request.GET.get('edit', False):
        ##
        # Check for permissions and redirect to AddAuthor view for editing
        
        print "DBG:: Redirecting to edit URL"
        return redirect('snippets:add', pk=obj.id)
    
   
    # Instantiate the Meta class
    title_for_meta = obj.get_title() + ' by ' + obj.author.get_name()    
    meta = Meta(title = title_for_meta, 
                description = truncatelines(obj.body, 4), 
                section= 'poetry', 
                url = obj.get_absolute_url(),                
                author = obj.author, 
                date_time = obj.updated_at,
                object_type = 'article',
                keywords = obj.tags.names(),
            )
    
    ##
    # Make the context and render
  
    context = {'snippet': obj, 'meta': meta}
    template = 'snippets/view.html'
    
    #return render_to_response(template, context , context_instance=RequestContext(request))
    return render(request, template, context)    
Beispiel #2
0
    def get_description(self):
        """
        Content to share on social media sites
        e.g. first stanza
        """
        return truncatelines(self.body, 4)
    
#     def get_dirty_fields(self):
#         return [f.name for f in self._meta.fields if self._original_state[f.attname] != self.__dict__[f.attname]]
#     
#     def _list_changes_in_tags(self):
#         dirty = self.get_dirty_fields()
# 
#         if not 'tagnames' in dirty:
#             return None
#         else:
#             if self._original_state['tagnames']:
#                 old_tags = set(self._original_state['tagnames'].split())
#             else:
#                 old_tags = set()
#             new_tags = set(self.tagnames.split())
# 
#             return dict(
#                     current=list(new_tags),
#                     added=list(new_tags - old_tags),
#                     removed=list(old_tags - new_tags)
#                     )
#             
#             
#     def _process_changes_in_tags(self):
#         tag_changes = self._list_changes_in_tags()
# 
#         if tag_changes is not None:
#             for name in tag_changes['added']:
#                 try:
#                     tag = Tag.objects.get(name=name)
#                 except Tag.DoesNotExist:
#                     tag = Tag.objects.create(name=name, created_by=self.updated_by)
# 
#                 if not self.nis.deleted:
#                     tag.add_to_usage_count(1)
#                     tag.save()
# 
#             if not self.nis.deleted:
#                 for name in tag_changes['removed']:
#                     try:
#                         tag = Tag.objects.get(name=name)
#                         tag.add_to_usage_count(-1)
#                         tag.save()
#                     except:
#                         pass
# 
#             return True
# 
#         return False  
    
#     def save(self, *args, **kwargs):
#       
#         tags_changed = self._process_changes_in_tags()
#         
#         super(Snippet, self).save(*args, **kwargs)
#         if tags_changed:
#             if self.tagnames.strip():
#                 self.tags = list(Tag.objects.filter(name__in=self.tagname_list()))
#             else:
#                 self.tags = []              
        
Beispiel #3
0
 def summary_socialmedia(self):
     """
     Content to share on social media sites.
     e.g. first two lines of first stanza
     """
     return truncatelines(self.body, 2, '%0A')
Beispiel #4
0
 def summary(self):
     """
     first stanza
     """
     return truncatelines(self.body, 4)
Beispiel #5
0
 def summary(self):
     """
     Content to share on social media sites
     e.g. first stanza
     """
     return truncatelines(self.body, 4)