Commits

Anonymous committed c8ac615

Refactored to DRY it out

Comments (0)

Files changed (1)

syncr/app/genericfeed.py

                     if entry.title != source_entry.get('title', 'No Title'):
                         entry.title = source_entry.get('title', 'No Title')
                     
-                    for field in ('author', 'summary'):
-                        if source_entry.has_key(field):
-                            if getattr(entry, field) != source_entry[field]:
-                                setattr(entry, field, source_entry[field])
-                    
-                    for field in ('published', 'updated'):
-                        field_key = '%s_parsed' % field
-                        if source_entry.has_key(field_key):
-                            if getattr(entry, field) != source_entry[field_key]:
-                                setattr(entry, field,
-                                        datetime.fromtimestamp(
-                                            time.mktime(
-                                                source_entry[field_key])))
-                    
-                    if source_content:
-                        if entry.content != source_content:
-                            entry.content = source_content
-                    
-                    if source_summary:
-                        if entry.summary != source_summary:
-                            entry.summary = source_summary
-                    
-                    entry.save()
-                    
                 except Entry.DoesNotExist:
                     # If this is a new entry, create a new Entry item
                     entry = Entry(id=entry_id,
                                   title=source_entry.get('title', 'No Title'),
                                   link=source_entry.link)
                     
-                    for field in ('author', 'summary'):
-                        if source_entry.has_key(field):
-                            setattr(entry, field, source_entry[field])
+                for field in ('author', 'summary'):
+                    if source_entry.has_key(field):
+                        setattr(entry, field, source_entry[field])
+                
+                for field in ('published', 'updated'):
+                    field_key = '%s_parsed' % field
+                    if source_entry.has_key(field_key):
+                        setattr(entry, field,
+                                datetime.fromtimestamp(
+                                    time.mktime(source_entry[field_key])))
                     
-                    for field in ('published', 'updated'):
-                        field_key = '%s_parsed' % field
-                        if source_entry.has_key(field_key):
-                            setattr(entry, field,
-                                    datetime.fromtimestamp(
-                                        time.mktime(
-                                            source_entry[field_key])))
+                entry.feed = feed
+                
+                if source_content:
+                    entry.content = source_content
+                
+                if source_summary:
+                    entry.summary = source_summary
                     
-                    entry.feed = feed
-                    
-                    if source_content:
-                        entry.content = source_content
-                    
-                    if source_summary:
-                        entry.summary = source_summary
-                    
-                    entry.save()
+                entry.save()